Move lifetimes_in_bounds call to outside with_hir_id_owner block in lower_async_fn_ret_ty

This commit is contained in:
Santiago Pastorino 2022-08-03 23:24:13 -03:00
parent 4b9b5838ac
commit 12fa3393a5
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF

View file

@ -1809,21 +1809,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
debug!(?captures); debug!(?captures);
self.with_hir_id_owner(opaque_ty_node_id, |this| { // We only want to capture the lifetimes that appear in the bounds. So visit the bounds to
let lifetimes_in_bounds = // find out exactly which ones those are.
lifetime_collector::lifetimes_in_ret_ty(&this.resolver, output); // in fn return position, like the `fn test<'a>() -> impl Debug + 'a` example,
debug!(?lifetimes_in_bounds); // we only keep the lifetimes that appear in the `impl Debug` itself:
let lifetimes_to_remap = lifetime_collector::lifetimes_in_ret_ty(&self.resolver, output);
debug!(?lifetimes_to_remap);
self.with_hir_id_owner(opaque_ty_node_id, |this| {
// If this opaque type is only capturing a subset of the lifetimes (those that appear
// in bounds), then create the new lifetime parameters required and create a mapping
// from the old `'a` (on the function) to the new `'a` (on the opaque type).
captures.extend( captures.extend(
this.create_lifetime_defs( this.create_lifetime_defs(
opaque_ty_def_id, opaque_ty_def_id,
&lifetimes_in_bounds, &lifetimes_to_remap,
&mut new_remapping, &mut new_remapping,
) )
.into_iter() .into_iter()
.map(|(new_node_id, lifetime)| (new_node_id, lifetime, None)), .map(|(new_node_id, lifetime)| (new_node_id, lifetime, None)),
); );
debug!(?captures);
debug!(?new_remapping);
// Install the remapping from old to new (if any):
this.with_remapping(new_remapping, |this| { this.with_remapping(new_remapping, |this| {
// We have to be careful to get elision right here. The // We have to be careful to get elision right here. The
// idea is that we create a lifetime parameter for each // idea is that we create a lifetime parameter for each