Skip to content

Commit

Permalink
Do not assert mutability of allocations for type errors
Browse files Browse the repository at this point in the history
We do not know whether a type error was supposed to be mutable or not.
  • Loading branch information
Noratrieb committed May 25, 2024
1 parent 49f9724 commit 333296f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_middle::mir::interpret::{
ValidationErrorInfo, ValidationErrorKind, ValidationErrorKind::*,
};
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_span::symbol::{sym, Symbol};
use rustc_target::abi::{
Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
Expand Down Expand Up @@ -724,20 +724,21 @@ fn mutability<'mir, 'tcx: 'mir>(
// so just use the declared mutability.
mutability
} else {
let ty = ecx
.tcx
.type_of(did)
.no_bound_vars()
.expect("statics should not have generic parameters");
let mutability = match mutability {
Mutability::Not
if !ecx
.tcx
.type_of(did)
.no_bound_vars()
.expect("statics should not have generic parameters")
.is_freeze(*ecx.tcx, ty::ParamEnv::reveal_all()) =>
{
Mutability::Not if !ty.is_freeze(*ecx.tcx, ty::ParamEnv::reveal_all()) => {
Mutability::Mut
}
_ => mutability,
};
if let Some((_, alloc)) = ecx.memory.alloc_map.get(alloc_id) {
if let Some((_, alloc)) = ecx.memory.alloc_map.get(alloc_id)
// For type errors, we do not know whether they are supposed to be mutable or not.
&& !ty.references_error()
{
assert_eq!(alloc.mutability, mutability);
}
mutability
Expand Down

0 comments on commit 333296f

Please sign in to comment.