about summary refs log tree commit diff
path: root/compiler/rustc_index_macros
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_index_macros')
-rw-r--r--compiler/rustc_index_macros/src/newtype.rs15
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