Skip to content

Commit 44a576c

Browse files
committed
Do not assert mutability of allocations for type errors
We do not know whether a type error was supposed to be mutable or not.
1 parent 7314f82 commit 44a576c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::mir::interpret::{
2020
ValidationErrorInfo, ValidationErrorKind, ValidationErrorKind::*,
2121
};
2222
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
23-
use rustc_middle::ty::{self, Ty};
23+
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
2424
use rustc_span::symbol::{sym, Symbol};
2525
use rustc_target::abi::{
2626
Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
@@ -724,20 +724,21 @@ fn mutability<'mir, 'tcx: 'mir>(
724724
// so just use the declared mutability.
725725
mutability
726726
} else {
727+
let ty = ecx
728+
.tcx
729+
.type_of(did)
730+
.no_bound_vars()
731+
.expect("statics should not have generic parameters");
727732
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()) => {
736734
Mutability::Mut
737735
}
738736
_ => mutability,
739737
};
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+
{
741742
assert_eq!(alloc.mutability, mutability);
742743
}
743744
mutability

0 commit comments

Comments
 (0)