Run the "is this static mutable" logic the same way as in in_mutable_memory

This commit is contained in:
Oli Scherer 2024-04-02 14:54:34 +00:00
parent 8c9cba2be7
commit d87e9636d5

View File

@ -491,21 +491,23 @@ fn check_safe_pointer(
}
// 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,