Skip to content

Commit 8addb2e

Browse files
authored
Rollup merge of #72897 - lcnr:structurally-match-normalize, r=pnkfelix
normalize adt fields during structural match checking fixes #72896 currently only fixes the issue itself and compiles stage 1 libs. I believe we have to use something else to normalize the adt fields here, as I expect some partially resolved adts to cause problems 🤔 stage 1 libs and the test itself pass, not sure about the rest... Will spend some more time looking into it tomorrow. r? @pnkfelix cc @eddyb
2 parents fda594e + 4725af3 commit 8addb2e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/librustc_trait_selection/traits/structural_match.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ 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+
let ty = self.tcx().normalize_erasing_regions(ty::ParamEnv::empty(), field_ty);
255+
debug!("structural-match ADT: field_ty={:?}, ty={:?}", field_ty, ty);
256+
257+
if ty.visit_with(self) {
255258
// found an ADT without structural-match; halt visiting!
256259
assert!(self.found.is_some());
257260
return true;

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

+23
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)