From 333296fcbc7e1f87b99331cdd5a624cbad940907 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 25 May 2024 22:38:09 +0200 Subject: [PATCH] Do not assert mutability of allocations for type errors We do not know whether a type error was supposed to be mutable or not. --- .../src/interpret/validity.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index cf6027a312fa2..f9a86c927653c 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -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, @@ -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