Skip to content

Commit 88542a3

Browse files
authored
Rollup merge of rust-lang#104615 - spastorino:create-async-def-id-in-lowering, r=compiler-errors
Create def_id for async fns during lowering r? `@compiler-errors`
2 parents 20d6a44 + 520fafe commit 88542a3

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
@@ -1817,9 +1817,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18171817

18181818
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
18191819

1820-
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
18211820
let fn_def_id = self.local_def_id(fn_node_id);
18221821

1822+
let opaque_ty_def_id =
1823+
self.create_def(fn_def_id, opaque_ty_node_id, DefPathData::ImplTrait);
1824+
18231825
// When we create the opaque type for this async fn, it is going to have
18241826
// to capture all the lifetimes involved in the signature (including in the
18251827
// 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)