Skip to content

Commit

Permalink
Rollup merge of #72897 - lcnr:structurally-match-normalize, r=pnkfelix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Dylan-DPC authored Jun 10, 2020
2 parents fda594e + 4725af3 commit 8addb2e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/librustc_trait_selection/traits/structural_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
// fields of ADT.
let tcx = self.tcx();
for field_ty in adt_def.all_fields().map(|field| field.ty(tcx, substs)) {
if field_ty.visit_with(self) {
let ty = self.tcx().normalize_erasing_regions(ty::ParamEnv::empty(), field_ty);
debug!("structural-match ADT: field_ty={:?}, ty={:?}", field_ty, ty);

if ty.visit_with(self) {
// found an ADT without structural-match; halt visiting!
assert!(self.found.is_some());
return true;
Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/match/issue-72896.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// run-pass
trait EnumSetType {
type Repr;
}

enum Enum8 { }
impl EnumSetType for Enum8 {
type Repr = u8;
}

#[derive(PartialEq, Eq)]
struct EnumSet<T: EnumSetType> {
__enumset_underlying: T::Repr,
}

const CONST_SET: EnumSet<Enum8> = EnumSet { __enumset_underlying: 3 };

fn main() {
match CONST_SET {
CONST_SET => { /* ok */ }
_ => panic!("match fell through?"),
}
}

0 comments on commit 8addb2e

Please sign in to comment.