1
Fork 0

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.
This commit is contained in:
Vadim Petrochenkov 2024-06-16 00:53:00 +03:00
parent 12b33d36f3
commit 14da80c372
6 changed files with 33 additions and 14 deletions

View file

@ -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