@@ -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) ) ;
@@ -682,7 +682,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
682
682
fn in_mutable_memory ( & self , op : & OpTy < ' tcx , M :: Provenance > ) -> bool {
683
683
if let Some ( mplace) = op. as_mplace_or_imm ( ) . left ( ) {
684
684
if let Some ( alloc_id) = mplace. ptr ( ) . provenance . and_then ( |p| p. get_alloc_id ( ) ) {
685
- return mutability ( self . ecx , alloc_id) . 0 . is_mut ( ) ;
685
+ return mutability ( self . ecx , alloc_id) . is_mut ( ) ;
686
686
}
687
687
}
688
688
false
@@ -695,13 +695,19 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
695
695
fn mutability < ' mir , ' tcx : ' mir > (
696
696
ecx : & InterpCx < ' mir , ' tcx , impl Machine < ' mir , ' tcx > > ,
697
697
alloc_id : AllocId ,
698
- ) -> ( Mutability , Option < ( DefId , bool ) > ) {
698
+ ) -> Mutability {
699
699
// Let's see what kind of memory this points to.
700
700
// We're not using `try_global_alloc` since dangling pointers have already been handled.
701
701
match ecx. tcx . global_alloc ( alloc_id) {
702
702
GlobalAlloc :: Static ( did) => {
703
703
let DefKind :: Static { mutability, nested } = ecx. tcx . def_kind ( did) else { bug ! ( ) } ;
704
- let mutability = if nested {
704
+ if nested {
705
+ assert ! (
706
+ ecx. memory. alloc_map. get( alloc_id) . is_none( ) ,
707
+ "allocations of nested statics are already interned: {alloc_id:?}, {did:?}"
708
+ ) ;
709
+ // Nested statics in a `static` are never interior mutable,
710
+ // so just use the declared mutability.
705
711
mutability
706
712
} else {
707
713
let mutability = match mutability {
@@ -721,13 +727,12 @@ fn mutability<'mir, 'tcx: 'mir>(
721
727
assert_eq ! ( alloc. mutability, mutability) ;
722
728
}
723
729
mutability
724
- } ;
725
- ( mutability, Some ( ( did, nested) ) )
730
+ }
726
731
}
727
- GlobalAlloc :: Memory ( alloc) => ( alloc. inner ( ) . mutability , None ) ,
732
+ GlobalAlloc :: Memory ( alloc) => alloc. inner ( ) . mutability ,
728
733
GlobalAlloc :: Function ( ..) | GlobalAlloc :: VTable ( ..) => {
729
734
// These are immutable, we better don't allow mutable pointers here.
730
- ( Mutability :: Not , None )
735
+ Mutability :: Not
731
736
}
732
737
}
733
738
}
0 commit comments