Remove ImplTraitContext::reborrow
This commit is contained in:
parent
208ffbbe86
commit
d327db9319
3 changed files with 21 additions and 42 deletions
|
@ -1337,7 +1337,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,
|
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
|
||||||
|
@ -1388,7 +1388,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
|
|
||||||
let mut predicates = SmallVec::new();
|
let mut predicates = SmallVec::new();
|
||||||
predicates.extend(generics.params.iter().filter_map(|param| {
|
predicates.extend(generics.params.iter().filter_map(|param| {
|
||||||
let bounds = self.lower_param_bounds(¶m.bounds, itctx.reborrow());
|
let bounds = self.lower_param_bounds(¶m.bounds, itctx);
|
||||||
self.lower_generic_bound_predicate(
|
self.lower_generic_bound_predicate(
|
||||||
param.ident,
|
param.ident,
|
||||||
param.id,
|
param.id,
|
||||||
|
|
|
@ -293,18 +293,6 @@ enum ImplTraitPosition {
|
||||||
ImplReturn,
|
ImplReturn,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImplTraitContext {
|
|
||||||
fn reborrow<'this>(&'this mut self) -> ImplTraitContext {
|
|
||||||
use self::ImplTraitContext::*;
|
|
||||||
match self {
|
|
||||||
Universal(parent) => Universal(*parent),
|
|
||||||
ReturnPositionOpaqueTy { origin } => ReturnPositionOpaqueTy { origin: *origin },
|
|
||||||
TypeAliasesOpaqueTy => TypeAliasesOpaqueTy,
|
|
||||||
Disallowed(pos) => Disallowed(*pos),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for ImplTraitPosition {
|
impl std::fmt::Display for ImplTraitPosition {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let name = match self {
|
let name = match self {
|
||||||
|
@ -867,7 +855,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,
|
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);
|
||||||
|
|
||||||
|
@ -875,12 +863,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let gen_args = if let Some(ref gen_args) = constraint.gen_args {
|
let gen_args = if let Some(ref gen_args) = constraint.gen_args {
|
||||||
let gen_args_ctor = match gen_args {
|
let gen_args_ctor = match gen_args {
|
||||||
GenericArgs::AngleBracketed(ref data) => {
|
GenericArgs::AngleBracketed(ref data) => {
|
||||||
self.lower_angle_bracketed_parameter_data(
|
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
|
||||||
data,
|
|
||||||
ParamMode::Explicit,
|
|
||||||
itctx.reborrow(),
|
|
||||||
)
|
|
||||||
.0
|
|
||||||
}
|
}
|
||||||
GenericArgs::Parenthesized(ref data) => {
|
GenericArgs::Parenthesized(ref data) => {
|
||||||
let mut err = self.sess.struct_span_err(
|
let mut err = self.sess.struct_span_err(
|
||||||
|
@ -892,7 +875,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.lower_angle_bracketed_parameter_data(
|
self.lower_angle_bracketed_parameter_data(
|
||||||
&data.as_angle_bracketed_args(),
|
&data.as_angle_bracketed_args(),
|
||||||
ParamMode::Explicit,
|
ParamMode::Explicit,
|
||||||
itctx.reborrow(),
|
itctx,
|
||||||
)
|
)
|
||||||
.0
|
.0
|
||||||
}
|
}
|
||||||
|
@ -1097,7 +1080,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::Ty<'hir> {
|
fn lower_ty_direct(&mut self, t: &Ty, 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,
|
||||||
|
@ -1129,11 +1112,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
}))
|
}))
|
||||||
}),
|
}),
|
||||||
TyKind::Never => hir::TyKind::Never,
|
TyKind::Never => hir::TyKind::Never,
|
||||||
TyKind::Tup(ref tys) => {
|
TyKind::Tup(ref tys) => hir::TyKind::Tup(
|
||||||
hir::TyKind::Tup(self.arena.alloc_from_iter(
|
self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty_direct(ty, itctx))),
|
||||||
tys.iter().map(|ty| self.lower_ty_direct(ty, itctx.reborrow())),
|
),
|
||||||
))
|
|
||||||
}
|
|
||||||
TyKind::Paren(ref ty) => {
|
TyKind::Paren(ref ty) => {
|
||||||
return self.lower_ty_direct(ty, itctx);
|
return self.lower_ty_direct(ty, itctx);
|
||||||
}
|
}
|
||||||
|
@ -1167,7 +1148,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
GenericBound::Trait(
|
GenericBound::Trait(
|
||||||
ref ty,
|
ref ty,
|
||||||
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
|
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
|
||||||
) => Some(this.lower_poly_trait_ref(ty, itctx.reborrow())),
|
) => Some(this.lower_poly_trait_ref(ty, itctx)),
|
||||||
// `~const ?Bound` will cause an error during AST validation
|
// `~const ?Bound` will cause an error during AST validation
|
||||||
// anyways, so treat it like `?Bound` as compilation proceeds.
|
// anyways, so treat it like `?Bound` as compilation proceeds.
|
||||||
GenericBound::Trait(
|
GenericBound::Trait(
|
||||||
|
@ -1935,12 +1916,12 @@ 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,
|
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);
|
||||||
|
|
||||||
let trait_ref = self.with_lifetime_binder(p.trait_ref.ref_id, |this| {
|
let trait_ref = self.with_lifetime_binder(p.trait_ref.ref_id, |this| {
|
||||||
this.lower_trait_ref(&p.trait_ref, itctx.reborrow())
|
this.lower_trait_ref(&p.trait_ref, itctx)
|
||||||
});
|
});
|
||||||
|
|
||||||
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) }
|
||||||
|
@ -1961,9 +1942,9 @@ 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,
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lowers a block directly to an expression, presuming that it
|
/// Lowers a block directly to an expression, presuming that it
|
||||||
|
|
|
@ -21,11 +21,11 @@ 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,
|
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);
|
||||||
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx.reborrow()));
|
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));
|
||||||
|
|
||||||
let partial_res =
|
let partial_res =
|
||||||
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
|
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
|
||||||
|
@ -70,7 +70,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
segment,
|
segment,
|
||||||
param_mode,
|
param_mode,
|
||||||
parenthesized_generic_args,
|
parenthesized_generic_args,
|
||||||
itctx.reborrow(),
|
itctx,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
|
@ -116,7 +116,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
segment,
|
segment,
|
||||||
param_mode,
|
param_mode,
|
||||||
ParenthesizedGenericArgs::Err,
|
ParenthesizedGenericArgs::Err,
|
||||||
itctx.reborrow(),
|
itctx,
|
||||||
));
|
));
|
||||||
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
|
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
|
||||||
|
|
||||||
|
@ -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,
|
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(_))
|
||||||
|
@ -329,14 +329,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|arg| match arg {
|
.filter_map(|arg| match arg {
|
||||||
AngleBracketedArg::Arg(arg) => Some(self.lower_generic_arg(arg, itctx.reborrow())),
|
AngleBracketedArg::Arg(arg) => Some(self.lower_generic_arg(arg, itctx)),
|
||||||
AngleBracketedArg::Constraint(_) => None,
|
AngleBracketedArg::Constraint(_) => None,
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let bindings = self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
|
let bindings = self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
|
||||||
AngleBracketedArg::Constraint(c) => {
|
AngleBracketedArg::Constraint(c) => Some(self.lower_assoc_ty_constraint(c, itctx)),
|
||||||
Some(self.lower_assoc_ty_constraint(c, itctx.reborrow()))
|
|
||||||
}
|
|
||||||
AngleBracketedArg::Arg(_) => None,
|
AngleBracketedArg::Arg(_) => None,
|
||||||
}));
|
}));
|
||||||
let ctor = GenericArgsCtor { args, bindings, parenthesized: false, span: data.span };
|
let ctor = GenericArgsCtor { args, bindings, parenthesized: false, span: data.span };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue