about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2023-03-21 15:27:08 +0800
committeryukang <moorekang@gmail.com>2023-03-21 15:28:11 +0800
commit8126ccb77d5d7edd242a9f9566364b70f0a7b0a6 (patch)
treea7dd192296a11d67fffeeb54100394200e5bf277
parentc90eb4825a9faca0d6317292a452859f00d5b786 (diff)
downloadrust-8126ccb77d5d7edd242a9f9566364b70f0a7b0a6.tar.gz
rust-8126ccb77d5d7edd242a9f9566364b70f0a7b0a6.zip
Return equal for two identical projections
-rw-r--r--compiler/rustc_hir_typeck/src/upvar.rs6
-rw-r--r--tests/ui/closures/issue-109188.rs22
-rw-r--r--tests/ui/closures/issue-109188.stderr19
3 files changed, 43 insertions, 4 deletions
diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs
index 4a432328c4d..90947912a19 100644
--- a/compiler/rustc_hir_typeck/src/upvar.rs
+++ b/compiler/rustc_hir_typeck/src/upvar.rs
@@ -712,10 +712,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     }
                 }
 
-                unreachable!(
-                    "we captured two identical projections: capture1 = {:?}, capture2 = {:?}",
-                    capture1, capture2
-                );
+                // return Equal for two identical projections
+                std::cmp::Ordering::Equal
             });
         }
 
diff --git a/tests/ui/closures/issue-109188.rs b/tests/ui/closures/issue-109188.rs
new file mode 100644
index 00000000000..cae1ced9958
--- /dev/null
+++ b/tests/ui/closures/issue-109188.rs
@@ -0,0 +1,22 @@
+enum Either {
+    One(X),
+    Two(X),
+}
+
+struct X(Y);
+
+struct Y;
+
+fn consume_fnmut(f: &dyn FnMut()) {
+    f();
+}
+
+fn move_into_fnmut() {
+    let x = move_into_fnmut();
+    consume_fnmut(&|| {
+        let Either::One(_t) = x; //~ ERROR mismatched types
+        let Either::Two(_t) = x; //~ ERROR mismatched types
+    });
+}
+
+fn main() { }
diff --git a/tests/ui/closures/issue-109188.stderr b/tests/ui/closures/issue-109188.stderr
new file mode 100644
index 00000000000..d52b516294f
--- /dev/null
+++ b/tests/ui/closures/issue-109188.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-109188.rs:17:13
+   |
+LL |         let Either::One(_t) = x;
+   |             ^^^^^^^^^^^^^^^   - this expression has type `()`
+   |             |
+   |             expected `()`, found `Either`
+
+error[E0308]: mismatched types
+  --> $DIR/issue-109188.rs:18:13
+   |
+LL |         let Either::Two(_t) = x;
+   |             ^^^^^^^^^^^^^^^   - this expression has type `()`
+   |             |
+   |             expected `()`, found `Either`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.