diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2024-06-16 00:53:00 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2024-06-16 14:08:25 +0300 |
| commit | 14da80c37279ada8d92d3f900414ebc0d7935e13 (patch) | |
| tree | c60adcf97679dcaff62880e42726206b57d10002 /compiler/rustc_index_macros | |
| parent | 12b33d36f3de0fb30ca08c49f5b2f4fa111861a4 (diff) | |
| download | rust-14da80c37279ada8d92d3f900414ebc0d7935e13.tar.gz rust-14da80c37279ada8d92d3f900414ebc0d7935e13.zip | |
rustc_span: Minor improvements
Introduce `{IndexNewtype,SyntaxContext}::from_u16` for convenience because small indices are sometimes encoded as `u16`.
Use `SpanData::span` instead of `Span::new` where appropriate.
Add a clarifying comment about decoding span parents.
Diffstat (limited to 'compiler/rustc_index_macros')
| -rw-r--r-- | compiler/rustc_index_macros/src/newtype.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_index_macros/src/newtype.rs b/compiler/rustc_index_macros/src/newtype.rs index fe9a048734f..41863f7b15f 100644 --- a/compiler/rustc_index_macros/src/newtype.rs +++ b/compiler/rustc_index_macros/src/newtype.rs @@ -205,6 +205,21 @@ impl Parse for Newtype { } } + /// Creates a new index from a given `u16`. + /// + /// # Panics + /// + /// Will panic if `value` exceeds `MAX`. + #[inline] + #vis const fn from_u16(value: u16) -> Self { + let value = value as u32; + assert!(value <= #max); + // SAFETY: We just checked that `value <= max`. + unsafe { + Self::from_u32_unchecked(value) + } + } + /// Creates a new index from a given `u32`. /// /// # Safety |
