about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/validity.rs
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-01-27 16:36:45 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-02-02 19:28:22 +0000
commit2f2b32b84e778669e06be5e37643f21ba98bedc8 (patch)
treeeb95a6ca1d762dfec8c0c49004df2459d860f9be /compiler/rustc_const_eval/src/interpret/validity.rs
parente1f09207fb273b10fee01c0bef1b2c6130eaea80 (diff)
downloadrust-2f2b32b84e778669e06be5e37643f21ba98bedc8.tar.gz
rust-2f2b32b84e778669e06be5e37643f21ba98bedc8.zip
Test validity of pattern types
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/validity.rs')
-rw-r--r--compiler/rustc_const_eval/src/interpret/validity.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs
index d75df1ad442..649a759bc8b 100644
--- a/compiler/rustc_const_eval/src/interpret/validity.rs
+++ b/compiler/rustc_const_eval/src/interpret/validity.rs
@@ -4,6 +4,7 @@
 //! That's useful because it means other passes (e.g. promotion) can rely on `const`s
 //! to be const-safe.
 
+use std::assert_matches::assert_matches;
 use std::borrow::Cow;
 use std::fmt::Write;
 use std::hash::Hash;
@@ -1240,6 +1241,17 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
                     self.visit_field(val, 0, &self.ecx.project_index(val, 0)?)?;
                 }
             }
+            ty::Pat(_base, pat) => {
+                // When you extend this match, make sure to also add tests to
+                // tests/ui/type/pattern_types/validity.rs((
+                match **pat {
+                    // Range patterns are precisely reflected into `valid_range` and thus
+                    // handled fully by `visit_scalar` (called below).
+                    ty::PatternKind::Range { .. } => {
+                        assert_matches!(val.layout.backend_repr, BackendRepr::Scalar(_));
+                    },
+                }
+            }
             _ => {
                 // default handler
                 try_validation!(