Exhaustively match on the mutability and nestedness

This commit is contained in:
Oli Scherer 2024-03-11 17:50:26 +00:00
parent bbbf06d5e9
commit bbedde835e

View file

@ -483,12 +483,14 @@ 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 self.ecx.tcx.def_kind(did) {
DefKind::Static { mutability: Mutability::Mut, .. } => Mutability::Mut,
DefKind::Static { mutability: Mutability::Not, nested: true } => {
Mutability::Not
}
DefKind::Static { mutability: Mutability::Not, nested: false }
let DefKind::Static { mutability, nested } = self.ecx.tcx.def_kind(did)
else {
bug!()
};
match (mutability, nested) {
(Mutability::Mut, _) => Mutability::Mut,
(Mutability::Not, true) => Mutability::Not,
(Mutability::Not, false)
if !self
.ecx
.tcx
@ -499,7 +501,7 @@ fn check_safe_pointer(
{
Mutability::Mut
}
_ => Mutability::Not,
(Mutability::Not, false) => Mutability::Not,
}
}
GlobalAlloc::Memory(alloc) => alloc.inner().mutability,