Move defs and bounds from Universal to LoweringContext
This commit is contained in:
parent
4a8d2e3856
commit
3d6eae8cd2
3 changed files with 60 additions and 87 deletions
|
@ -83,6 +83,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
||||||
task_context: None,
|
task_context: None,
|
||||||
current_item: None,
|
current_item: None,
|
||||||
captured_lifetimes: None,
|
captured_lifetimes: None,
|
||||||
|
impl_trait_defs: Vec::new(),
|
||||||
|
impl_trait_bounds: Vec::new(),
|
||||||
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
|
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
|
||||||
allow_gen_future: Some([sym::gen_future][..].into()),
|
allow_gen_future: Some([sym::gen_future][..].into()),
|
||||||
allow_into_future: Some([sym::into_future][..].into()),
|
allow_into_future: Some([sym::into_future][..].into()),
|
||||||
|
@ -264,16 +266,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let body_id =
|
let body_id =
|
||||||
this.lower_maybe_async_body(span, &decl, asyncness, body.as_deref());
|
this.lower_maybe_async_body(span, &decl, asyncness, body.as_deref());
|
||||||
|
|
||||||
let (generics, decl) =
|
let (generics, decl) = this.add_implicit_generics(generics, id, |this| {
|
||||||
this.add_implicit_generics(generics, id, |this, idty, idpb| {
|
let ret_id = asyncness.opt_return_id();
|
||||||
let ret_id = asyncness.opt_return_id();
|
this.lower_fn_decl(&decl, Some(id), FnDeclKind::Fn, ret_id)
|
||||||
this.lower_fn_decl(
|
});
|
||||||
&decl,
|
|
||||||
Some((id, idty, idpb)),
|
|
||||||
FnDeclKind::Fn,
|
|
||||||
ret_id,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
let sig = hir::FnSig {
|
let sig = hir::FnSig {
|
||||||
decl,
|
decl,
|
||||||
header: this.lower_fn_header(header),
|
header: this.lower_fn_header(header),
|
||||||
|
@ -387,7 +383,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
// lifetime to be added, but rather a reference to a
|
// lifetime to be added, but rather a reference to a
|
||||||
// parent lifetime.
|
// parent lifetime.
|
||||||
let (generics, (trait_ref, lowered_ty)) =
|
let (generics, (trait_ref, lowered_ty)) =
|
||||||
self.add_implicit_generics(ast_generics, id, |this, _, _| {
|
self.add_implicit_generics(ast_generics, id, |this| {
|
||||||
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
|
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
|
||||||
this.lower_trait_ref(
|
this.lower_trait_ref(
|
||||||
trait_ref,
|
trait_ref,
|
||||||
|
@ -652,7 +648,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
ForeignItemKind::Fn(box Fn { ref sig, ref generics, .. }) => {
|
ForeignItemKind::Fn(box Fn { ref sig, ref generics, .. }) => {
|
||||||
let fdec = &sig.decl;
|
let fdec = &sig.decl;
|
||||||
let (generics, (fn_dec, fn_args)) =
|
let (generics, (fn_dec, fn_args)) =
|
||||||
self.add_implicit_generics(generics, i.id, |this, _, _| {
|
self.add_implicit_generics(generics, i.id, |this| {
|
||||||
(
|
(
|
||||||
// Disallow `impl Trait` in foreign items.
|
// Disallow `impl Trait` in foreign items.
|
||||||
this.lower_fn_decl(fdec, None, FnDeclKind::ExternFn, None),
|
this.lower_fn_decl(fdec, None, FnDeclKind::ExternFn, None),
|
||||||
|
@ -1231,8 +1227,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
is_async: Option<NodeId>,
|
is_async: Option<NodeId>,
|
||||||
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
|
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
|
||||||
let header = self.lower_fn_header(sig.header);
|
let header = self.lower_fn_header(sig.header);
|
||||||
let (generics, decl) = self.add_implicit_generics(generics, id, |this, idty, idpb| {
|
let (generics, decl) = self.add_implicit_generics(generics, id, |this| {
|
||||||
this.lower_fn_decl(&sig.decl, Some((id, idty, idpb)), kind, is_async)
|
this.lower_fn_decl(&sig.decl, Some(id), kind, is_async)
|
||||||
});
|
});
|
||||||
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
|
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
|
||||||
}
|
}
|
||||||
|
@ -1292,7 +1288,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
pub(super) fn lower_generics_mut(
|
pub(super) fn lower_generics_mut(
|
||||||
&mut self,
|
&mut self,
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
mut itctx: ImplTraitContext<'_, 'hir>,
|
mut itctx: ImplTraitContext,
|
||||||
) -> GenericsCtor<'hir> {
|
) -> GenericsCtor<'hir> {
|
||||||
// Error if `?Trait` bounds in where clauses don't refer directly to type parameters.
|
// Error if `?Trait` bounds in where clauses don't refer directly to type parameters.
|
||||||
// Note: we used to clone these bounds directly onto the type parameter (and avoid lowering
|
// Note: we used to clone these bounds directly onto the type parameter (and avoid lowering
|
||||||
|
@ -1372,7 +1368,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
pub(super) fn lower_generics(
|
pub(super) fn lower_generics(
|
||||||
&mut self,
|
&mut self,
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
itctx: ImplTraitContext<'_, 'hir>,
|
itctx: ImplTraitContext,
|
||||||
) -> &'hir hir::Generics<'hir> {
|
) -> &'hir hir::Generics<'hir> {
|
||||||
let generics_ctor = self.lower_generics_mut(generics, itctx);
|
let generics_ctor = self.lower_generics_mut(generics, itctx);
|
||||||
generics_ctor.into_generics(self.arena)
|
generics_ctor.into_generics(self.arena)
|
||||||
|
|
|
@ -121,6 +121,9 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||||
local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>,
|
local_id_to_def_id: SortedMap<ItemLocalId, LocalDefId>,
|
||||||
trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
||||||
|
|
||||||
|
impl_trait_defs: Vec<hir::GenericParam<'hir>>,
|
||||||
|
impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
|
||||||
|
|
||||||
/// NodeIds that are lowered inside the current HIR owner.
|
/// NodeIds that are lowered inside the current HIR owner.
|
||||||
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
|
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
|
||||||
|
|
||||||
|
@ -244,13 +247,13 @@ pub trait ResolverAstLowering {
|
||||||
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
|
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
|
||||||
/// and if so, what meaning it has.
|
/// and if so, what meaning it has.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ImplTraitContext<'b, 'a> {
|
enum ImplTraitContext {
|
||||||
/// Treat `impl Trait` as shorthand for a new universal generic parameter.
|
/// Treat `impl Trait` as shorthand for a new universal generic parameter.
|
||||||
/// Example: `fn foo(x: impl Debug)`, where `impl Debug` is conceptually
|
/// Example: `fn foo(x: impl Debug)`, where `impl Debug` is conceptually
|
||||||
/// equivalent to a fresh universal parameter like `fn foo<T: Debug>(x: T)`.
|
/// equivalent to a fresh universal parameter like `fn foo<T: Debug>(x: T)`.
|
||||||
///
|
///
|
||||||
/// Newly generated parameters should be inserted into the given `Vec`.
|
/// Newly generated parameters should be inserted into the given `Vec`.
|
||||||
Universal(&'b mut Vec<hir::GenericParam<'a>>, &'b mut Vec<hir::WherePredicate<'a>>, LocalDefId),
|
Universal(LocalDefId),
|
||||||
|
|
||||||
/// Treat `impl Trait` as shorthand for a new opaque type.
|
/// Treat `impl Trait` as shorthand for a new opaque type.
|
||||||
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
|
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
|
||||||
|
@ -290,11 +293,11 @@ enum ImplTraitPosition {
|
||||||
ImplReturn,
|
ImplReturn,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ImplTraitContext<'_, 'a> {
|
impl ImplTraitContext {
|
||||||
fn reborrow<'this>(&'this mut self) -> ImplTraitContext<'this, 'a> {
|
fn reborrow<'this>(&'this mut self) -> ImplTraitContext {
|
||||||
use self::ImplTraitContext::*;
|
use self::ImplTraitContext::*;
|
||||||
match self {
|
match self {
|
||||||
Universal(params, bounds, parent) => Universal(params, bounds, *parent),
|
Universal(parent) => Universal(*parent),
|
||||||
ReturnPositionOpaqueTy { origin } => ReturnPositionOpaqueTy { origin: *origin },
|
ReturnPositionOpaqueTy { origin } => ReturnPositionOpaqueTy { origin: *origin },
|
||||||
TypeAliasesOpaqueTy => TypeAliasesOpaqueTy,
|
TypeAliasesOpaqueTy => TypeAliasesOpaqueTy,
|
||||||
Disallowed(pos) => Disallowed(*pos),
|
Disallowed(pos) => Disallowed(*pos),
|
||||||
|
@ -701,34 +704,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
&mut self,
|
&mut self,
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
parent_node_id: NodeId,
|
parent_node_id: NodeId,
|
||||||
f: impl FnOnce(
|
f: impl FnOnce(&mut Self) -> T,
|
||||||
&mut Self,
|
|
||||||
&mut Vec<hir::GenericParam<'hir>>,
|
|
||||||
&mut Vec<hir::WherePredicate<'hir>>,
|
|
||||||
) -> T,
|
|
||||||
) -> (&'hir hir::Generics<'hir>, T) {
|
) -> (&'hir hir::Generics<'hir>, T) {
|
||||||
let mut impl_trait_defs = Vec::new();
|
let mut lowered_generics = self
|
||||||
let mut impl_trait_bounds = Vec::new();
|
.lower_generics_mut(generics, ImplTraitContext::Universal(self.current_hir_id_owner));
|
||||||
let mut lowered_generics = self.lower_generics_mut(
|
let res = f(self);
|
||||||
generics,
|
|
||||||
ImplTraitContext::Universal(
|
|
||||||
&mut impl_trait_defs,
|
|
||||||
&mut impl_trait_bounds,
|
|
||||||
self.current_hir_id_owner,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
let res = f(self, &mut impl_trait_defs, &mut impl_trait_bounds);
|
|
||||||
|
|
||||||
let extra_lifetimes = self.resolver.take_extra_lifetime_params(parent_node_id);
|
let extra_lifetimes = self.resolver.take_extra_lifetime_params(parent_node_id);
|
||||||
|
let impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
|
||||||
lowered_generics.params.extend(
|
lowered_generics.params.extend(
|
||||||
extra_lifetimes
|
extra_lifetimes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(ident, node_id, res)| {
|
.filter_map(|(ident, node_id, res)| {
|
||||||
self.lifetime_res_to_generic_param(ident, node_id, res)
|
self.lifetime_res_to_generic_param(ident, node_id, res)
|
||||||
})
|
})
|
||||||
.chain(impl_trait_defs),
|
.chain(impl_trait_defs.into_iter()),
|
||||||
);
|
);
|
||||||
lowered_generics.predicates.extend(impl_trait_bounds);
|
let impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
|
||||||
|
lowered_generics.predicates.extend(impl_trait_bounds.into_iter());
|
||||||
|
|
||||||
let lowered_generics = lowered_generics.into_generics(self.arena);
|
let lowered_generics = lowered_generics.into_generics(self.arena);
|
||||||
(lowered_generics, res)
|
(lowered_generics, res)
|
||||||
|
@ -898,7 +891,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_assoc_ty_constraint(
|
fn lower_assoc_ty_constraint(
|
||||||
&mut self,
|
&mut self,
|
||||||
constraint: &AssocConstraint,
|
constraint: &AssocConstraint,
|
||||||
mut itctx: ImplTraitContext<'_, 'hir>,
|
mut itctx: ImplTraitContext,
|
||||||
) -> hir::TypeBinding<'hir> {
|
) -> hir::TypeBinding<'hir> {
|
||||||
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
|
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
|
||||||
|
|
||||||
|
@ -962,7 +955,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// so desugar to
|
// so desugar to
|
||||||
//
|
//
|
||||||
// fn foo(x: dyn Iterator<Item = impl Debug>)
|
// fn foo(x: dyn Iterator<Item = impl Debug>)
|
||||||
ImplTraitContext::Universal(_, _, parent) if self.is_in_dyn_type => {
|
ImplTraitContext::Universal(parent) if self.is_in_dyn_type => {
|
||||||
parent_def_id = parent;
|
parent_def_id = parent;
|
||||||
(true, itctx)
|
(true, itctx)
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1029,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_generic_arg(
|
fn lower_generic_arg(
|
||||||
&mut self,
|
&mut self,
|
||||||
arg: &ast::GenericArg,
|
arg: &ast::GenericArg,
|
||||||
itctx: ImplTraitContext<'_, 'hir>,
|
itctx: ImplTraitContext,
|
||||||
) -> hir::GenericArg<'hir> {
|
) -> hir::GenericArg<'hir> {
|
||||||
match arg {
|
match arg {
|
||||||
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)),
|
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)),
|
||||||
|
@ -1103,7 +1096,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_, 'hir>) -> &'hir hir::Ty<'hir> {
|
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
|
||||||
self.arena.alloc(self.lower_ty_direct(t, itctx))
|
self.arena.alloc(self.lower_ty_direct(t, itctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1113,7 +1106,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
qself: &Option<QSelf>,
|
qself: &Option<QSelf>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
itctx: ImplTraitContext<'_, 'hir>,
|
itctx: ImplTraitContext,
|
||||||
) -> hir::Ty<'hir> {
|
) -> hir::Ty<'hir> {
|
||||||
let id = self.lower_node_id(t.id);
|
let id = self.lower_node_id(t.id);
|
||||||
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx);
|
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx);
|
||||||
|
@ -1128,7 +1121,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.ty(span, hir::TyKind::Tup(tys))
|
self.ty(span, hir::TyKind::Tup(tys))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'hir>) -> hir::Ty<'hir> {
|
fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext) -> hir::Ty<'hir> {
|
||||||
let kind = match t.kind {
|
let kind = match t.kind {
|
||||||
TyKind::Infer => hir::TyKind::Infer,
|
TyKind::Infer => hir::TyKind::Infer,
|
||||||
TyKind::Err => hir::TyKind::Err,
|
TyKind::Err => hir::TyKind::Err,
|
||||||
|
@ -1235,32 +1228,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
|this| this.lower_param_bounds(bounds, nested_itctx),
|
|this| this.lower_param_bounds(bounds, nested_itctx),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ImplTraitContext::Universal(
|
ImplTraitContext::Universal(parent_def_id) => {
|
||||||
in_band_ty_params,
|
|
||||||
in_band_ty_bounds,
|
|
||||||
parent_def_id,
|
|
||||||
) => {
|
|
||||||
// Add a definition for the in-band `Param`.
|
// Add a definition for the in-band `Param`.
|
||||||
let def_id = self.resolver.local_def_id(def_node_id);
|
let def_id = self.resolver.local_def_id(def_node_id);
|
||||||
|
|
||||||
let hir_bounds = self.lower_param_bounds(
|
let hir_bounds = self
|
||||||
bounds,
|
.lower_param_bounds(bounds, ImplTraitContext::Universal(parent_def_id));
|
||||||
ImplTraitContext::Universal(
|
|
||||||
in_band_ty_params,
|
|
||||||
in_band_ty_bounds,
|
|
||||||
parent_def_id,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// Set the name to `impl Bound1 + Bound2`.
|
// Set the name to `impl Bound1 + Bound2`.
|
||||||
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
|
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
|
||||||
in_band_ty_params.push(hir::GenericParam {
|
let param = hir::GenericParam {
|
||||||
hir_id: self.lower_node_id(def_node_id),
|
hir_id: self.lower_node_id(def_node_id),
|
||||||
name: ParamName::Plain(self.lower_ident(ident)),
|
name: ParamName::Plain(self.lower_ident(ident)),
|
||||||
pure_wrt_drop: false,
|
pure_wrt_drop: false,
|
||||||
span: self.lower_span(span),
|
span: self.lower_span(span),
|
||||||
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
|
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
|
||||||
colon_span: None,
|
colon_span: None,
|
||||||
});
|
};
|
||||||
|
self.impl_trait_defs.push(param);
|
||||||
|
|
||||||
if let Some(preds) = self.lower_generic_bound_predicate(
|
if let Some(preds) = self.lower_generic_bound_predicate(
|
||||||
ident,
|
ident,
|
||||||
def_node_id,
|
def_node_id,
|
||||||
|
@ -1268,7 +1253,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
hir_bounds,
|
hir_bounds,
|
||||||
hir::PredicateOrigin::ImplTrait,
|
hir::PredicateOrigin::ImplTrait,
|
||||||
) {
|
) {
|
||||||
in_band_ty_bounds.push(preds)
|
self.impl_trait_bounds.push(preds)
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::TyKind::Path(hir::QPath::Resolved(
|
hir::TyKind::Path(hir::QPath::Resolved(
|
||||||
|
@ -1442,21 +1427,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_fn_decl(
|
fn lower_fn_decl(
|
||||||
&mut self,
|
&mut self,
|
||||||
decl: &FnDecl,
|
decl: &FnDecl,
|
||||||
mut in_band_ty_params: Option<(
|
fn_node_id: Option<NodeId>,
|
||||||
NodeId,
|
|
||||||
&mut Vec<hir::GenericParam<'hir>>,
|
|
||||||
&mut Vec<hir::WherePredicate<'hir>>,
|
|
||||||
)>,
|
|
||||||
kind: FnDeclKind,
|
kind: FnDeclKind,
|
||||||
make_ret_async: Option<NodeId>,
|
make_ret_async: Option<NodeId>,
|
||||||
) -> &'hir hir::FnDecl<'hir> {
|
) -> &'hir hir::FnDecl<'hir> {
|
||||||
debug!(
|
debug!(
|
||||||
"lower_fn_decl(\
|
"lower_fn_decl(\
|
||||||
fn_decl: {:?}, \
|
fn_decl: {:?}, \
|
||||||
in_band_ty_params: {:?}, \
|
fn_node_id: {:?}, \
|
||||||
kind: {:?}, \
|
kind: {:?}, \
|
||||||
make_ret_async: {:?})",
|
make_ret_async: {:?})",
|
||||||
decl, in_band_ty_params, kind, make_ret_async,
|
decl, fn_node_id, kind, make_ret_async,
|
||||||
);
|
);
|
||||||
|
|
||||||
let c_variadic = decl.c_variadic();
|
let c_variadic = decl.c_variadic();
|
||||||
|
@ -1469,10 +1450,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
inputs = &inputs[..inputs.len() - 1];
|
inputs = &inputs[..inputs.len() - 1];
|
||||||
}
|
}
|
||||||
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
|
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
|
||||||
if let Some((_, ibty, ibpb)) = &mut in_band_ty_params {
|
if fn_node_id.is_some() {
|
||||||
self.lower_ty_direct(
|
self.lower_ty_direct(
|
||||||
¶m.ty,
|
¶m.ty,
|
||||||
ImplTraitContext::Universal(ibty, ibpb, self.current_hir_id_owner),
|
ImplTraitContext::Universal(self.current_hir_id_owner),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.lower_ty_direct(
|
self.lower_ty_direct(
|
||||||
|
@ -1494,15 +1475,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let output = if let Some(ret_id) = make_ret_async {
|
let output = if let Some(ret_id) = make_ret_async {
|
||||||
self.lower_async_fn_ret_ty(
|
self.lower_async_fn_ret_ty(
|
||||||
&decl.output,
|
&decl.output,
|
||||||
in_band_ty_params.expect("`make_ret_async` but no `fn_def_id`").0,
|
fn_node_id.expect("`make_ret_async` but no `fn_def_id`"),
|
||||||
ret_id,
|
ret_id,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
match decl.output {
|
match decl.output {
|
||||||
FnRetTy::Ty(ref ty) => {
|
FnRetTy::Ty(ref ty) => {
|
||||||
let context = match in_band_ty_params {
|
let context = match fn_node_id {
|
||||||
Some((node_id, _, _)) if kind.impl_trait_return_allowed() => {
|
Some(fn_node_id) if kind.impl_trait_return_allowed() => {
|
||||||
let fn_def_id = self.resolver.local_def_id(node_id);
|
let fn_def_id = self.resolver.local_def_id(fn_node_id);
|
||||||
ImplTraitContext::ReturnPositionOpaqueTy {
|
ImplTraitContext::ReturnPositionOpaqueTy {
|
||||||
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
|
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
|
||||||
}
|
}
|
||||||
|
@ -1788,7 +1769,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_param_bound(
|
fn lower_param_bound(
|
||||||
&mut self,
|
&mut self,
|
||||||
tpb: &GenericBound,
|
tpb: &GenericBound,
|
||||||
itctx: ImplTraitContext<'_, 'hir>,
|
itctx: ImplTraitContext,
|
||||||
) -> hir::GenericBound<'hir> {
|
) -> hir::GenericBound<'hir> {
|
||||||
match tpb {
|
match tpb {
|
||||||
GenericBound::Trait(p, modifier) => hir::GenericBound::Trait(
|
GenericBound::Trait(p, modifier) => hir::GenericBound::Trait(
|
||||||
|
@ -1966,11 +1947,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_trait_ref(
|
fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext) -> hir::TraitRef<'hir> {
|
||||||
&mut self,
|
|
||||||
p: &TraitRef,
|
|
||||||
itctx: ImplTraitContext<'_, 'hir>,
|
|
||||||
) -> hir::TraitRef<'hir> {
|
|
||||||
let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) {
|
let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) {
|
||||||
hir::QPath::Resolved(None, path) => path,
|
hir::QPath::Resolved(None, path) => path,
|
||||||
qpath => panic!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
|
qpath => panic!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
|
||||||
|
@ -1982,7 +1959,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_poly_trait_ref(
|
fn lower_poly_trait_ref(
|
||||||
&mut self,
|
&mut self,
|
||||||
p: &PolyTraitRef,
|
p: &PolyTraitRef,
|
||||||
mut itctx: ImplTraitContext<'_, 'hir>,
|
mut itctx: ImplTraitContext,
|
||||||
) -> hir::PolyTraitRef<'hir> {
|
) -> hir::PolyTraitRef<'hir> {
|
||||||
let bound_generic_params = self.lower_generic_params(&p.bound_generic_params);
|
let bound_generic_params = self.lower_generic_params(&p.bound_generic_params);
|
||||||
|
|
||||||
|
@ -1993,14 +1970,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
|
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_, 'hir>) -> hir::MutTy<'hir> {
|
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
|
||||||
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl }
|
hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_param_bounds(
|
fn lower_param_bounds(
|
||||||
&mut self,
|
&mut self,
|
||||||
bounds: &[GenericBound],
|
bounds: &[GenericBound],
|
||||||
itctx: ImplTraitContext<'_, 'hir>,
|
itctx: ImplTraitContext,
|
||||||
) -> hir::GenericBounds<'hir> {
|
) -> hir::GenericBounds<'hir> {
|
||||||
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx))
|
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx))
|
||||||
}
|
}
|
||||||
|
@ -2008,7 +1985,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
fn lower_param_bounds_mut<'s>(
|
fn lower_param_bounds_mut<'s>(
|
||||||
&'s mut self,
|
&'s mut self,
|
||||||
bounds: &'s [GenericBound],
|
bounds: &'s [GenericBound],
|
||||||
mut itctx: ImplTraitContext<'s, 'hir>,
|
mut itctx: ImplTraitContext,
|
||||||
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
|
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
|
||||||
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx.reborrow()))
|
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx.reborrow()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
qself: &Option<QSelf>,
|
qself: &Option<QSelf>,
|
||||||
p: &Path,
|
p: &Path,
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
mut itctx: ImplTraitContext<'_, 'hir>,
|
mut itctx: ImplTraitContext,
|
||||||
) -> hir::QPath<'hir> {
|
) -> hir::QPath<'hir> {
|
||||||
debug!("lower_qpath(id: {:?}, qself: {:?}, p: {:?})", id, qself, p);
|
debug!("lower_qpath(id: {:?}, qself: {:?}, p: {:?})", id, qself, p);
|
||||||
let qself_position = qself.as_ref().map(|q| q.position);
|
let qself_position = qself.as_ref().map(|q| q.position);
|
||||||
|
@ -180,7 +180,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
segment: &PathSegment,
|
segment: &PathSegment,
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
parenthesized_generic_args: ParenthesizedGenericArgs,
|
parenthesized_generic_args: ParenthesizedGenericArgs,
|
||||||
itctx: ImplTraitContext<'_, 'hir>,
|
itctx: ImplTraitContext,
|
||||||
) -> hir::PathSegment<'hir> {
|
) -> hir::PathSegment<'hir> {
|
||||||
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment,);
|
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment,);
|
||||||
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
|
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
|
||||||
|
@ -318,7 +318,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
&mut self,
|
&mut self,
|
||||||
data: &AngleBracketedArgs,
|
data: &AngleBracketedArgs,
|
||||||
param_mode: ParamMode,
|
param_mode: ParamMode,
|
||||||
mut itctx: ImplTraitContext<'_, 'hir>,
|
mut itctx: ImplTraitContext,
|
||||||
) -> (GenericArgsCtor<'hir>, bool) {
|
) -> (GenericArgsCtor<'hir>, bool) {
|
||||||
let has_non_lt_args = data.args.iter().any(|arg| match arg {
|
let has_non_lt_args = data.args.iter().any(|arg| match arg {
|
||||||
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
|
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue