mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Only generate closure def id for async fns with body
This commit is contained in:
parent
f5193a9fcc
commit
730ead8047
@ -1,6 +1,5 @@
|
||||
use crate::{ImplTraitContext, Resolver};
|
||||
use rustc_ast::visit::{self, FnKind};
|
||||
use rustc_ast::walk_list;
|
||||
use rustc_ast::*;
|
||||
use rustc_expand::expand::AstFragment;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
@ -148,8 +147,13 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
|
||||
self.with_parent(return_impl_trait_id, |this| {
|
||||
this.visit_fn_ret_ty(&sig.decl.output)
|
||||
});
|
||||
// If this async fn has no body (i.e. it's an async fn signature in a trait)
|
||||
// then the closure_def will never be used, and we should avoid generating a
|
||||
// def-id for it.
|
||||
if let Some(body) = body {
|
||||
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
|
||||
self.with_parent(closure_def, |this| walk_list!(this, visit_block, body));
|
||||
self.with_parent(closure_def, |this| this.visit_block(body));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
10
src/test/ui/async-await/in-trait/issue-102219.rs
Normal file
10
src/test/ui/async-await/in-trait/issue-102219.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// compile-flags:--crate-type=lib
|
||||
// edition:2021
|
||||
// check-pass
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait T {
|
||||
async fn foo();
|
||||
}
|
Loading…
Reference in New Issue
Block a user