Skip to content

Commit 8126ccb

Browse files
committed
Return equal for two identical projections
1 parent c90eb48 commit 8126ccb

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

compiler/rustc_hir_typeck/src/upvar.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
712712
}
713713
}
714714

715-
unreachable!(
716-
"we captured two identical projections: capture1 = {:?}, capture2 = {:?}",
717-
capture1, capture2
718-
);
715+
// return Equal for two identical projections
716+
std::cmp::Ordering::Equal
719717
});
720718
}
721719

tests/ui/closures/issue-109188.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
enum Either {
2+
One(X),
3+
Two(X),
4+
}
5+
6+
struct X(Y);
7+
8+
struct Y;
9+
10+
fn consume_fnmut(f: &dyn FnMut()) {
11+
f();
12+
}
13+
14+
fn move_into_fnmut() {
15+
let x = move_into_fnmut();
16+
consume_fnmut(&|| {
17+
let Either::One(_t) = x; //~ ERROR mismatched types
18+
let Either::Two(_t) = x; //~ ERROR mismatched types
19+
});
20+
}
21+
22+
fn main() { }

tests/ui/closures/issue-109188.stderr

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-109188.rs:17:13
3+
|
4+
LL | let Either::One(_t) = x;
5+
| ^^^^^^^^^^^^^^^ - this expression has type `()`
6+
| |
7+
| expected `()`, found `Either`
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/issue-109188.rs:18:13
11+
|
12+
LL | let Either::Two(_t) = x;
13+
| ^^^^^^^^^^^^^^^ - this expression has type `()`
14+
| |
15+
| expected `()`, found `Either`
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)