Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 422e271

Browse files
authored
Unrolled build for rust-lang#120402
Rollup merge of rust-lang#120402 - compiler-errors:async-closure-def-tree, r=cjgillot Make the coroutine def id of an async closure the child of the closure def id Adjust def collection to make the (inner) coroutine returned by an async closure be a def id child of the (outer) closure. This makes it easy to map from coroutine -> closure by using `tcx.parent`, since currently it's not trivial to do this.
2 parents c401f09 + 5d8c178 commit 422e271

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,18 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
289289
// we must create two defs.
290290
let closure_def = self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span);
291291
match closure.coroutine_kind {
292-
Some(coroutine_kind) => self.create_def(
293-
coroutine_kind.closure_id(),
294-
kw::Empty,
295-
DefKind::Closure,
296-
expr.span,
297-
),
292+
Some(coroutine_kind) => {
293+
self.with_parent(closure_def, |this| {
294+
let coroutine_def = this.create_def(
295+
coroutine_kind.closure_id(),
296+
kw::Empty,
297+
DefKind::Closure,
298+
expr.span,
299+
);
300+
this.with_parent(coroutine_def, |this| visit::walk_expr(this, expr));
301+
});
302+
return;
303+
}
298304
None => closure_def,
299305
}
300306
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-flags: -Zverbose-internals
2+
// edition:2021
3+
4+
#![feature(async_closure)]
5+
6+
fn main() {
7+
let x = async || {};
8+
//~^ NOTE the expected `async` closure body
9+
let () = x();
10+
//~^ ERROR mismatched types
11+
//~| NOTE this expression has type `{static main::{closure#0}::{closure#0} upvar_tys=
12+
//~| NOTE expected `async` closure body, found `()`
13+
//~| NOTE expected `async` closure body `{static main::{closure#0}::{closure#0}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/def-path.rs:9:9
3+
|
4+
LL | let x = async || {};
5+
| -- the expected `async` closure body
6+
LL |
7+
LL | let () = x();
8+
| ^^ --- this expression has type `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}`
9+
| |
10+
| expected `async` closure body, found `()`
11+
|
12+
= note: expected `async` closure body `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}`
13+
found unit type `()`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)