Skip to content

Commit 8610550

Browse files
committed
Pass ImplTraitContext as &, there's no need for that to be &mut
1 parent 669f2d4 commit 8610550

File tree

6 files changed

+84
-107
lines changed

6 files changed

+84
-107
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
220220
&sym.qself,
221221
&sym.path,
222222
ParamMode::Optional,
223-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
223+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
224224
);
225225
hir::InlineAsmOperand::SymStatic { path, def_id }
226226
} else {

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
8484
}
8585

8686
fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> {
87-
let ty = l.ty.as_ref().map(|t| {
88-
self.lower_ty(t, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Variable))
89-
});
87+
let ty = l
88+
.ty
89+
.as_ref()
90+
.map(|t| self.lower_ty(t, &ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
9091
let init = l.kind.init().map(|init| self.lower_expr(init));
9192
let hir_id = self.lower_node_id(l.id);
9293
let pat = self.lower_pat(&l.pat);

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
6666
seg,
6767
ParamMode::Optional,
6868
ParenthesizedGenericArgs::Err,
69-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
69+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7070
));
7171
let receiver = self.lower_expr(receiver);
7272
let args =
@@ -89,14 +89,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
8989
}
9090
ExprKind::Cast(ref expr, ref ty) => {
9191
let expr = self.lower_expr(expr);
92-
let ty = self
93-
.lower_ty(ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
92+
let ty =
93+
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
9494
hir::ExprKind::Cast(expr, ty)
9595
}
9696
ExprKind::Type(ref expr, ref ty) => {
9797
let expr = self.lower_expr(expr);
98-
let ty = self
99-
.lower_ty(ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
98+
let ty =
99+
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
100100
hir::ExprKind::Type(expr, ty)
101101
}
102102
ExprKind::AddrOf(k, m, ref ohs) => {
@@ -225,7 +225,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
225225
qself,
226226
path,
227227
ParamMode::Optional,
228-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
228+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
229229
);
230230
hir::ExprKind::Path(qpath)
231231
}
@@ -259,7 +259,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
259259
&se.qself,
260260
&se.path,
261261
ParamMode::Optional,
262-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
262+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
263263
)),
264264
self.arena
265265
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
@@ -556,14 +556,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
556556
async_gen_kind: hir::AsyncGeneratorKind,
557557
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
558558
) -> hir::ExprKind<'hir> {
559-
let output =
560-
match ret_ty {
561-
Some(ty) => hir::FnRetTy::Return(self.lower_ty(
562-
&ty,
563-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock),
564-
)),
565-
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
566-
};
559+
let output = match ret_ty {
560+
Some(ty) => hir::FnRetTy::Return(
561+
self.lower_ty(&ty, &ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)),
562+
),
563+
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
564+
};
567565

568566
// Resume argument type. We let the compiler infer this to simplify the lowering. It is
569567
// fully constrained by `future::from_generator`.
@@ -1131,7 +1129,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11311129
qself,
11321130
path,
11331131
ParamMode::Optional,
1134-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
1132+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
11351133
);
11361134
// Destructure like a tuple struct.
11371135
let tuple_struct_pat = hir::PatKind::TupleStruct(
@@ -1150,7 +1148,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11501148
qself,
11511149
path,
11521150
ParamMode::Optional,
1153-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
1151+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
11541152
);
11551153
// Destructure like a unit struct.
11561154
let unit_struct_pat = hir::PatKind::Path(qpath);
@@ -1174,7 +1172,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11741172
&se.qself,
11751173
&se.path,
11761174
ParamMode::Optional,
1177-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
1175+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
11781176
);
11791177
let fields_omitted = match &se.rest {
11801178
StructRest::Base(e) => {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
313313
let (generics, ty) = self.lower_generics(
314314
&generics,
315315
id,
316-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
317-
|this| this.lower_ty(ty, &mut ImplTraitContext::TypeAliasesOpaqueTy),
316+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
317+
|this| this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy),
318318
);
319319
hir::ItemKind::TyAlias(ty, generics)
320320
}
@@ -326,7 +326,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
326326
let (generics, ty) = self.lower_generics(
327327
&generics,
328328
id,
329-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
329+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
330330
|this| this.arena.alloc(this.ty(span, hir::TyKind::Err)),
331331
);
332332
hir::ItemKind::TyAlias(ty, generics)
@@ -335,7 +335,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
335335
let (generics, variants) = self.lower_generics(
336336
generics,
337337
id,
338-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
338+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
339339
|this| {
340340
this.arena.alloc_from_iter(
341341
enum_definition.variants.iter().map(|x| this.lower_variant(x)),
@@ -348,7 +348,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
348348
let (generics, struct_def) = self.lower_generics(
349349
generics,
350350
id,
351-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
351+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
352352
|this| this.lower_variant_data(hir_id, struct_def),
353353
);
354354
hir::ItemKind::Struct(struct_def, generics)
@@ -357,7 +357,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
357357
let (generics, vdata) = self.lower_generics(
358358
generics,
359359
id,
360-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
360+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
361361
|this| this.lower_variant_data(hir_id, vdata),
362362
);
363363
hir::ItemKind::Union(vdata, generics)
@@ -391,14 +391,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
391391
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
392392
this.lower_trait_ref(
393393
trait_ref,
394-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
394+
&ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
395395
)
396396
});
397397

398-
let lowered_ty = this.lower_ty(
399-
ty,
400-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Type),
401-
);
398+
let lowered_ty = this
399+
.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
402400

