Skip to content

Commit

Permalink
Make the coroutine def id of an async closure the child of the closur…
Browse files Browse the repository at this point in the history
…e def id
  • Loading branch information
compiler-errors committed Jan 27, 2024
1 parent c073f56 commit ee792d0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
18 changes: 12 additions & 6 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,18 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
// we must create two defs.
let closure_def = self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span);
match closure.coroutine_kind {
Some(coroutine_kind) => self.create_def(
coroutine_kind.closure_id(),
kw::Empty,
DefKind::Closure,
expr.span,
),
Some(coroutine_kind) => {
self.with_parent(closure_def, |this| {
let coroutine_def = this.create_def(
coroutine_kind.closure_id(),
kw::Empty,
DefKind::Closure,
expr.span,
);
this.with_parent(coroutine_def, |this| visit::walk_expr(this, expr));
});
return;
}
None => closure_def,
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/async-await/async-closures/def-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// compile-flags: -Zverbose-internals
// edition:2021

#![feature(async_closure)]

fn main() {
let x = async || {};
let () = x();
//~^ ERROR mismatched types
}
16 changes: 16 additions & 0 deletions tests/ui/async-await/async-closures/def-path.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0308]: mismatched types
--> $DIR/def-path.rs:8:9
|
LL | let x = async || {};
| -- the expected `async` closure body
LL | let () = x();
| ^^ --- this expression has type `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}`
| |
| expected `async` closure body, found `()`
|
= note: expected `async` closure body `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}`
found unit type `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

0 comments on commit ee792d0

Please sign in to comment.