Skip to content

Commit 98254c5

Browse files
authored
Rollup merge of #109433 - chenyukang:yukang/fix-109188-ice, r=lcnr
Return equal for two identical projections Fixes #109188
2 parents 936377a + 7bffe94 commit 98254c5

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

compiler/rustc_hir_typeck/src/upvar.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
712712
}
713713
}
714714

715-
unreachable!(
716-
"we captured two identical projections: capture1 = {:?}, capture2 = {:?}",
717-
capture1, capture2
715+
self.tcx.sess.delay_span_bug(
716+
closure_span,
717+
&format!(
718+
"two identical projections: ({:?}, {:?})",
719+
capture1.place.projections, capture2.place.projections
720+
),
718721
);
722+
std::cmp::Ordering::Equal
719723
});
720724
}
721725

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)