diff options
Diffstat (limited to 'compiler/rustc_metadata/src')
| -rw-r--r-- | compiler/rustc_metadata/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/encoder.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/mod.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/table.rs | 6 |
5 files changed, 26 insertions, 23 deletions
diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 2e7130f3565..70ad8598957 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -5,6 +5,7 @@ #![feature(decl_macro)] #![feature(extract_if)] #![feature(coroutines)] +#![feature(generic_nonzero)] #![feature(iter_from_coroutine)] #![feature(let_chains)] #![feature(if_let_guard)] diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 72e9744295b..8a031e4f3a3 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -327,7 +327,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { } #[inline] - fn read_lazy_offset_then<T>(&mut self, f: impl Fn(NonZeroUsize) -> T) -> T { + fn read_lazy_offset_then<T>(&mut self, f: impl Fn(NonZero<usize>) -> T) -> T { let distance = self.read_usize(); let position = match self.lazy_state { LazyState::NoNode => bug!("read_lazy_with_meta: outside of a metadata node"), @@ -338,7 +338,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { } LazyState::Previous(last_pos) => last_pos.get() + distance, }; - let position = NonZeroUsize::new(position).unwrap(); + let position = NonZero::<usize>::new(position).unwrap(); self.lazy_state = LazyState::Previous(position); f(position) } @@ -685,15 +685,17 @@ impl MetadataBlob { } pub(crate) fn get_rustc_version(&self) -> String { - LazyValue::<String>::from_position(NonZeroUsize::new(METADATA_HEADER.len() + 8).unwrap()) - .decode(self) + LazyValue::<String>::from_position( + NonZero::<usize>::new(METADATA_HEADER.len() + 8).unwrap(), + ) + .decode(self) } - fn root_pos(&self) -> NonZeroUsize { + fn root_pos(&self) -> NonZero<usize> { let offset = METADATA_HEADER.len(); let pos_bytes = self.blob()[offset..][..8].try_into().unwrap(); let pos = u64::from_le_bytes(pos_bytes); - NonZeroUsize::new(pos as usize).unwrap() + NonZero::<usize>::new(pos as usize).unwrap() } pub(crate) fn get_header(&self) -> CrateHeader { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 4a24c038f7a..51d747efdd3 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -421,7 +421,7 @@ macro_rules! record_defaulted_array { } impl<'a, 'tcx> EncodeContext<'a, 'tcx> { - fn emit_lazy_distance(&mut self, position: NonZeroUsize) { + fn emit_lazy_distance(&mut self, position: NonZero<usize>) { let pos = position.get(); let distance = match self.lazy_state { LazyState::NoNode => bug!("emit_lazy_distance: outside of a metadata node"), @@ -439,7 +439,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { position.get() - last_pos.get() } }; - self.lazy_state = LazyState::Previous(NonZeroUsize::new(pos).unwrap()); + self.lazy_state = LazyState::Previous(NonZero::<usize>::new(pos).unwrap()); self.emit_usize(distance); } @@ -447,7 +447,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { where T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>, { - let pos = NonZeroUsize::new(self.position()).unwrap(); + let pos = NonZero::<usize>::new(self.position()).unwrap(); assert_eq!(self.lazy_state, LazyState::NoNode); self.lazy_state = LazyState::NodeStart(pos); @@ -466,7 +466,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { where T::Value<'tcx>: Encodable<EncodeContext<'a, 'tcx>>, { - let pos = NonZeroUsize::new(self.position()).unwrap(); + let pos = NonZero::<usize>::new(self.position()).unwrap(); assert_eq!(self.lazy_state, LazyState::NoNode); self.lazy_state = LazyState::NodeStart(pos); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 4d0a6cb60ee..81d834e0456 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -37,7 +37,7 @@ use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_target::spec::{PanicStrategy, TargetTriple}; use std::marker::PhantomData; -use std::num::NonZeroUsize; +use std::num::NonZero; use decoder::DecodeContext; pub(crate) use decoder::{CrateMetadata, CrateNumMap, MetadataBlob}; @@ -83,7 +83,7 @@ pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_V /// order than they were encoded in. #[must_use] struct LazyValue<T> { - position: NonZeroUsize, + position: NonZero<usize>, _marker: PhantomData<fn() -> T>, } @@ -92,7 +92,7 @@ impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyValue<T> { } impl<T> LazyValue<T> { - fn from_position(position: NonZeroUsize) -> LazyValue<T> { + fn from_position(position: NonZero<usize>) -> LazyValue<T> { LazyValue { position, _marker: PhantomData } } } @@ -108,7 +108,7 @@ impl<T> LazyValue<T> { /// the minimal distance the length of the sequence, i.e. /// it's assumed there's no 0-byte element in the sequence. struct LazyArray<T> { - position: NonZeroUsize, + position: NonZero<usize>, num_elems: usize, _marker: PhantomData<fn() -> T>, } @@ -119,12 +119,12 @@ impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyArray<T> { impl<T> Default for LazyArray<T> { fn default() -> LazyArray<T> { - LazyArray::from_position_and_num_elems(NonZeroUsize::new(1).unwrap(), 0) + LazyArray::from_position_and_num_elems(NonZero::<usize>::new(1).unwrap(), 0) } } impl<T> LazyArray<T> { - fn from_position_and_num_elems(position: NonZeroUsize, num_elems: usize) -> LazyArray<T> { + fn from_position_and_num_elems(position: NonZero<usize>, num_elems: usize) -> LazyArray<T> { LazyArray { position, num_elems, _marker: PhantomData } } } @@ -135,7 +135,7 @@ impl<T> LazyArray<T> { /// `LazyArray<T>`, but without requiring encoding or decoding all the values /// eagerly and in-order. struct LazyTable<I, T> { - position: NonZeroUsize, + position: NonZero<usize>, /// The encoded size of the elements of a table is selected at runtime to drop /// trailing zeroes. This is the number of bytes used for each table element. width: usize, @@ -150,7 +150,7 @@ impl<I: 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for LazyTable<I, impl<I, T> LazyTable<I, T> { fn from_position_and_encoded_size( - position: NonZeroUsize, + position: NonZero<usize>, width: usize, len: usize, ) -> LazyTable<I, T> { @@ -187,11 +187,11 @@ enum LazyState { /// Inside a metadata node, and before any `Lazy`s. /// The position is that of the node itself. - NodeStart(NonZeroUsize), + NodeStart(NonZero<usize>), /// Inside a metadata node, with a previous `Lazy`s. /// The position is where that previous `Lazy` would start. - Previous(NonZeroUsize), + Previous(NonZero<usize>), } type SyntaxContextTable = LazyTable<u32, Option<LazyValue<SyntaxContextData>>>; diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 306bf07a976..00752ad15a3 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -339,7 +339,7 @@ impl<T> FixedSizeEncoding for Option<LazyValue<T>> { #[inline] fn from_bytes(b: &[u8; 8]) -> Self { - let position = NonZeroUsize::new(u64::from_bytes(b) as usize)?; + let position = NonZero::<usize>::new(u64::from_bytes(b) as usize)?; Some(LazyValue::from_position(position)) } @@ -366,7 +366,7 @@ impl<T> LazyArray<T> { } fn from_bytes_impl(position: &[u8; 8], meta: &[u8; 8]) -> Option<LazyArray<T>> { - let position = NonZeroUsize::new(u64::from_bytes(position) as usize)?; + let position = NonZero::<usize>::new(u64::from_bytes(position) as usize)?; let len = u64::from_bytes(meta) as usize; Some(LazyArray::from_position_and_num_elems(position, len)) } @@ -497,7 +497,7 @@ impl<I: Idx, const N: usize, T: FixedSizeEncoding<ByteArray = [u8; N]>> TableBui } LazyTable::from_position_and_encoded_size( - NonZeroUsize::new(pos).unwrap(), + NonZero::<usize>::new(pos).unwrap(), width, self.blocks.len(), ) |
