@@ -10,7 +10,6 @@ use std::num::NonZero;
10
10
use either:: { Left , Right } ;
11
11
12
12
use hir:: def:: DefKind ;
13
- use hir:: def_id:: DefId ;
14
13
use rustc_ast:: Mutability ;
15
14
use rustc_data_structures:: fx:: FxHashSet ;
16
15
use rustc_hir as hir;
@@ -450,8 +449,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
450
449
// `!` is a ZST and we want to validate it.
451
450
if let Ok ( ( alloc_id, _offset, _prov) ) = self . ecx . ptr_try_get_alloc_id ( place. ptr ( ) ) {
452
451
let mut skip_recursive_check = false ;
453
- let ( alloc_actual_mutbl, is_static) = mutability ( self . ecx , alloc_id) ;
454
- if let Some ( ( did, nested) ) = is_static {
452
+ let alloc_actual_mutbl = mutability ( self . ecx , alloc_id) ;
453
+ if let GlobalAlloc :: Static ( did) = self . ecx . tcx . global_alloc ( alloc_id) {
454
+ let DefKind :: Static { nested, .. } = self . ecx . tcx . def_kind ( did) else { bug ! ( ) } ;
455
455
// Special handling for pointers to statics (irrespective of their type).
456
456
assert ! ( !self . ecx. tcx. is_thread_local_static( did) ) ;
457
457
assert ! ( self . ecx. tcx. is_static( did) ) ;
@@ -681,7 +681,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
681
681
fn in_mutable_memory ( & self , op : & OpTy < ' tcx , M :: Provenance > ) -> bool {
682
682
if let Some ( mplace) = op. as_mplace_or_imm ( ) . left ( ) {
683
683
if let Some ( alloc_id) = mplace. ptr ( ) . provenance . and_then ( |p| p. get_alloc_id ( ) ) {
684
- return mutability ( self . ecx , alloc_id) . 0 . is_mut ( ) ;
684
+ return mutability ( self . ecx , alloc_id) . is_mut ( ) ;
685
685
}
686
686
}
687
687
false
@@ -694,13 +694,19 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
694
694
fn mutability < ' mir , ' tcx : ' mir > (
695
695
ecx : & InterpCx < ' mir , ' tcx , impl Machine < ' mir , ' tcx > > ,
696
696
alloc_id : AllocId ,
697
- ) -> ( Mutability , Option < ( DefId , bool ) > ) {
697
+ ) -> Mutability {
698
698
// Let's see what kind of memory this points to.
699
699
// We're not using `try_global_alloc` since dangling pointers have already been handled.
700
700
match ecx. tcx . global_alloc ( alloc_id) {
701
701
GlobalAlloc :: Static ( did) => {
702
702
let DefKind :: Static { mutability, nested } = ecx. tcx . def_kind ( did) else { bug ! ( ) } ;
703
- let mutability = if nested {
703
+ if nested {
704
+ assert ! (
705
+ ecx. memory. alloc_map. get( alloc_id) . is_none( ) ,
706
+ "allocations of nested statics are already interned: {alloc_id:?}, {did:?}"
707
+ ) ;
708
+ // Nested statics in a `static` are never interior mutable,
709
+ // so just use the declared mutability.
704
710
mutability
705
711
} else {
706
712
let mutability = match mutability {
@@ -720,13 +726,12 @@ fn mutability<'mir, 'tcx: 'mir>(
720
726
assert_eq ! ( alloc. mutability, mutability) ;
721
727
}
722
728
mutability
723
- } ;
724
- ( mutability, Some ( ( did, nested) ) )
729
+ }
725
730
}
726
- GlobalAlloc :: Memory ( alloc) => ( alloc. inner ( ) . mutability , None ) ,
731
+ GlobalAlloc :: Memory ( alloc) => alloc. inner ( ) . mutability ,
727
732
GlobalAlloc :: Function ( ..) | GlobalAlloc :: VTable ( ..) => {
728
733
// These are immutable, we better don't allow mutable pointers here.
729
- ( Mutability :: Not , None )
734
+ Mutability :: Not
730
735
}
731
736
}
732
737
}
0 commit comments