@@ -20,7 +20,7 @@ use rustc_middle::mir::interpret::{
20
20
ValidationErrorInfo , ValidationErrorKind , ValidationErrorKind :: * ,
21
21
} ;
22
22
use rustc_middle:: ty:: layout:: { LayoutOf , TyAndLayout } ;
23
- use rustc_middle:: ty:: { self , Ty } ;
23
+ use rustc_middle:: ty:: { self , Ty , TypeVisitableExt } ;
24
24
use rustc_span:: symbol:: { sym, Symbol } ;
25
25
use rustc_target:: abi:: {
26
26
Abi , FieldIdx , Scalar as ScalarAbi , Size , VariantIdx , Variants , WrappingRange ,
@@ -724,20 +724,21 @@ fn mutability<'mir, 'tcx: 'mir>(
724
724
// so just use the declared mutability.
725
725
mutability
726
726
} else {
727
+ let ty = ecx
728
+ . tcx
729
+ . type_of ( did)
730
+ . no_bound_vars ( )
731
+ . expect ( "statics should not have generic parameters" ) ;
727
732
let mutability = match mutability {
728
- Mutability :: Not
729
- if !ecx
730
- . tcx
731
- . type_of ( did)
732
- . no_bound_vars ( )
733
- . expect ( "statics should not have generic parameters" )
734
- . is_freeze ( * ecx. tcx , ty:: ParamEnv :: reveal_all ( ) ) =>
735
- {
733
+ Mutability :: Not if !ty. is_freeze ( * ecx. tcx , ty:: ParamEnv :: reveal_all ( ) ) => {
736
734
Mutability :: Mut
737
735
}
738
736
_ => mutability,
739
737
} ;
740
- if let Some ( ( _, alloc) ) = ecx. memory . alloc_map . get ( alloc_id) {
738
+ if let Some ( ( _, alloc) ) = ecx. memory . alloc_map . get ( alloc_id)
739
+ // For type errors, we do not know whether they are supposed to be mutable or not.
740
+ && !ty. references_error ( )
741
+ {
741
742
assert_eq ! ( alloc. mutability, mutability) ;
742
743
}
743
744
mutability
0 commit comments