Skip to content

Commit 876f129

Browse files
committed
Create def_id for async fns during lowering
1 parent 911cbf8 commit 876f129

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1837,9 +1837,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18371837

18381838
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
18391839

1840-
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
18411840
let fn_def_id = self.local_def_id(fn_node_id);
18421841

1842+
let opaque_ty_def_id =
1843+
self.create_def(fn_def_id, opaque_ty_node_id, DefPathData::ImplTrait);
1844+
18431845
// When we create the opaque type for this async fn, it is going to have
18441846
// to capture all the lifetimes involved in the signature (including in the
18451847
// return type). This is done by introducing lifetime parameters for:

compiler/rustc_resolve/src/def_collector.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,17 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
131131

132132
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
133133
if let FnKind::Fn(_, _, sig, _, generics, body) = fn_kind {
134-
if let Async::Yes { closure_id, return_impl_trait_id, .. } = sig.header.asyncness {
134+
if let Async::Yes { closure_id, .. } = sig.header.asyncness {
135135
self.visit_generics(generics);
136136

137-
let return_impl_trait_id =
138-
self.create_def(return_impl_trait_id, DefPathData::ImplTrait, span);
139-
140137
// For async functions, we need to create their inner defs inside of a
141138
// closure to match their desugared representation. Besides that,
142139
// we must mirror everything that `visit::walk_fn` below does.
143140
self.visit_fn_header(&sig.header);
144141
for param in &sig.decl.inputs {
145142
self.visit_param(param);
146143
}
147-
self.with_parent(return_impl_trait_id, |this| {
148-
this.visit_fn_ret_ty(&sig.decl.output)
149-
});
144+
self.visit_fn_ret_ty(&sig.decl.output);
150145
// If this async fn has no body (i.e. it's an async fn signature in a trait)
151146
// then the closure_def will never be used, and we should avoid generating a
152147
// def-id for it.

0 commit comments

Comments
 (0)