Skip to content

Commit 0b41aed

Browse files
authored
Rollup merge of #164105 - JonathanBrouwer:indirect-constarg, r=mu001999
Remove unnecessary indirection around `hir::ConstArg` Probably doesn't have measurable perf effect because `ConstArg` is not that common of a type (yet), but it's nicer this way regardless imo :)
2 parents f2f26bc + 672e1a1 commit 0b41aed

5 files changed

Lines changed: 26 additions & 27 deletions

File tree

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,10 +2844,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
28442844
None,
28452845
);
28462846

2847-
let lowered_args = self.arena.alloc_from_iter(args.iter().map(|arg| {
2848-
let const_arg = self.lower_expr_to_const_arg_direct(arg, None);
2849-
&*self.arena.alloc(const_arg)
2850-
}));
2847+
let lowered_args = self.arena.alloc_from_iter(
2848+
args.iter().map(|arg| self.lower_expr_to_const_arg_direct(arg, None)),
2849+
);
28512850

28522851
ConstArg {
28532852
hir_id: self.lower_node_id(node_id),
@@ -2856,10 +2855,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
28562855
}
28572856
}
28582857
ExprKind::Tup(exprs) => {
2859-
let exprs = self.arena.alloc_from_iter(exprs.iter().map(|expr| {
2860-
let expr = self.lower_expr_to_const_arg_direct(expr, None);
2861-
&*self.arena.alloc(expr)
2862-
}));
2858+
let exprs = self.arena.alloc_from_iter(
2859+
exprs.iter().map(|expr| self.lower_expr_to_const_arg_direct(expr, None)),
2860+
);
28632861

28642862
ConstArg {
28652863
hir_id: self.lower_node_id(node_id),
@@ -2892,12 +2890,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
28922890
self.lower_attrs(hir_id, &f.attrs, f.span, Target::ExprField);
28932891
let expr = self.lower_expr_to_const_arg_direct(&f.expr, None);
28942892

2895-
&*self.arena.alloc(hir::ConstArgExprField {
2893+
hir::ConstArgExprField {
28962894
hir_id,
28972895
field: self.lower_ident(f.ident),
28982896
expr: self.arena.alloc(expr),
28992897
span: self.lower_span(f.span),
2900-
})
2898+
}
29012899
}));
29022900

