File tree Expand file tree Collapse file tree 4 files changed +12
-14
lines changed
Expand file tree Collapse file tree 4 files changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,10 @@ impl NodeId {
1616 /// # Panics
1717 /// Panics if `idx` is `u32::MAX`.
1818 pub const fn new ( idx : u32 ) -> Self {
19- // We could use `NonMaxU32::new(idx).unwrap()` but `Option::unwrap` is not a const function
20- // and we want this function to be
21- assert ! ( idx != u32 :: MAX ) ;
22- // SAFETY: We have checked that `idx` is not `u32::MAX`
23- unsafe { Self :: new_unchecked ( idx) }
19+ if let Some ( idx) = NonMaxU32 :: new ( idx) {
20+ return Self ( idx) ;
21+ }
22+ panic ! ( ) ;
2423 }
2524
2625 /// Create `NodeId` from `u32` unchecked.
@@ -38,7 +37,7 @@ impl Idx for NodeId {
3837 #[ allow( clippy:: cast_possible_truncation) ]
3938 fn from_usize ( idx : usize ) -> Self {
4039 assert ! ( idx < u32 :: MAX as usize ) ;
41- // SAFETY: We just checked `idx` is valid for `NonMaxU32`
40+ // SAFETY: We just checked `idx` is a legal value for `NonMaxU32`
4241 Self ( unsafe { NonMaxU32 :: new_unchecked ( idx as u32 ) } )
4342 }
4443
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ impl Idx for ReferenceId {
1212 #[ allow( clippy:: cast_possible_truncation) ]
1313 fn from_usize ( idx : usize ) -> Self {
1414 assert ! ( idx < u32 :: MAX as usize ) ;
15- // SAFETY: We just checked `idx` is valid for `NonMaxU32`
15+ // SAFETY: We just checked `idx` is a legal value for `NonMaxU32`
1616 Self ( unsafe { NonMaxU32 :: new_unchecked ( idx as u32 ) } )
1717 }
1818
Original file line number Diff line number Diff line change @@ -13,11 +13,10 @@ impl ScopeId {
1313 /// # Panics
1414 /// Panics if `idx` is `u32::MAX`.
1515 pub const fn new ( idx : u32 ) -> Self {
16- // We could use `NonMaxU32::new(idx).unwrap()` but `Option::unwrap` is not a const function
17- // and we want this function to be
18- assert ! ( idx != u32 :: MAX ) ;
19- // SAFETY: We have checked that `idx` is not `u32::MAX`
20- unsafe { Self :: new_unchecked ( idx) }
16+ if let Some ( idx) = NonMaxU32 :: new ( idx) {
17+ return Self ( idx) ;
18+ }
19+ panic ! ( ) ;
2120 }
2221
2322 /// Create `ScopeId` from `u32` unchecked.
@@ -35,7 +34,7 @@ impl Idx for ScopeId {
3534 #[ allow( clippy:: cast_possible_truncation) ]
3635 fn from_usize ( idx : usize ) -> Self {
3736 assert ! ( idx < u32 :: MAX as usize ) ;
38- // SAFETY: We just checked `idx` is valid for `NonMaxU32`
37+ // SAFETY: We just checked `idx` is a legal value for `NonMaxU32`
3938 Self ( unsafe { NonMaxU32 :: new_unchecked ( idx as u32 ) } )
4039 }
4140
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ impl Idx for SymbolId {
1111 #[ allow( clippy:: cast_possible_truncation) ]
1212 fn from_usize ( idx : usize ) -> Self {
1313 assert ! ( idx < u32 :: MAX as usize ) ;
14- // SAFETY: We just checked `idx` is valid for `NonMaxU32`
14+ // SAFETY: We just checked `idx` is a legal value for `NonMaxU32`
1515 Self ( unsafe { NonMaxU32 :: new_unchecked ( idx as u32 ) } )
1616 }
1717
You can’t perform that action at this time.
0 commit comments