403401
(trait_ref, lowered_ty)
404402
});
@@ -437,11 +435,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
437435
let (generics, (unsafety, items, bounds)) = self.lower_generics(
438436
generics,
439437
id,
440-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
438+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
441439
|this| {
442440
let bounds = this.lower_param_bounds(
443441
bounds,
444-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
442+
&ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
445443
);
446444
let items = this.arena.alloc_from_iter(
447445
items.iter().map(|item| this.lower_trait_item_ref(item)),
@@ -456,11 +454,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
456454
let (generics, bounds) = self.lower_generics(
457455
generics,
458456
id,
459-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
457+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
460458
|this| {
461459
this.lower_param_bounds(
462460
bounds,
463-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
461+
&ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
464462
)
465463
},
466464
);
@@ -483,7 +481,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
483481
span: Span,
484482
body: Option<&Expr>,
485483
) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
486-
let ty = self.lower_ty(ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
484+
let ty = self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
487485
(ty, self.lower_const_body(span, body))
488486
}
489487

@@ -675,8 +673,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
675673
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
676674
}
677675
ForeignItemKind::Static(ref t, m, _) => {
678-
let ty = self
679-
.lower_ty(t, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
676+
let ty =
677+
self.lower_ty(t, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
680678
hir::ForeignItemKind::Static(ty, m)
681679
}
682680
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
@@ -744,11 +742,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
744742
qself,
745743
path,
746744
ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124)
747-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
745+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
748746
);
749747
self.arena.alloc(t)
750748
} else {
751-
self.lower_ty(&f.ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type))
749+
self.lower_ty(&f.ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type))
752750
};
753751
let hir_id = self.lower_node_id(f.id);
754752
self.lower_attrs(hir_id, &f.attrs);
@@ -771,8 +769,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
771769

772770
let (generics, kind, has_default) = match i.kind {
773771
AssocItemKind::Const(_, ref ty, ref default) => {
774-
let ty =
775-
self.lower_ty(ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
772+
let ty = self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
776773
let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
777774
(hir::Generics::empty(), hir::TraitItemKind::Const(ty, body), body.is_some())
778775
}
@@ -813,18 +810,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
813810
let (generics, kind) = self.lower_generics(
814811
&generics,
815812
i.id,
816-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
813+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
817814
|this| {
818815
let ty = ty.as_ref().map(|x| {
819-
this.lower_ty(
820-
x,
821-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Type),
822-
)
816+
this.lower_ty(x, &ImplTraitContext::Disallowed(ImplTraitPosition::Type))
823817
});
824818
hir::TraitItemKind::Type(
825819
this.lower_param_bounds(
826820
bounds,
827-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
821+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
828822
),
829823
ty,
830824
)
@@ -877,8 +871,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
877871

878872
let (generics, kind) = match &i.kind {
879873
AssocItemKind::Const(_, ty, expr) => {
880-
let ty =
881-
self.lower_ty(ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
874+
let ty = self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
882875
(
883876
hir::Generics::empty(),
884877
hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())),
@@ -905,14 +898,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
905898
self.lower_generics(
906899
&generics,
907900
i.id,
908-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
901+
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
909902
|this| match ty {
910903
None => {
911904
let ty = this.arena.alloc(this.ty(i.span, hir::TyKind::Err));
912905
hir::ImplItemKind::TyAlias(ty)
913906
}
914907
Some(ty) => {
915-
let ty = this.lower_ty(ty, &mut ImplTraitContext::TypeAliasesOpaqueTy);
908+
let ty = this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy);
916909
hir::ImplItemKind::TyAlias(ty)
917910
}
918911
},
@@ -1322,7 +1315,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13221315
&mut self,
13231316
generics: &Generics,
13241317
parent_node_id: NodeId,
1325-
itctx: &mut ImplTraitContext,
1318+
itctx: &ImplTraitContext,
13261319
f: impl FnOnce(&mut Self) -> T,
13271320
) -> (&'hir hir::Generics<'hir>, T) {
13281321
debug_assert!(self.impl_trait_defs.is_empty());
@@ -1427,7 +1420,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14271420
id: NodeId,
14281421
kind: &GenericParamKind,
14291422
bounds: &[GenericBound],
1430-
itctx: &mut ImplTraitContext,
1423+
itctx: &ImplTraitContext,
14311424
origin: PredicateOrigin,
14321425
) -> Option<hir::WherePredicate<'hir>> {
14331426
// Do not create a clause if we do not have anything inside it.
@@ -1502,14 +1495,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
15021495
span,
15031496
}) => hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
15041497
bound_generic_params: self.lower_generic_params(bound_generic_params),
1505-
bounded_ty: self.lower_ty(
1506-
bounded_ty,
1507-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Type),
1508-
),
1498+
bounded_ty: self
1499+
.lower_ty(bounded_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
15091500
bounds: self.arena.alloc_from_iter(bounds.iter().map(|bound| {
15101501
self.lower_param_bound(
15111502
bound,
1512-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
1503+
&ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
15131504
)
15141505
})),
15151506
span: self.lower_span(span),
@@ -1524,20 +1515,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
15241515
lifetime: self.lower_lifetime(lifetime),
15251516
bounds: self.lower_param_bounds(
15261517
bounds,
1527-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
1518+
&ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
15281519
),
15291520
in_where_clause: true,
15301521
}),
15311522
WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, span }) => {
15321523
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
1533-
lhs_ty: self.lower_ty(
1534-
lhs_ty,
1535-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Type),
1536-
),
1537-
rhs_ty: self.lower_ty(
1538-
rhs_ty,
1539-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Type),
1540-
),
1524+
lhs_ty: self
1525+
.lower_ty(lhs_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
1526+
rhs_ty: self
1527+
.lower_ty(rhs_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
15411528
span: self.lower_span(span),
15421529
})
15431530
}

0 commit comments

Comments
 (0)