Rollup merge of #129858 - compiler-errors:async-def, r=cjgillot

Replace walk with visit so we dont skip outermost expr kind in def collector

This affects async closures with macros as their body expr. Fixes #129855.

r? ``@cjgillot`` or anyone else
This commit is contained in:
Matthias Krüger 2024-09-02 04:19:31 +02:00 committed by GitHub
commit 38b6a66def
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -223,7 +223,7 @@ fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
// we must create two defs.
let coroutine_def =
self.create_def(coroutine_kind.closure_id(), kw::Empty, DefKind::Closure, span);
self.with_parent(coroutine_def, |this| visit::walk_expr(this, body));
self.with_parent(coroutine_def, |this| this.visit_expr(body));
}
_ => visit::walk_fn(self, fn_kind),
}

View File

@ -0,0 +1,12 @@
//@ edition: 2021
//@ check-pass
#![feature(async_closure)]
// Make sure we don't ICE if an async closure has a macro body.
// This happened because we were calling walk instead of visit
// in the def collector, oops!
fn main() {
let _ = async || println!();
}