about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-06-10 11:03:42 +0200
committerGitHub <noreply@github.com>2020-06-10 11:03:42 +0200
commit8addb2e684dfbe0cd2e16a769485a093f9b2de32 (patch)
tree00dbc98394618b70ec998050191fd616f75da35f
parentfda594e6ae5c430475120944b8a0e92fe8f206a5 (diff)
parent4725af38bc51760ad36180ebd7d128481b3d8ccc (diff)
downloadrust-8addb2e684dfbe0cd2e16a769485a093f9b2de32.tar.gz
rust-8addb2e684dfbe0cd2e16a769485a093f9b2de32.zip
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 :thinking:

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
-rw-r--r--src/librustc_trait_selection/traits/structural_match.rs5
-rw-r--r--src/test/ui/match/issue-72896.rs23
2 files changed, 27 insertions, 1 deletions
diff --git a/src/librustc_trait_selection/traits/structural_match.rs b/src/librustc_trait_selection/traits/structural_match.rs
index b877049fcf6..87ff667b6a0 100644
--- a/src/librustc_trait_selection/traits/structural_match.rs
+++ b/src/librustc_trait_selection/traits/structural_match.rs
@@ -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;
diff --git a/src/test/ui/match/issue-72896.rs b/src/test/ui/match/issue-72896.rs
new file mode 100644
index 00000000000..3a8b8203731
--- /dev/null
+++ b/src/test/ui/match/issue-72896.rs
@@ -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?"),
+    }
+}