Skip to content

Commit d327db9

Browse files
committed
Remove ImplTraitContext::reborrow
1 parent 208ffbb commit d327db9

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13371337
pub(super) fn lower_generics_mut(
13381338
&mut self,
13391339
generics: &Generics,
1340-
mut itctx: ImplTraitContext,
1340+
itctx: ImplTraitContext,
13411341
) -> GenericsCtor<'hir> {
13421342
// Error if `?Trait` bounds in where clauses don't refer directly to type parameters.
13431343
// Note: we used to clone these bounds directly onto the type parameter (and avoid lowering
@@ -1388,7 +1388,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13881388

13891389
let mut predicates = SmallVec::new();
13901390
predicates.extend(generics.params.iter().filter_map(|param| {
1391-
let bounds = self.lower_param_bounds(&param.bounds, itctx.reborrow());
1391+
let bounds = self.lower_param_bounds(&param.bounds, itctx);
13921392
self.lower_generic_bound_predicate(
13931393
param.ident,
13941394
param.id,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,6 @@ enum ImplTraitPosition {
293293
ImplReturn,
294294
}
295295

296-
impl ImplTraitContext {
297-
fn reborrow<'this>(&'this mut self) -> ImplTraitContext {
298-
use self::ImplTraitContext::*;
299-
match self {
300-
Universal(parent) => Universal(*parent),
301-
ReturnPositionOpaqueTy { origin } => ReturnPositionOpaqueTy { origin: *origin },
302-
TypeAliasesOpaqueTy => TypeAliasesOpaqueTy,
303-
Disallowed(pos) => Disallowed(*pos),
304-
}
305-
}
306-
}
307-
308296
impl std::fmt::Display for ImplTraitPosition {
309297
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
310298
let name = match self {
@@ -867,20 +855,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
867855
fn lower_assoc_ty_constraint(
868856
&mut self,
869857
constraint: &AssocConstraint,
870-
mut itctx: ImplTraitContext,
858+
itctx: ImplTraitContext,
871859
) -> hir::TypeBinding<'hir> {
872860
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
873861

874862
// lower generic arguments of identifier in constraint
875863
let gen_args = if let Some(ref gen_args) = constraint.gen_args {
876864
let gen_args_ctor = match gen_args {
877865
GenericArgs::AngleBracketed(ref data) => {
878-
self.lower_angle_bracketed_parameter_data(
879-
data,
880-
ParamMode::Explicit,
881-
itctx.reborrow(),
882-
)
883-
.0
866+
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
884867
}
885868
GenericArgs::Parenthesized(ref data) => {
886869
let mut err = self.sess.struct_span_err(
@@ -892,7 +875,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
892875
self.lower_angle_bracketed_parameter_data(
893876
&data.as_angle_bracketed_args(),
894877
ParamMode::Explicit,
895-
itctx.reborrow(),
878+
itctx,
896879
)
897880
.0
898881
}
@@ -1097,7 +1080,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10971080
self.ty(span, hir::TyKind::Tup(tys))
10981081
}
10991082

1100-
fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext) -> hir::Ty<'hir> {
1083+
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
11011084
let kind = match t.kind {
11021085
TyKind::Infer => hir::TyKind::Infer,
11031086
TyKind::Err => hir::TyKind::Err,
@@ -1129,11 +1112,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11291112
}))
11301113
}),
11311114
TyKind::Never => hir::TyKind::Never,
1132-
TyKind::Tup(ref tys) => {
1133-
hir::TyKind::Tup(self.arena.alloc_from_iter(
1134-
tys.iter().map(|ty| self.lower_ty_direct(ty, itctx.reborrow())),
1135-
))
1136-
}
1115+
TyKind::Tup(ref tys) => hir::TyKind::Tup(
1116+
self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty_direct(ty, itctx))),
1117+
),
11371118
TyKind::Paren(ref ty) => {
11381119
return self.lower_ty_direct(ty, itctx);
11391120
}
@@ -1167,7 +1148,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11671148
GenericBound::Trait(
11681149
ref ty,
11691150
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
1170-
) => Some(this.lower_poly_trait_ref(ty, itctx.reborrow())),
1151+
) => Some(this.lower_poly_trait_ref(ty, itctx)),
11711152
// `~const ?Bound` will cause an error during AST validation
11721153
// anyways, so treat it like `?Bound` as compilation proceeds.
11731154
GenericBound::Trait(
@@ -1935,12 +1916,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19351916
fn lower_poly_trait_ref(
19361917
&mut self,
19371918
p: &PolyTraitRef,
1938-
mut itctx: ImplTraitContext,
1919+
itctx: ImplTraitContext,
19391920
) -> hir::PolyTraitRef<'hir> {
19401921
let bound_generic_params = self.lower_generic_params(&p.bound_generic_params);
19411922

19421923
let trait_ref = self.with_lifetime_binder(p.trait_ref.ref_id, |this| {
1943-
this.lower_trait_ref(&p.trait_ref, itctx.reborrow())
1924+
this.lower_trait_ref(&p.trait_ref, itctx)
19441925
});
19451926

19461927
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
@@ -1961,9 +1942,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19611942
fn lower_param_bounds_mut<'s>(
19621943
&'s mut self,
19631944
bounds: &'s [GenericBound],
1964-
mut itctx: ImplTraitContext,
1945+
itctx: ImplTraitContext,
19651946
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
1966-
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx.reborrow()))
1947+
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
19671948
}
19681949

