Skip to content

Commit

Permalink
Run the "is this static mutable" logic the same way as in `in_mutable…
Browse files Browse the repository at this point in the history
…_memory`
  • Loading branch information
oli-obk committed Apr 17, 2024
1 parent 8c9cba2 commit d87e963
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,21 +491,23 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
}
// Return alloc mutability. For "root" statics we look at the type to account for interior
// mutability; for nested statics we have no type and directly use the annotated mutability.
match (mutability, nested) {
(Mutability::Mut, _) => Mutability::Mut,
(Mutability::Not, true) => Mutability::Not,
(Mutability::Not, false)
if !self
.ecx
.tcx
.type_of(did)
.no_bound_vars()
.expect("statics should not have generic parameters")
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all()) =>
{
Mutability::Mut
if nested {
mutability
} else {
match mutability {
Mutability::Not
if !self
.ecx
.tcx
.type_of(did)
.no_bound_vars()
.expect("statics should not have generic parameters")
.is_freeze(*self.ecx.tcx, ty::ParamEnv::reveal_all()) =>
{
Mutability::Mut
}
_ => mutability,
}
(Mutability::Not, false) => Mutability::Not,
}
}
GlobalAlloc::Memory(alloc) => alloc.inner().mutability,
Expand Down

0 comments on commit d87e963

Please sign in to comment.