Skip to content

Commit 29508ce

Browse files
committed
normalize adt fields during structural match check
1 parent 4b1f86a commit 29508ce

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/librustc_trait_selection/traits/structural_match.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
251251
// fields of ADT.
252252
let tcx = self.tcx();
253253
for field_ty in adt_def.all_fields().map(|field| field.ty(tcx, substs)) {
254-
if field_ty.visit_with(self) {
254+
assert!(!field_ty.needs_subst());
255+
let ty = self.tcx().normalize_erasing_regions(ty::ParamEnv::reveal_all(), field_ty);
256+
debug!("structural-match ADT: field_ty={:?}, ty={:?}", field_ty, ty);
257+
258+
if ty.visit_with(self) {
255259
// found an ADT without structural-match; halt visiting!
256260
assert!(self.found.is_some());
257261
return true;

src/test/ui/match/issue-72896.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
trait EnumSetType {
3+
type Repr;
4+
}
5+
6+
enum Enum8 { }
7+
impl EnumSetType for Enum8 {
8+
type Repr = u8;
9+
}
10+
11+
#[derive(PartialEq, Eq)]
12+
struct EnumSet<T: EnumSetType> {
13+
__enumset_underlying: T::Repr,
14+
}
15+
16+
const CONST_SET: EnumSet<Enum8> = EnumSet { __enumset_underlying: 3 };
17+
18+
fn main() {
19+
match CONST_SET {
20+
CONST_SET => { /* ok */ }
21+
_ => panic!("match fell through?"),
22+
}
23+
}

0 commit comments

Comments
 (0)