19691950
/// Lowers a block directly to an expression, presuming that it

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2121
qself: &Option<QSelf>,
2222
p: &Path,
2323
param_mode: ParamMode,
24-
mut itctx: ImplTraitContext,
24+
itctx: ImplTraitContext,
2525
) -> hir::QPath<'hir> {
2626
debug!("lower_qpath(id: {:?}, qself: {:?}, p: {:?})", id, qself, p);
2727
let qself_position = qself.as_ref().map(|q| q.position);
28-
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx.reborrow()));
28+
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));
2929

3030
let partial_res =
3131
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
@@ -70,7 +70,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7070
segment,
7171
param_mode,
7272
parenthesized_generic_args,
73-
itctx.reborrow(),
73+
itctx,
7474
)
7575
},
7676
)),
@@ -116,7 +116,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
116116
segment,
117117
param_mode,
118118
ParenthesizedGenericArgs::Err,
119-
itctx.reborrow(),
119+
itctx,
120120
));
121121
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
122122

@@ -318,7 +318,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
318318
&mut self,
319319
data: &AngleBracketedArgs,
320320
param_mode: ParamMode,
321-
mut itctx: ImplTraitContext,
321+
itctx: ImplTraitContext,
322322
) -> (GenericArgsCtor<'hir>, bool) {
323323
let has_non_lt_args = data.args.iter().any(|arg| match arg {
324324
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
@@ -329,14 +329,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
329329
.args
330330
.iter()
331331
.filter_map(|arg| match arg {
332-
AngleBracketedArg::Arg(arg) => Some(self.lower_generic_arg(arg, itctx.reborrow())),
332+
AngleBracketedArg::Arg(arg) => Some(self.lower_generic_arg(arg, itctx)),
333333
AngleBracketedArg::Constraint(_) => None,
334334
})
335335
.collect();
336336
let bindings = self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
337-
AngleBracketedArg::Constraint(c) => {
338-
Some(self.lower_assoc_ty_constraint(c, itctx.reborrow()))
339-
}
337+
AngleBracketedArg::Constraint(c) => Some(self.lower_assoc_ty_constraint(c, itctx)),
340338
AngleBracketedArg::Arg(_) => None,
341339
}));
342340
let ctor = GenericArgsCtor { args, bindings, parenthesized: false, span: data.span };

0 commit comments

Comments
 (0)