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(
|
||||
&mut self,
|
||||
generics: &Generics,
|
||||
mut itctx: ImplTraitContext,
|
||||
itctx: ImplTraitContext,
|
||||
) -> GenericsCtor<'hir> {
|
||||
// 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
|
||||
|
@ -1388,7 +1388,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
|
||||
let mut predicates = SmallVec::new();
|
||||
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(
|
||||
param.ident,
|
||||
param.id,
|
||||
|
|
|
@ -293,18 +293,6 @@ enum ImplTraitPosition {
|
|||
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 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let name = match self {
|
||||
|
@ -867,7 +855,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
fn lower_assoc_ty_constraint(
|
||||
&mut self,
|
||||
constraint: &AssocConstraint,
|
||||
mut itctx: ImplTraitContext,
|
||||
itctx: ImplTraitContext,
|
||||
) -> hir::TypeBinding<'hir> {
|
||||
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_ctor = match gen_args {
|
||||
GenericArgs::AngleBracketed(ref data) => {
|
||||
self.lower_angle_bracketed_parameter_data(
|
||||
data,
|
||||
ParamMode::Explicit,
|
||||
itctx.reborrow(),
|
||||
)
|
||||
.0
|
||||
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
|
||||
}
|
||||
GenericArgs::Parenthesized(ref data) => {
|
||||
let mut err = self.sess.struct_span_err(
|
||||
|
@ -892,7 +875,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
self.lower_angle_bracketed_parameter_data(
|
||||
&data.as_angle_bracketed_args(),
|
||||
ParamMode::Explicit,
|
||||
itctx.reborrow(),
|
||||
itctx,
|
||||
)
|
||||
.0
|
||||
}
|
||||
|
@ -1097,7 +1080,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
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 {
|
||||
TyKind::Infer => hir::TyKind::Infer,
|
||||
TyKind::Err => hir::TyKind::Err,
|
||||
|
@ -1129,11 +1112,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
}))
|
||||
}),
|
||||
TyKind::Never => hir::TyKind::Never,
|
||||
TyKind::Tup(ref tys) => {
|
||||
hir::TyKind::Tup(self.arena.alloc_from_iter(
|
||||
tys.iter().map(|ty| self.lower_ty_direct(ty, itctx.reborrow())),
|
||||
))
|
||||
}
|
||||
TyKind::Tup(ref tys) => hir::TyKind::Tup(
|
||||
self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty_direct(ty, itctx))),
|
||||
),
|
||||
TyKind::Paren(ref ty) => {
|
||||
return self.lower_ty_direct(ty, itctx);
|
||||
}
|
||||
|
@ -1167,7 +1148,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
GenericBound::Trait(
|
||||
ref ty,
|
||||
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
|
||||
// anyways, so treat it like `?Bound` as compilation proceeds.
|
||||
GenericBound::Trait(
|
||||
|
@ -1935,12 +1916,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
fn lower_poly_trait_ref(
|
||||
&mut self,
|
||||
p: &PolyTraitRef,
|
||||
mut itctx: ImplTraitContext,
|
||||
itctx: ImplTraitContext,
|
||||
) -> hir::PolyTraitRef<'hir> {
|
||||
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| {
|
||||
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) }
|
||||
|
@ -1961,9 +1942,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
fn lower_param_bounds_mut<'s>(
|
||||
&'s mut self,
|
||||
bounds: &'s [GenericBound],
|
||||
mut itctx: ImplTraitContext,
|
||||
itctx: ImplTraitContext,
|
||||
) -> 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
|
||||
|
|
|
@ -21,11 +21,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
qself: &Option<QSelf>,
|
||||
p: &Path,
|
||||
param_mode: ParamMode,
|
||||
mut itctx: ImplTraitContext,
|
||||
itctx: ImplTraitContext,
|
||||
) -> hir::QPath<'hir> {
|
||||
debug!("lower_qpath(id: {:?}, qself: {:?}, p: {:?})", id, qself, p);
|
||||
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 =
|
||||
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
|
||||
|
@ -70,7 +70,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
segment,
|
||||
param_mode,
|
||||
parenthesized_generic_args,
|
||||
itctx.reborrow(),
|
||||
itctx,
|
||||
)
|
||||
},
|
||||
)),
|
||||
|
@ -116,7 +116,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
segment,
|
||||
param_mode,
|
||||
ParenthesizedGenericArgs::Err,
|
||||
itctx.reborrow(),
|
||||
itctx,
|
||||
));
|
||||
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
|
||||
|
||||
|
@ -318,7 +318,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
&mut self,
|
||||
data: &AngleBracketedArgs,
|
||||
param_mode: ParamMode,
|
||||
mut itctx: ImplTraitContext,
|
||||
itctx: ImplTraitContext,
|
||||
) -> (GenericArgsCtor<'hir>, bool) {
|
||||
let has_non_lt_args = data.args.iter().any(|arg| match arg {
|
||||
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
|
||||
|
@ -329,14 +329,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
.args
|
||||
.iter()
|
||||
.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,
|
||||
})
|
||||
.collect();
|
||||
let bindings = self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
|
||||
AngleBracketedArg::Constraint(c) => {
|
||||
Some(self.lower_assoc_ty_constraint(c, itctx.reborrow()))
|
||||
}
|
||||
AngleBracketedArg::Constraint(c) => Some(self.lower_assoc_ty_constraint(c, itctx)),
|
||||
AngleBracketedArg::Arg(_) => None,
|
||||
}));
|
||||
let ctor = GenericArgsCtor { args, bindings, parenthesized: false, span: data.span };
|
||||
|
|
Loading…
Add table
Reference in a new issue