@@ -21,7 +21,7 @@ use std::hash::Hash;
2121
2222use super :: {
2323 alloc_range, CheckInAllocMsg , GlobalAlloc , InterpCx , InterpResult , MPlaceTy , Machine ,
24- MemPlaceMeta , OpTy , ScalarMaybeUninit , ValueVisitor ,
24+ MemPlaceMeta , OpTy , Scalar , ScalarMaybeUninit , ValueVisitor ,
2525} ;
2626
2727macro_rules! throw_validation_failure {
@@ -521,8 +521,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
521521 // NOTE: Keep this in sync with the array optimization for int/float
522522 // types below!
523523 if M :: enforce_number_validity ( self . ecx ) {
524- // Integers/floats in CTFE: Must be scalar bits, pointers are dangerous
525- let is_bits = value. check_init ( ) . map_or ( false , |v| v. try_to_int ( ) . is_ok ( ) ) ;
524+ // Integers/floats with number validity: Must be scalar bits, pointers are dangerous.
525+ // As a special exception we *do* match on a `Scalar` here, since we truly want
526+ // to know its underlying representation (and *not* cast it to an integer).
527+ let is_bits =
528+ value. check_init ( ) . map_or ( false , |v| matches ! ( v, Scalar :: Int ( ..) ) ) ;
526529 if !is_bits {
527530 throw_validation_failure ! ( self . path,
528531 { "{:x}" , value } expected { "initialized plain (non-pointer) bytes" }
0 commit comments