Skip to content

Commit 169236e

Browse files
a function is just another AnonymousCreateParameter rib
1 parent 57a9689 commit 169236e

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

compiler/rustc_resolve/src/late.rs

+28-30
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
904904
sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
905905
&sig.decl.output,
906906
);
907+
908+
if let Some((async_node_id, span)) = sig.header.asyncness.opt_return_id() {
909+
this.record_lifetime_params_for_impl_trait(async_node_id, span);
910+
}
907911
},
908912
);
909-
self.record_lifetime_params_for_async(fn_id, sig.header.asyncness.opt_return_id());
910913
return;
911914
}
912915
FnKind::Fn(..) => {
@@ -942,12 +945,14 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
942945
.iter()
943946
.map(|Param { pat, ty, .. }| (Some(&**pat), &**ty)),
944947
&declaration.output,
945-
)
948+
);
949+
950+
if let Some((async_node_id, span)) = async_node_id {
951+
this.record_lifetime_params_for_impl_trait(async_node_id, span);
952+
}
946953
},
947954
);
948955

949-
this.record_lifetime_params_for_async(fn_id, async_node_id);
950-
951956
if let Some(body) = body {
952957
// Ignore errors in function bodies if this is rustdoc
953958
// Be sure not to set this until the function signature has been resolved.
@@ -4326,39 +4331,32 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
43264331
)
43274332
}
43284333

4329-
/// Construct the list of in-scope lifetime parameters for async lowering.
4334+
/// Construct the list of in-scope lifetime parameters for impl trait lowering.
43304335
/// We include all lifetime parameters, either named or "Fresh".
43314336
/// The order of those parameters does not matter, as long as it is
43324337
/// deterministic.
4333-
fn record_lifetime_params_for_async(
4334-
&mut self,
4335-
fn_id: NodeId,
4336-
async_node_id: Option<(NodeId, Span)>,
4337-
) {
4338-
if let Some((async_node_id, span)) = async_node_id {
4339-
let mut extra_lifetime_params =
4340-
self.r.extra_lifetime_params_map.get(&fn_id).cloned().unwrap_or_default();
4341-
for rib in self.lifetime_ribs.iter().rev() {
4342-
extra_lifetime_params.extend(
4343-
rib.bindings.iter().map(|(&ident, &(node_id, res))| (ident, node_id, res)),
4344-
);
4345-
match rib.kind {
4346-
LifetimeRibKind::Item => break,
4347-
LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
4348-
if let Some(earlier_fresh) = self.r.extra_lifetime_params_map.get(&binder) {
4349-
extra_lifetime_params.extend(earlier_fresh);
4350-
}
4351-
}
4352-
LifetimeRibKind::Generics { .. } => {}
4353-
_ => {
4354-
// We are in a function definition. We should only find `Generics`
4355-
// and `AnonymousCreateParameter` inside the innermost `Item`.
4356-
span_bug!(span, "unexpected rib kind: {:?}", rib.kind)
4338+
fn record_lifetime_params_for_impl_trait(&mut self, impl_trait_node_id: NodeId, span: Span) {
4339+
let mut extra_lifetime_params = vec![];
4340+
4341+
for rib in self.lifetime_ribs.iter().rev() {
4342+
extra_lifetime_params
4343+
.extend(rib.bindings.iter().map(|(&ident, &(node_id, res))| (ident, node_id, res)));
4344+
match rib.kind {
4345+
LifetimeRibKind::Item => break,
4346+
LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
4347+
if let Some(earlier_fresh) = self.r.extra_lifetime_params_map.get(&binder) {
4348+
extra_lifetime_params.extend(earlier_fresh);
43574349
}
43584350
}
4351+
LifetimeRibKind::Generics { .. } => {}
4352+
_ => {
4353+
// We are in a function definition. We should only find `Generics`
4354+
// and `AnonymousCreateParameter` inside the innermost `Item`.
4355+
span_bug!(span, "unexpected rib kind: {:?}", rib.kind)
4356+
}
43594357
}
4360-
self.r.extra_lifetime_params_map.insert(async_node_id, extra_lifetime_params);
43614358
}
4359+
self.r.extra_lifetime_params_map.insert(impl_trait_node_id, extra_lifetime_params);
43624360
}
43634361

43644362
fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> Option<Res> {

0 commit comments

Comments
 (0)