diff --git a/rust-version b/rust-version index 2115e482c6..ab6f899cd3 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -0f806a9812b62c36bdab08d33c14cf2d3ecf4355 +4316d0c6252cb1f833e582dfa68adb98efd5ddfb diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 9319877472..db4c4a28de 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -1,3 +1,4 @@ +#![feature(generic_nonzero)] #![feature(rustc_private, stmt_expr_attributes)] #![allow( clippy::manual_range_contains, @@ -19,7 +20,7 @@ extern crate rustc_session; extern crate tracing; use std::env::{self, VarError}; -use std::num::NonZeroU64; +use std::num::NonZero; use std::path::PathBuf; use std::str::FromStr; @@ -524,7 +525,7 @@ fn main() { } } } else if let Some(param) = arg.strip_prefix("-Zmiri-track-alloc-id=") { - let ids: Vec = match parse_comma_list::(param) { + let ids: Vec = match parse_comma_list::>(param) { Ok(ids) => ids.into_iter().map(miri::AllocId).collect(), Err(err) => show_error!( diff --git a/src/borrow_tracker/mod.rs b/src/borrow_tracker/mod.rs index f50aaa292f..711323b51c 100644 --- a/src/borrow_tracker/mod.rs +++ b/src/borrow_tracker/mod.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; use std::fmt; -use std::num::NonZeroU64; +use std::num::NonZero; use smallvec::SmallVec; @@ -12,22 +12,22 @@ use crate::*; pub mod stacked_borrows; pub mod tree_borrows; -pub type CallId = NonZeroU64; +pub type CallId = NonZero; /// Tracking pointer provenance #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct BorTag(NonZeroU64); +pub struct BorTag(NonZero); impl BorTag { pub fn new(i: u64) -> Option { - NonZeroU64::new(i).map(BorTag) + NonZero::new(i).map(BorTag) } pub fn get(&self) -> u64 { self.0.get() } - pub fn inner(&self) -> NonZeroU64 { + pub fn inner(&self) -> NonZero { self.0 } @@ -183,7 +183,7 @@ impl GlobalStateInner { borrow_tracker_method, next_ptr_tag: BorTag::one(), base_ptr_tags: FxHashMap::default(), - next_call_id: NonZeroU64::new(1).unwrap(), + next_call_id: NonZero::new(1).unwrap(), protected_tags: FxHashMap::default(), tracked_pointer_tags, tracked_call_ids, @@ -205,7 +205,7 @@ impl GlobalStateInner { if self.tracked_call_ids.contains(&call_id) { machine.emit_diagnostic(NonHaltingDiagnostic::CreatedCallId(call_id)); } - self.next_call_id = NonZeroU64::new(call_id.get() + 1).unwrap(); + self.next_call_id = NonZero::new(call_id.get() + 1).unwrap(); FrameState { call_id, protected_tags: SmallVec::new() } } diff --git a/src/concurrency/init_once.rs b/src/concurrency/init_once.rs index 9a848d5034..35dcfecbbe 100644 --- a/src/concurrency/init_once.rs +++ b/src/concurrency/init_once.rs @@ -1,5 +1,4 @@ use std::collections::VecDeque; -use std::num::NonZeroU32; use rustc_index::Idx; use rustc_middle::ty::layout::TyAndLayout; diff --git a/src/concurrency/sync.rs b/src/concurrency/sync.rs index 6863119032..956a02ded0 100644 --- a/src/concurrency/sync.rs +++ b/src/concurrency/sync.rs @@ -1,5 +1,4 @@ use std::collections::{hash_map::Entry, VecDeque}; -use std::num::NonZeroU32; use std::ops::Not; use rustc_data_structures::fx::FxHashMap; @@ -24,12 +23,12 @@ macro_rules! declare_id { /// 0 is used to indicate that the id was not yet assigned and, /// therefore, is not a valid identifier. #[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] - pub struct $name(NonZeroU32); + pub struct $name(std::num::NonZero); impl SyncId for $name { // Panics if `id == 0`. fn from_u32(id: u32) -> Self { - Self(NonZeroU32::new(id).unwrap()) + Self(std::num::NonZero::new(id).unwrap()) } fn to_u32(&self) -> u32 { self.0.get() @@ -42,11 +41,11 @@ macro_rules! declare_id { // therefore, need to shift by one when converting from an index // into a vector. let shifted_idx = u32::try_from(idx).unwrap().checked_add(1).unwrap(); - $name(NonZeroU32::new(shifted_idx).unwrap()) + $name(std::num::NonZero::new(shifted_idx).unwrap()) } fn index(self) -> usize { // See the comment in `Self::new`. - // (This cannot underflow because self is NonZeroU32.) + // (This cannot underflow because `self.0` is `NonZero`.) usize::try_from(self.0.get() - 1).unwrap() } } diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 7825673db0..d47f446716 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -1,5 +1,5 @@ use std::fmt::{self, Write}; -use std::num::NonZeroU64; +use std::num::NonZero; use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, Level}; use rustc_span::{SpanData, Symbol, DUMMY_SP}; @@ -110,7 +110,7 @@ pub enum NonHaltingDiagnostic { /// (new_tag, new_perm, (alloc_id, base_offset, orig_tag)) /// /// new_perm is `None` for base tags. - CreatedPointerTag(NonZeroU64, Option, Option<(AllocId, AllocRange, ProvenanceExtra)>), + CreatedPointerTag(NonZero, Option, Option<(AllocId, AllocRange, ProvenanceExtra)>), /// This `Item` was popped from the borrow stack. The string explains the reason. PoppedPointerTag(Item, String), CreatedCallId(CallId), diff --git a/src/helpers.rs b/src/helpers.rs index 932a35d9bf..d9b4363d60 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,6 +1,6 @@ use std::cmp; use std::iter; -use std::num::NonZeroUsize; +use std::num::NonZero; use std::time::Duration; use rustc_apfloat::ieee::{Double, Single}; @@ -572,7 +572,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { fn visit_union( &mut self, _v: &MPlaceTy<'tcx, Provenance>, - _fields: NonZeroUsize, + _fields: NonZero, ) -> InterpResult<'tcx> { bug!("we should have already handled unions in `visit_value`") } diff --git a/src/lib.rs b/src/lib.rs index adc547aa6c..c567949102 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![feature(rustc_private)] #![feature(cell_update)] #![feature(float_gamma)] +#![feature(generic_nonzero)] #![feature(map_try_insert)] #![feature(never_type)] #![feature(try_blocks)] diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index f4d6905534..0645c1f176 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -475,7 +475,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let [id, show_unnamed] = this.check_shim(abi, Abi::Rust, link_name, args)?; let id = this.read_scalar(id)?.to_u64()?; let show_unnamed = this.read_scalar(show_unnamed)?.to_bool()?; - if let Some(id) = std::num::NonZeroU64::new(id) { + if let Some(id) = std::num::NonZero::new(id) { this.print_borrow_state(AllocId(id), show_unnamed)?; } } diff --git a/tests/pass/intrinsics.rs b/tests/pass/intrinsics.rs index 8e46bd7ad4..0dda5aadce 100644 --- a/tests/pass/intrinsics.rs +++ b/tests/pass/intrinsics.rs @@ -37,7 +37,7 @@ fn main() { let mut saw_false = false; for _ in 0..50 { - if unsafe { intrinsics::is_val_statically_known(0) } { + if intrinsics::is_val_statically_known(0) { saw_true = true; } else { saw_false = true;