diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-02-02 17:54:35 +0000 | 
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-02-02 19:30:53 +0000 | 
| commit | ded0836c18a0b25f076ee776e1c9eeb989272f3b (patch) | |
| tree | fda26aaf4de1fbd14636dfbc25e274c9ff87739a /compiler/rustc_const_eval/src/interpret/validity.rs | |
| parent | 2f2b32b84e778669e06be5e37643f21ba98bedc8 (diff) | |
| download | rust-ded0836c18a0b25f076ee776e1c9eeb989272f3b.tar.gz rust-ded0836c18a0b25f076ee776e1c9eeb989272f3b.zip | |
Check the base type of pattern types for validity first
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/validity.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/validity.rs | 9 | 
1 files changed, 4 insertions, 5 deletions
| diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 649a759bc8b..8e544798742 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -4,7 +4,6 @@ //! 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; @@ -1241,15 +1240,15 @@ 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) => { + ty::Pat(base, pat) => { + // First check that the base type is valid + self.visit_value(&val.transmute(self.ecx.layout_of(*base)?, self.ecx)?)?; // 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(_)); - }, + ty::PatternKind::Range { .. } => {}, } } _ => { | 
