Skip to content

Commit bbedde8

Browse files
committed
Exhaustively match on the mutability and nestedness
1 parent bbbf06d commit bbedde8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,14 @@ 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-
match self.ecx.tcx.def_kind(did) {
487-
DefKind::Static { mutability: Mutability::Mut, .. } => Mutability::Mut,
488-
DefKind::Static { mutability: Mutability::Not, nested: true } => {
489-
Mutability::Not
490-
}
491-
DefKind::Static { mutability: Mutability::Not, nested: false }
486+
let DefKind::Static { mutability, nested } = self.ecx.tcx.def_kind(did)
487+
else {
488+
bug!()
489+
};
490+
match (mutability, nested) {
491+
(Mutability::Mut, _) => Mutability::Mut,
492+
(Mutability::Not, true) => Mutability::Not,
493+
(Mutability::Not, false)
492494
if !self
493495
.ecx
494496
.tcx
@@ -499,7 +501,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
499501
{
500502
Mutability::Mut
501503
}
502-
_ => Mutability::Not,
504+
(Mutability::Not, false) => Mutability::Not,
503505
}
504506
}
505507
GlobalAlloc::Memory(alloc) => alloc.inner().mutability,

0 commit comments

Comments
 (0)