Skip to content

Commit 5a1cd7d

Browse files
Don't do coroutine-closure-specific upvar analysis if tainted by errors
1 parent df7daa8 commit 5a1cd7d

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

compiler/rustc_hir_typeck/src/upvar.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361361
// For coroutine-closures, we additionally must compute the
362362
// `coroutine_captures_by_ref_ty` type, which is used to generate the by-ref
363363
// version of the coroutine-closure's output coroutine.
364-
if let UpvarArgs::CoroutineClosure(args) = args {
364+
if let UpvarArgs::CoroutineClosure(args) = args
365+
// Don't do this if we are tainted by errors, because fallback causes us
366+
// to fail to infer upvars for the outer coroutine-closure.
367+
&& self.tainted_by_errors().is_none()
368+
{
365369
let closure_env_region: ty::Region<'_> = ty::Region::new_bound(
366370
self.tcx,
367371
ty::INNERMOST,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ edition: 2021
2+
3+
#![feature(async_closure)]
4+
5+
struct DropMe;
6+
7+
trait Impossible {}
8+
fn trait_error<T: Impossible>() {}
9+
10+
pub fn main() {
11+
let b = DropMe;
12+
let async_closure = async move || {
13+
// Type error here taints the environment. This causes us to fallback all
14+
// variables to `Error`. This means that when we compute the upvars for the
15+
// *outer* coroutine-closure, we don't actually see any upvars since `MemCategorization`
16+
// and `ExprUseVisitor`` will bail early when it sees error. This means
17+
// that our underlying assumption that the parent and child captures are
18+
// compatible ends up being broken, previously leading to an ICE.
19+
trait_error::<()>();
20+
//~^ ERROR the trait bound `(): Impossible` is not satisfied
21+
let _b = b;
22+
};
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the trait bound `(): Impossible` is not satisfied
2+
--> $DIR/dont-ice-when-body-tainted-by-errors.rs:19:23
3+
|
4+
LL | trait_error::<()>();
5+
| ^^ the trait `Impossible` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/dont-ice-when-body-tainted-by-errors.rs:7:1
9+
|
10+
LL | trait Impossible {}
11+
| ^^^^^^^^^^^^^^^^
12+
note: required by a bound in `trait_error`
13+
--> $DIR/dont-ice-when-body-tainted-by-errors.rs:8:19
14+
|
15+
LL | fn trait_error<T: Impossible>() {}
16+
| ^^^^^^^^^^ required by this bound in `trait_error`
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)