Skip to content

Commit

Permalink
Check the base type of pattern types for validty first
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 2, 2025
1 parent 7c0ed54 commit 9ec62f8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 { .. } => {},
}
}
_ => {
Expand Down

0 comments on commit 9ec62f8

Please sign in to comment.