@@ -454,20 +454,17 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
454
454
// here since we cannot know if there really is an `UnsafeCell` inside
455
455
// `Option<UnsafeCell>` -- so we check that in the recursive descent behind this
456
456
// reference.
457
- if size == Size :: ZERO || tam. mutbl == Mutability :: Not {
458
- Mutability :: Not
459
- } else {
460
- Mutability :: Mut
461
- }
457
+ if size == Size :: ZERO { Mutability :: Not } else { tam. mutbl }
462
458
}
463
459
} ;
464
460
// Proceed recursively even for ZST, no reason to skip them!
465
461
// `!` is a ZST and we want to validate it.
466
462
if let Ok ( ( alloc_id, _offset, _prov) ) = self . ecx . ptr_try_get_alloc_id ( place. ptr ( ) ) {
467
463
// Let's see what kind of memory this points to.
468
- let alloc_kind = self . ecx . tcx . try_get_global_alloc ( alloc_id) ;
464
+ // `unwrap` since dangling pointers have already been handled.
465
+ let alloc_kind = self . ecx . tcx . try_get_global_alloc ( alloc_id) . unwrap ( ) ;
469
466
match alloc_kind {
470
- Some ( GlobalAlloc :: Static ( did) ) => {
467
+ GlobalAlloc :: Static ( did) => {
471
468
// Special handling for pointers to statics (irrespective of their type).
472
469
assert ! ( !self . ecx. tcx. is_thread_local_static( did) ) ;
473
470
assert ! ( self . ecx. tcx. is_static( did) ) ;
@@ -506,7 +503,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
506
503
// referring to statics).
507
504
return Ok ( ( ) ) ;
508
505
}
509
- Some ( GlobalAlloc :: Memory ( alloc) ) => {
506
+ GlobalAlloc :: Memory ( alloc) => {
510
507
if alloc. inner ( ) . mutability == Mutability :: Mut
511
508
&& matches ! ( self . ctfe_mode, Some ( CtfeValidationMode :: Const { .. } ) )
512
509
{
@@ -525,14 +522,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
525
522
throw_validation_failure ! ( self . path, MutableRefToImmutable ) ;
526
523
}
527
524
}
528
- Some ( GlobalAlloc :: Function ( ..) | GlobalAlloc :: VTable ( ..) ) => {
525
+ GlobalAlloc :: Function ( ..) | GlobalAlloc :: VTable ( ..) => {
529
526
// These are immutable, we better don't allow mutable pointers here.
530
527
if ptr_expected_mutbl == Mutability :: Mut {
531
528
throw_validation_failure ! ( self . path, MutableRefToImmutable ) ;
532
529
}
533
530
}
534
- // Dangling, already handled.
535
- None => bug ! ( ) ,
536
531
}
537
532
}
538
533
let path = & self . path ;
0 commit comments