@@ -21,7 +21,7 @@ use std::hash::Hash;
21
21
22
22
use super :: {
23
23
alloc_range, CheckInAllocMsg , GlobalAlloc , InterpCx , InterpResult , MPlaceTy , Machine ,
24
- MemPlaceMeta , OpTy , ScalarMaybeUninit , ValueVisitor ,
24
+ MemPlaceMeta , OpTy , Scalar , ScalarMaybeUninit , ValueVisitor ,
25
25
} ;
26
26
27
27
macro_rules! throw_validation_failure {
@@ -521,8 +521,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
521
521
// NOTE: Keep this in sync with the array optimization for int/float
522
522
// types below!
523
523
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 ( ..) ) ) ;
526
529
if !is_bits {
527
530
throw_validation_failure ! ( self . path,
528
531
{ "{:x}" , value } expected { "initialized plain (non-pointer) bytes" }
0 commit comments