From d327db9319e7b8ec7dff56f1fc2cfb199d3151b9 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 31 May 2022 16:46:15 -0300 Subject: [PATCH] Remove ImplTraitContext::reborrow --- compiler/rustc_ast_lowering/src/item.rs | 4 +-- compiler/rustc_ast_lowering/src/lib.rs | 43 +++++++------------------ compiler/rustc_ast_lowering/src/path.rs | 16 ++++----- 3 files changed, 21 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 1b7fa1da77f..c905f4f11bc 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -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, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a934bcbe337..1bd2988576a 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -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> + 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 diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 0827fc8173e..d56974b773d 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -21,11 +21,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { qself: &Option, 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 };