Skip to content

Commit 9ec62f8

Browse files
committed
Check the base type of pattern types for validty first
1 parent 7c0ed54 commit 9ec62f8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! That's useful because it means other passes (e.g. promotion) can rely on `const`s
55
//! to be const-safe.
66
7-
use std::assert_matches::assert_matches;
87
use std::borrow::Cow;
98
use std::fmt::Write;
109
use std::hash::Hash;
@@ -1241,15 +1240,15 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt,
12411240
self.visit_field(val, 0, &self.ecx.project_index(val, 0)?)?;
12421241
}
12431242
}
1244-
ty::Pat(_base, pat) => {
1243+
ty::Pat(base, pat) => {
1244+
// First check that the base type is valid
1245+
self.visit_value(&val.transmute(self.ecx.layout_of(*base)?, self.ecx)?)?;
12451246
// When you extend this match, make sure to also add tests to
12461247
// tests/ui/type/pattern_types/validity.rs((
12471248
match **pat {
12481249
// Range patterns are precisely reflected into `valid_range` and thus
12491250
// handled fully by `visit_scalar` (called below).
1250-
ty::PatternKind::Range { .. } => {
1251-
assert_matches!(val.layout.backend_repr, BackendRepr::Scalar(_));
1252-
},
1251+
ty::PatternKind::Range { .. } => {},
12531252
}
12541253
}
12551254
_ => {

0 commit comments

Comments
 (0)