Skip to content

Commit 5d8c178

Browse files
Make the coroutine def id of an async closure the child of the closure def id
1 parent 6b4f1c5 commit 5d8c178

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

compiler/rustc_resolve/src/def_collector.rs

+12-6
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
}
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+
}
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)