diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 5db0f72919d03..ac84188a35fb1 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1359,7 +1359,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } // Get closure's arguments - let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else { unreachable!() }; + let ty::Closure(_, substs) = typeck_results.expr_ty(closure_expr).kind() else { /* hir::Closure can be a generator too */ return }; let sig = substs.as_closure().sig(); let tupled_params = tcx.erase_late_bound_regions(sig.inputs().iter().next().unwrap().map_bound(|&b| b)); diff --git a/tests/ui/generator/issue-110929-generator-conflict-error-ice.rs b/tests/ui/generator/issue-110929-generator-conflict-error-ice.rs new file mode 100644 index 0000000000000..9408acc15f965 --- /dev/null +++ b/tests/ui/generator/issue-110929-generator-conflict-error-ice.rs @@ -0,0 +1,12 @@ +// edition:2021 +// compile-flags: -Zdrop-tracking-mir=yes +#![feature(generators)] + +fn main() { + let x = &mut (); + || { + let _c = || yield *&mut *x; + || _ = &mut *x; + //~^ cannot borrow `*x` as mutable more than once at a time + }; +} diff --git a/tests/ui/generator/issue-110929-generator-conflict-error-ice.stderr b/tests/ui/generator/issue-110929-generator-conflict-error-ice.stderr new file mode 100644 index 0000000000000..4d72ebe79eb49 --- /dev/null +++ b/tests/ui/generator/issue-110929-generator-conflict-error-ice.stderr @@ -0,0 +1,18 @@ +error[E0499]: cannot borrow `*x` as mutable more than once at a time + --> $DIR/issue-110929-generator-conflict-error-ice.rs:9:9 + | +LL | let _c = || yield *&mut *x; + | -- -- first borrow occurs due to use of `*x` in generator + | | + | first mutable borrow occurs here +LL | || _ = &mut *x; + | ^^ -- second borrow occurs due to use of `*x` in closure + | | + | second mutable borrow occurs here +LL | +LL | }; + | - first borrow might be used here, when `_c` is dropped and runs the destructor for generator + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0499`.