@@ -688,7 +688,7 @@ impl Primitive {
688688///
689689/// This is intended specifically to mirror LLVM’s `!range` metadata,
690690/// semantics.
691- #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
691+ #[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
692692#[ derive( HashStable_Generic ) ]
693693pub struct AllocationRange {
694694 pub start : u128 ,
@@ -705,6 +705,13 @@ impl AllocationRange {
705705 self . start <= v || v <= self . end
706706 }
707707 }
708+
709+ /// Returns `true` if zero is contained in the range.
710+ /// Equal to `range.contains(0)` but should be faster.
711+ #[ inline]
712+ pub fn contains_zero ( & self ) -> bool {
713+ !( self . start <= self . end && self . start != 0 )
714+ }
708715}
709716
710717/// Information about one scalar component of a Rust type.
@@ -1222,9 +1229,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
12221229 {
12231230 let scalar_allows_raw_init = move |s : & Scalar | -> bool {
12241231 if zero {
1225- let range = & s. valid_range ;
12261232 // The range must contain 0.
1227- range . contains ( 0 ) || ( range . start > range . end ) // wrap-around allows 0
1233+ s . valid_range . contains_zero ( )
12281234 } else {
12291235 // The range must include all values. `valid_range_exclusive` handles
12301236 // the wrap-around using target arithmetic; with wrap-around then the full
0 commit comments