Skip to content

Commit 235d088

Browse files
authored
Rollup merge of #110957 - WaffleLapkin:reach_generator_conflict_error, r=cjgillot
Fix an ICE in conflict error diagnostics Fixes #110929 r? ``@cjgillot``
2 parents afbb188 + 754a62c commit 235d088

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13591359
}
13601360

13611361
// Get closure's arguments
1362-
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else { unreachable!() };
1362+
let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else { /* hir::Closure can be a generator too */ return };
13631363
let sig = substs.as_closure().sig();
13641364
let tupled_params =
13651365
tcx.erase_late_bound_regions(sig.inputs().iter().next().unwrap().map_bound(|&b| b));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2021
2+
// compile-flags: -Zdrop-tracking-mir=yes
3+
#![feature(generators)]
4+
5+
fn main() {
6+
let x = &mut ();
7+
|| {
8+
let _c = || yield *&mut *x;
9+
|| _ = &mut *x;
10+
//~^ cannot borrow `*x` as mutable more than once at a time
11+
};
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0499]: cannot borrow `*x` as mutable more than once at a time
2+
--> $DIR/issue-110929-generator-conflict-error-ice.rs:9:9
3+
|
4+
LL | let _c = || yield *&mut *x;
5+
| -- -- first borrow occurs due to use of `*x` in generator
6+
| |
7+
| first mutable borrow occurs here
8+
LL | || _ = &mut *x;
9+
| ^^ -- second borrow occurs due to use of `*x` in closure
10+
| |
11+
| second mutable borrow occurs here
12+
LL |
13+
LL | };
14+
| - first borrow might be used here, when `_c` is dropped and runs the destructor for generator
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0499`.

0 commit comments

Comments
 (0)