with_lifetime_binder is now lower_lifetime_binder and doesn't need a closure
This commit is contained in:
parent
11e00f502a
commit
6289d0eb53
@ -864,22 +864,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
(body_id, generator_option)
|
(body_id, generator_option)
|
||||||
});
|
});
|
||||||
|
|
||||||
self.with_lifetime_binder(closure_id, generic_params, |this, bound_generic_params| {
|
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
|
||||||
// Lower outside new scope to preserve `is_in_loop_condition`.
|
// Lower outside new scope to preserve `is_in_loop_condition`.
|
||||||
let fn_decl = this.lower_fn_decl(decl, None, FnDeclKind::Closure, None);
|
let fn_decl = self.lower_fn_decl(decl, None, FnDeclKind::Closure, None);
|
||||||
|
|
||||||
let c = self.arena.alloc(hir::Closure {
|
let c = self.arena.alloc(hir::Closure {
|
||||||
binder: binder_clause,
|
binder: binder_clause,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
bound_generic_params,
|
bound_generic_params,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
body: body_id,
|
body: body_id,
|
||||||
fn_decl_span: this.lower_span(fn_decl_span),
|
fn_decl_span: self.lower_span(fn_decl_span),
|
||||||
movability: generator_option,
|
movability: generator_option,
|
||||||
});
|
});
|
||||||
|
|
||||||
hir::ExprKind::Closure(c)
|
hir::ExprKind::Closure(c)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generator_movability_for_fn(
|
fn generator_movability_for_fn(
|
||||||
@ -991,23 +990,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
body_id
|
body_id
|
||||||
});
|
});
|
||||||
|
|
||||||
self.with_lifetime_binder(closure_id, generic_params, |this, bound_generic_params| {
|
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
|
||||||
// We need to lower the declaration outside the new scope, because we
|
|
||||||
// have to conserve the state of being inside a loop condition for the
|
|
||||||
// closure argument types.
|
|
||||||
let fn_decl = this.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);
|
|
||||||
|
|
||||||
let c = self.arena.alloc(hir::Closure {
|
// We need to lower the declaration outside the new scope, because we
|
||||||
binder: binder_clause,
|
// have to conserve the state of being inside a loop condition for the
|
||||||
capture_clause,
|
// closure argument types.
|
||||||
bound_generic_params,
|
let fn_decl = self.lower_fn_decl(&outer_decl, None, FnDeclKind::Closure, None);
|
||||||
fn_decl,
|
|
||||||
body,
|
let c = self.arena.alloc(hir::Closure {
|
||||||
fn_decl_span: this.lower_span(fn_decl_span),
|
binder: binder_clause,
|
||||||
movability: None,
|
capture_clause,
|
||||||
});
|
bound_generic_params,
|
||||||
hir::ExprKind::Closure(c)
|
fn_decl,
|
||||||
})
|
body,
|
||||||
|
fn_decl_span: self.lower_span(fn_decl_span),
|
||||||
|
movability: None,
|
||||||
|
});
|
||||||
|
hir::ExprKind::Closure(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructure the LHS of complex assignments.
|
/// Destructure the LHS of complex assignments.
|
||||||
|
@ -787,15 +787,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a binder to be ignored for lifetime capture.
|
/// Lowers a lifetime binder that defines `generic_params`, returning the corresponding HIR
|
||||||
#[tracing::instrument(level = "debug", skip(self, f))]
|
/// nodes. The returned list includes any "extra" lifetime parameters that were added by the
|
||||||
|
/// name resolver owing to lifetime elision; this also populates the resolver's node-id->def-id
|
||||||
|
/// map, so that later calls to `opt_node_id_to_def_id` that refer to these extra lifetime
|
||||||
|
/// parameters will be successful.
|
||||||
|
#[tracing::instrument(level = "debug", skip(self))]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_lifetime_binder<T>(
|
fn lower_lifetime_binder(
|
||||||
&mut self,
|
&mut self,
|
||||||
binder: NodeId,
|
binder: NodeId,
|
||||||
generic_params: &[GenericParam],
|
generic_params: &[GenericParam],
|
||||||
f: impl FnOnce(&mut Self, &'hir [hir::GenericParam<'hir>]) -> T,
|
) -> &'hir [hir::GenericParam<'hir>] {
|
||||||
) -> T {
|
|
||||||
let mut generic_params: Vec<_> = self.lower_generic_params_mut(generic_params).collect();
|
let mut generic_params: Vec<_> = self.lower_generic_params_mut(generic_params).collect();
|
||||||
let extra_lifetimes = self.resolver.take_extra_lifetime_params(binder);
|
let extra_lifetimes = self.resolver.take_extra_lifetime_params(binder);
|
||||||
debug!(?extra_lifetimes);
|
debug!(?extra_lifetimes);
|
||||||
@ -805,7 +808,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
let generic_params = self.arena.alloc_from_iter(generic_params);
|
let generic_params = self.arena.alloc_from_iter(generic_params);
|
||||||
debug!(?generic_params);
|
debug!(?generic_params);
|
||||||
|
|
||||||
f(self, generic_params)
|
generic_params
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
|
fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
|
||||||
@ -1226,15 +1229,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
|
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
|
||||||
}
|
}
|
||||||
TyKind::BareFn(ref f) => {
|
TyKind::BareFn(ref f) => {
|
||||||
self.with_lifetime_binder(t.id, &f.generic_params, |this, generic_params| {
|
let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
|
||||||
hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
|
hir::TyKind::BareFn(self.arena.alloc(hir::BareFnTy {
|
||||||
generic_params,
|
generic_params,
|
||||||
unsafety: this.lower_unsafety(f.unsafety),
|
unsafety: self.lower_unsafety(f.unsafety),
|
||||||
abi: this.lower_extern(f.ext),
|
abi: self.lower_extern(f.ext),
|
||||||
decl: this.lower_fn_decl(&f.decl, None, FnDeclKind::Pointer, None),
|
decl: self.lower_fn_decl(&f.decl, None, FnDeclKind::Pointer, None),
|
||||||
param_names: this.lower_fn_params_to_names(&f.decl),
|
param_names: self.lower_fn_params_to_names(&f.decl),
|
||||||
}))
|
}))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
TyKind::Never => hir::TyKind::Never,
|
TyKind::Never => hir::TyKind::Never,
|
||||||
TyKind::Tup(ref tys) => hir::TyKind::Tup(
|
TyKind::Tup(ref tys) => hir::TyKind::Tup(
|
||||||
@ -2069,14 +2071,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
p: &PolyTraitRef,
|
p: &PolyTraitRef,
|
||||||
itctx: ImplTraitContext,
|
itctx: ImplTraitContext,
|
||||||
) -> hir::PolyTraitRef<'hir> {
|
) -> hir::PolyTraitRef<'hir> {
|
||||||
self.with_lifetime_binder(
|
let bound_generic_params =
|
||||||
p.trait_ref.ref_id,
|
self.lower_lifetime_binder(p.trait_ref.ref_id, &p.bound_generic_params);
|
||||||
&p.bound_generic_params,
|
let trait_ref = self.lower_trait_ref(&p.trait_ref, itctx);
|
||||||
|this, bound_generic_params| {
|
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
|
||||||
let trait_ref = this.lower_trait_ref(&p.trait_ref, itctx);
|
|
||||||
hir::PolyTraitRef { bound_generic_params, trait_ref, span: this.lower_span(p.span) }
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
|
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user