29032901
ConstArg {
@@ -2907,10 +2905,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
29072905
}
29082906
}
29092907
ExprKind::Array(elements) => {
2910-
let lowered_elems = self.arena.alloc_from_iter(elements.iter().map(|element| {
2911-
let const_arg = self.lower_expr_to_const_arg_direct(element, None);
2912-
&*self.arena.alloc(const_arg)
2913-
}));
2908+
let lowered_elems = self.arena.alloc_from_iter(
2909+
elements
2910+
.iter()
2911+
.map(|element| self.lower_expr_to_const_arg_direct(element, None)),
2912+
);
29142913
let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
29152914
span: self.lower_span(expr.span),
29162915
elems: lowered_elems,

‎compiler/rustc_hir/src/hir.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl<'hir, Unambig> ConstArg<'hir, Unambig> {
508508
#[derive(Clone, Copy, Debug, StableHash)]
509509
#[repr(u8, C)]
510510
pub enum ConstArgKind<'hir, Unambig = ()> {
511-
Tup(&'hir [&'hir ConstArg<'hir>]),
511+
Tup(&'hir [ConstArg<'hir>]),
512512
/// **Note:** Currently this is only used for bare const params
513513
/// (`N` where `fn foo<const N: usize>(...)`),
514514
/// not paths to any const (`N` where `const N: usize = ...`).
@@ -517,9 +517,9 @@ pub enum ConstArgKind<'hir, Unambig = ()> {
517517
Path(QPath<'hir>),
518518
Anon(&'hir AnonConst),
519519
/// Represents construction of struct/struct variants
520-
Struct(QPath<'hir>, &'hir [&'hir ConstArgExprField<'hir>]),
520+
Struct(QPath<'hir>, &'hir [ConstArgExprField<'hir>]),
521521
/// Tuple constructor variant
522-
TupleCall(QPath<'hir>, &'hir [&'hir ConstArg<'hir>]),
522+
TupleCall(QPath<'hir>, &'hir [ConstArg<'hir>]),
523523
/// Array literal argument
524524
Array(&'hir ConstArgArrayExpr<'hir>),
525525
/// Error const
@@ -544,7 +544,7 @@ pub struct ConstArgExprField<'hir> {
544544
#[derive(Clone, Copy, Debug, StableHash)]
545545
pub struct ConstArgArrayExpr<'hir> {
546546
pub span: Span,
547-
pub elems: &'hir [&'hir ConstArg<'hir>],
547+
pub elems: &'hir [ConstArg<'hir>],
548548
}
549549

550550
/// Tracks what a [GenericArg::Infer] can be inferred to based on its syntax.

‎compiler/rustc_hir/src/intravisit.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,13 +1129,13 @@ pub fn walk_const_arg<'v, V: Visitor<'v>>(
11291129
ConstArgKind::TupleCall(qpath, args) => {
11301130
try_visit!(visitor.visit_qpath(qpath, *hir_id, qpath.span()));
11311131
for arg in *args {
1132-
try_visit!(visitor.visit_const_arg_unambig(*arg));
1132+
try_visit!(visitor.visit_const_arg_unambig(arg));
11331133
}
11341134
V::Result::output()
11351135
}
11361136
ConstArgKind::Array(array_expr) => {
11371137
for arg in array_expr.elems {
1138-
try_visit!(visitor.visit_const_arg_unambig(*arg));
1138+
try_visit!(visitor.visit_const_arg_unambig(arg));
11391139
}
11401140
V::Result::output()
11411141
}

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25412541
&self,
25422542
hir_id: HirId,
25432543
qpath: hir::QPath<'_>,
2544-
args: &[&hir::ConstArg<'_>],
2544+
args: &[hir::ConstArg<'_>],
25452545
span: Span,
25462546
) -> Const<'tcx> {
25472547
let tcx = self.tcx();
@@ -2642,7 +2642,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26422642

26432643
fn lower_const_arg_tup(
26442644
&self,
2645-
exprs: &[&hir::ConstArg<'_>],
2645+
exprs: &[hir::ConstArg<'_>],
26462646
ty: Ty<'tcx>,
26472647
span: Span,
26482648
) -> Const<'tcx> {
@@ -2685,7 +2685,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26852685
&self,
26862686
hir_id: HirId,
26872687
qpath: hir::QPath<'_>,
2688-
inits: &[&hir::ConstArgExprField<'_>],
2688+
inits: &[hir::ConstArgExprField<'_>],
26892689
span: Span,
26902690
) -> Const<'tcx> {
26912691
// FIXME(mgca): try to deduplicate this function with

‎compiler/rustc_hir_pretty/src/lib.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,14 +1216,14 @@ impl<'a> State<'a> {
12161216
}
12171217
}
12181218

1219-
fn print_const_struct(&mut self, qpath: &hir::QPath<'_>, fields: &&[&ConstArgExprField<'_>]) {
1219+
fn print_const_struct(&mut self, qpath: &hir::QPath<'_>, fields: &[ConstArgExprField<'_>]) {
12201220
self.print_qpath(qpath, true);
12211221
self.word(" ");
12221222
self.word("{");
12231223
if !fields.is_empty() {
12241224
self.nbsp();
12251225
}
1226-
self.commasep(Inconsistent, *fields, |s, field| {
1226+
self.commasep(Inconsistent, fields, |s, field| {
12271227
s.word(field.field.as_str().to_string());
12281228
s.word(":");
12291229
s.nbsp();
@@ -1232,10 +1232,10 @@ impl<'a> State<'a> {
12321232
self.word("}");
12331233
}
12341234

1235-
fn print_const_ctor(&mut self, qpath: &hir::QPath<'_>, args: &&[&ConstArg<'_, ()>]) {
1235+
fn print_const_ctor(&mut self, qpath: &hir::QPath<'_>, args: &[ConstArg<'_, ()>]) {
12361236
self.print_qpath(qpath, true);
12371237
self.word("(");
1238-
self.commasep(Inconsistent, *args, |s, arg| {
1238+
self.commasep(Inconsistent, args, |s, arg| {
12391239
s.print_const_arg(arg);
12401240
});
12411241
self.word(")");

0 commit comments

Comments
 (0)