Skip to content

Commit 730ead8

Browse files
Only generate closure def id for async fns with body
1 parent f5193a9 commit 730ead8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{ImplTraitContext, Resolver};
22
use rustc_ast::visit::{self, FnKind};
3-
use rustc_ast::walk_list;
43
use rustc_ast::*;
54
use rustc_expand::expand::AstFragment;
65
use rustc_hir::def_id::LocalDefId;
@@ -148,8 +147,13 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
148147
self.with_parent(return_impl_trait_id, |this| {
149148
this.visit_fn_ret_ty(&sig.decl.output)
150149
});
151-
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
152-
self.with_parent(closure_def, |this| walk_list!(this, visit_block, body));
150+
// If this async fn has no body (i.e. it's an async fn signature in a trait)
151+
// then the closure_def will never be used, and we should avoid generating a
152+
// def-id for it.
153+
if let Some(body) = body {
154+
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
155+
self.with_parent(closure_def, |this| this.visit_block(body));
156+
}
153157
return;
154158
}
155159
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags:--crate-type=lib
2+
// edition:2021
3+
// check-pass
4+
5+
#![feature(async_fn_in_trait)]
6+
#![allow(incomplete_features)]
7+
8+
trait T {
9+
async fn foo();
10+
}

0 commit comments

Comments
 (0)