about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-03-11 17:50:26 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-03-12 05:53:47 +0000
commitbbedde835e1b9bb3ec9255c2b49e5cac2398ece0 (patch)
tree132b225fa2a926e9d2e19dc4297f58a74305a59b
parentbbbf06d5e9bb977b09a6c4aeb50b5b8a9488d475 (diff)
downloadrust-bbedde835e1b9bb3ec9255c2b49e5cac2398ece0.tar.gz
rust-bbedde835e1b9bb3ec9255c2b49e5cac2398ece0.zip
Exhaustively match on the mutability and nestedness
-rw-r--r--compiler/rustc_const_eval/src/interpret/validity.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs
index 44409d46473..d18600ce7d7 100644
--- a/compiler/rustc_const_eval/src/interpret/validity.rs
+++ b/compiler/rustc_const_eval/src/interpret/validity.rs
@@ -483,12 +483,14 @@ 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 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 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
                             {
                                 Mutability::Mut
                             }
-                            _ => Mutability::Not,
+                            (Mutability::Not, false) => Mutability::Not,
                         }
                     }
                     GlobalAlloc::Memory(alloc) => alloc.inner().mutability,