Skip to content

Commit 56a4912

Browse files
committed
Make mutability taken from Freezeness of the main static alloc explicit.
Before it was hard to see that in the other cases we just preserve the static's mutability
1 parent 9d7a214 commit 56a4912

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -483,26 +483,25 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
483483
}
484484
// Return alloc mutability. For "root" statics we look at the type to account for interior
485485
// mutability; for nested statics we have no type and directly use the annotated mutability.
486-
let DefKind::Static { mutability, nested } = self.ecx.tcx.def_kind(did)
486+
let DefKind::Static { mut mutability, nested } = self.ecx.tcx.def_kind(did)
487487
else {
488488
bug!()
489489
};
490-
match (mutability, nested) {
491-
(Mutability::Mut, _) => Mutability::Mut,
492-
(Mutability::Not, true) => Mutability::Not,
493-
(Mutability::Not, false)
494-
if !self
495-
.ecx
496-
.tcx
497-
.type_of(did)
498-
.no_bound_vars()
499-
.expect("statics should not have generic parameters")
500-
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all()) =>
490+
if let Mutability::Not = mutability
491+
&& !nested
492+
{
493+
if !self
494+
.ecx
495+
.tcx
496+
.type_of(did)
497+
.no_bound_vars()
498+
.expect("statics should not have generic parameters")
499+
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all())
501500
{
502-
Mutability::Mut
501+
mutability = Mutability::Mut;
503502
}
504-
(Mutability::Not, false) => Mutability::Not,
505503
}
504+
mutability
506505
}
507506
Some(GlobalAlloc::Memory(alloc)) => alloc.inner().mutability,
508507
Some(GlobalAlloc::Function(..) | GlobalAlloc::VTable(..)) => {

0 commit comments

Comments
 (0)