a function is just another AnonymousCreateParameter rib

This commit is contained in:
Michael Goulet 2023-08-04 22:51:37 +00:00
parent 57a96893f6
commit 169236ec8a

View File

@ -904,9 +904,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)), sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
&sig.decl.output, &sig.decl.output,
); );
if let Some((async_node_id, span)) = sig.header.asyncness.opt_return_id() {
this.record_lifetime_params_for_impl_trait(async_node_id, span);
}
}, },
); );
self.record_lifetime_params_for_async(fn_id, sig.header.asyncness.opt_return_id());
return; return;
} }
FnKind::Fn(..) => { FnKind::Fn(..) => {
@ -942,12 +945,14 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
.iter() .iter()
.map(|Param { pat, ty, .. }| (Some(&**pat), &**ty)), .map(|Param { pat, ty, .. }| (Some(&**pat), &**ty)),
&declaration.output, &declaration.output,
) );
if let Some((async_node_id, span)) = async_node_id {
this.record_lifetime_params_for_impl_trait(async_node_id, span);
}
}, },
); );
this.record_lifetime_params_for_async(fn_id, async_node_id);
if let Some(body) = body { if let Some(body) = body {
// Ignore errors in function bodies if this is rustdoc // Ignore errors in function bodies if this is rustdoc
// Be sure not to set this until the function signature has been resolved. // 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> {
) )
} }
/// Construct the list of in-scope lifetime parameters for async lowering. /// Construct the list of in-scope lifetime parameters for impl trait lowering.
/// We include all lifetime parameters, either named or "Fresh". /// We include all lifetime parameters, either named or "Fresh".
/// The order of those parameters does not matter, as long as it is /// The order of those parameters does not matter, as long as it is
/// deterministic. /// deterministic.
fn record_lifetime_params_for_async( fn record_lifetime_params_for_impl_trait(&mut self, impl_trait_node_id: NodeId, span: Span) {
&mut self, let mut extra_lifetime_params = vec![];
fn_id: NodeId,
async_node_id: Option<(NodeId, Span)>, for rib in self.lifetime_ribs.iter().rev() {
) { extra_lifetime_params
if let Some((async_node_id, span)) = async_node_id { .extend(rib.bindings.iter().map(|(&ident, &(node_id, res))| (ident, node_id, res)));
let mut extra_lifetime_params = match rib.kind {
self.r.extra_lifetime_params_map.get(&fn_id).cloned().unwrap_or_default(); LifetimeRibKind::Item => break,
for rib in self.lifetime_ribs.iter().rev() { LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
extra_lifetime_params.extend( if let Some(earlier_fresh) = self.r.extra_lifetime_params_map.get(&binder) {
rib.bindings.iter().map(|(&ident, &(node_id, res))| (ident, node_id, res)), extra_lifetime_params.extend(earlier_fresh);
);
match rib.kind {
LifetimeRibKind::Item => break,
LifetimeRibKind::AnonymousCreateParameter { binder, .. } => {
if let Some(earlier_fresh) = self.r.extra_lifetime_params_map.get(&binder) {
extra_lifetime_params.extend(earlier_fresh);
}
}
LifetimeRibKind::Generics { .. } => {}
_ => {
// We are in a function definition. We should only find `Generics`
// and `AnonymousCreateParameter` inside the innermost `Item`.
span_bug!(span, "unexpected rib kind: {:?}", rib.kind)
} }
} }
LifetimeRibKind::Generics { .. } => {}
_ => {
// We are in a function definition. We should only find `Generics`
// and `AnonymousCreateParameter` inside the innermost `Item`.
span_bug!(span, "unexpected rib kind: {:?}", rib.kind)
}
} }
self.r.extra_lifetime_params_map.insert(async_node_id, extra_lifetime_params);
} }
self.r.extra_lifetime_params_map.insert(impl_trait_node_id, extra_lifetime_params);
} }
fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> Option<Res> { fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> Option<Res> {