Skip to content

Commit 57e8602

Browse files
committed
Run the "is this static mutable" logic the same way as in in_mutable_memory
1 parent 6e1c8a9 commit 57e8602

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -491,21 +491,23 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
491491
}
492492
// Return alloc mutability. For "root" statics we look at the type to account for interior
493493
// mutability; for nested statics we have no type and directly use the annotated mutability.
494-
match (mutability, nested) {
495-
(Mutability::Mut, _) => Mutability::Mut,
496-
(Mutability::Not, true) => Mutability::Not,
497-
(Mutability::Not, false)
498-
if !self
499-
.ecx
500-
.tcx
501-
.type_of(did)
502-
.no_bound_vars()
503-
.expect("statics should not have generic parameters")
504-
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all()) =>
505-
{
506-
Mutability::Mut
494+
if nested {
495+
mutability
496+
} else {
497+
match mutability {
498+
Mutability::Not
499+
if !self
500+
.ecx
501+
.tcx
502+
.type_of(did)
503+
.no_bound_vars()
504+
.expect("statics should not have generic parameters")
505+
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all()) =>
506+
{
507+
Mutability::Mut
508+
}
509+
_ => mutability,
507510
}
508-
(Mutability::Not, false) => Mutability::Not,
509511
}
510512
}
511513
GlobalAlloc::Memory(alloc) => alloc.inner().mutability,

0 commit comments

Comments
 (0)