1
Fork 0

Replace NonZero::<_>::new with NonZero::new.

This commit is contained in:
Markus Reiter 2024-02-08 23:03:25 +01:00
parent 746a58d435
commit a90cc05233
No known key found for this signature in database
GPG key ID: 245293B51702655B
70 changed files with 175 additions and 216 deletions

View file

@ -433,7 +433,7 @@ impl<'tcx> TyCtxt<'tcx> {
// the `-Z force-unstable-if-unmarked` flag present (we're
// compiling a compiler crate), then let this missing feature
// annotation slide.
if feature == sym::rustc_private && issue == NonZero::<u32>::new(27812) {
if feature == sym::rustc_private && issue == NonZero::new(27812) {
if self.sess.opts.unstable_opts.force_unstable_if_unmarked {
return EvalResult::Allow;
}

View file

@ -500,7 +500,7 @@ impl<'tcx> AllocMap<'tcx> {
AllocMap {
alloc_map: Default::default(),
dedup: Default::default(),
next_id: AllocId(NonZero::<u64>::new(1).unwrap()),
next_id: AllocId(NonZero::new(1).unwrap()),
}
}
fn reserve(&mut self) -> AllocId {

View file

@ -155,7 +155,7 @@ impl CtfeProvenance {
/// Returns the `AllocId` of this provenance.
#[inline(always)]
pub fn alloc_id(self) -> AllocId {
AllocId(NonZero::<u64>::new(self.0.get() & !IMMUTABLE_MASK).unwrap())
AllocId(NonZero::new(self.0.get() & !IMMUTABLE_MASK).unwrap())
}
/// Returns whether this provenance is immutable.

View file

@ -161,14 +161,14 @@ impl<D: Decoder> Decodable<D> for ScalarInt {
let mut data = [0u8; 16];
let size = d.read_u8();
data[..size as usize].copy_from_slice(d.read_raw_bytes(size as usize));
ScalarInt { data: u128::from_le_bytes(data), size: NonZero::<u8>::new(size).unwrap() }
ScalarInt { data: u128::from_le_bytes(data), size: NonZero::new(size).unwrap() }
}
}
impl ScalarInt {
pub const TRUE: ScalarInt = ScalarInt { data: 1_u128, size: NonZero::<u8>::new(1).unwrap() };
pub const TRUE: ScalarInt = ScalarInt { data: 1_u128, size: NonZero::new(1).unwrap() };
pub const FALSE: ScalarInt = ScalarInt { data: 0_u128, size: NonZero::<u8>::new(1).unwrap() };
pub const FALSE: ScalarInt = ScalarInt { data: 0_u128, size: NonZero::new(1).unwrap() };
#[inline]
pub fn size(self) -> Size {
@ -196,7 +196,7 @@ impl ScalarInt {
#[inline]
pub fn null(size: Size) -> Self {
Self { data: 0, size: NonZero::<u8>::new(size.bytes() as u8).unwrap() }
Self { data: 0, size: NonZero::new(size.bytes() as u8).unwrap() }
}
#[inline]
@ -208,7 +208,7 @@ impl ScalarInt {
pub fn try_from_uint(i: impl Into<u128>, size: Size) -> Option<Self> {
let data = i.into();
if size.truncate(data) == data {
Some(Self { data, size: NonZero::<u8>::new(size.bytes() as u8).unwrap() })
Some(Self { data, size: NonZero::new(size.bytes() as u8).unwrap() })
} else {
None
}
@ -220,7 +220,7 @@ impl ScalarInt {
// `into` performed sign extension, we have to truncate
let truncated = size.truncate(i as u128);
if size.sign_extend(truncated) as i128 == i {
Some(Self { data: truncated, size: NonZero::<u8>::new(size.bytes() as u8).unwrap() })
Some(Self { data: truncated, size: NonZero::new(size.bytes() as u8).unwrap() })
} else {
None
}
@ -388,7 +388,7 @@ macro_rules! from {
fn from(u: $ty) -> Self {
Self {
data: u128::from(u),
size: NonZero::<u8>::new(std::mem::size_of::<$ty>() as u8).unwrap(),
size: NonZero::new(std::mem::size_of::<$ty>() as u8).unwrap(),
}
}
}
@ -427,10 +427,7 @@ impl TryFrom<ScalarInt> for bool {
impl From<char> for ScalarInt {
#[inline]
fn from(c: char) -> Self {
Self {
data: c as u128,
size: NonZero::<u8>::new(std::mem::size_of::<char>() as u8).unwrap(),
}
Self { data: c as u128, size: NonZero::new(std::mem::size_of::<char>() as u8).unwrap() }
}
}
@ -457,7 +454,7 @@ impl From<Single> for ScalarInt {
#[inline]
fn from(f: Single) -> Self {
// We trust apfloat to give us properly truncated data.
Self { data: f.to_bits(), size: NonZero::<u8>::new((Single::BITS / 8) as u8).unwrap() }
Self { data: f.to_bits(), size: NonZero::new((Single::BITS / 8) as u8).unwrap() }
}
}
@ -473,7 +470,7 @@ impl From<Double> for ScalarInt {
#[inline]
fn from(f: Double) -> Self {
// We trust apfloat to give us properly truncated data.
Self { data: f.to_bits(), size: NonZero::<u8>::new((Double::BITS / 8) as u8).unwrap() }
Self { data: f.to_bits(), size: NonZero::new((Double::BITS / 8) as u8).unwrap() }
}
}

View file

@ -143,9 +143,8 @@ impl<'tcx> From<ty::Term<'tcx>> for GenericArg<'tcx> {
impl<'tcx> GenericArg<'tcx> {
#[inline]
pub fn unpack(self) -> GenericArgKind<'tcx> {
let ptr = unsafe {
self.ptr.map_addr(|addr| NonZero::<usize>::new_unchecked(addr.get() & !TAG_MASK))
};
let ptr =
unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) };
// SAFETY: use of `Interned::new_unchecked` here is ok because these
// pointers were originally created from `Interned` types in `pack()`,
// and this is just going in the other direction.

View file

@ -761,7 +761,7 @@ where
};
tcx.mk_layout(LayoutS {
variants: Variants::Single { index: variant_index },
fields: match NonZero::<usize>::new(fields) {
fields: match NonZero::new(fields) {
Some(fields) => FieldsShape::Union(fields),
None => FieldsShape::Arbitrary { offsets: IndexVec::new(), memory_index: IndexVec::new() },
},

View file

@ -617,9 +617,8 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Term<'tcx> {
impl<'tcx> Term<'tcx> {
#[inline]
pub fn unpack(self) -> TermKind<'tcx> {
let ptr = unsafe {
self.ptr.map_addr(|addr| NonZero::<usize>::new_unchecked(addr.get() & !TAG_MASK))
};
let ptr =
unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) };
// SAFETY: use of `Interned::new_unchecked` here is ok because these
// pointers were originally created from `Interned` types in `pack()`,
// and this is just going in the other direction.