From bbedde835e1b9bb3ec9255c2b49e5cac2398ece0 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 11 Mar 2024 17:50:26 +0000 Subject: [PATCH] Exhaustively match on the mutability and nestedness --- .../rustc_const_eval/src/interpret/validity.rs | 16 +++++++++------- 1 file 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,