Skip to content

Commit db35b68

Browse files
committed
Use &'hir Expr everywhere.
For consistency, and because it makes HIR measurement simpler and more accurate.
1 parent 854219d commit db35b68

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
155155
let op = match *op {
156156
InlineAsmOperand::In { reg, ref expr } => hir::InlineAsmOperand::In {
157157
reg: lower_reg(reg),
158-
expr: self.lower_expr_mut(expr),
158+
expr: self.lower_expr(expr),
159159
},
160160
InlineAsmOperand::Out { reg, late, ref expr } => hir::InlineAsmOperand::Out {
161161
reg: lower_reg(reg),
162162
late,
163-
expr: expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
163+
expr: expr.as_ref().map(|expr| self.lower_expr(expr)),
164164
},
165165
InlineAsmOperand::InOut { reg, late, ref expr } => {
166166
hir::InlineAsmOperand::InOut {
167167
reg: lower_reg(reg),
168168
late,
169-
expr: self.lower_expr_mut(expr),
169+
expr: self.lower_expr(expr),
170170
}
171171
}
172172
InlineAsmOperand::SplitInOut { reg, late, ref in_expr, ref out_expr } => {
173173
hir::InlineAsmOperand::SplitInOut {
174174
reg: lower_reg(reg),
175175
late,
176-
in_expr: self.lower_expr_mut(in_expr),
177-
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
176+
in_expr: self.lower_expr(in_expr),
177+
out_expr: out_expr.as_ref().map(|expr| self.lower_expr(expr)),
178178
}
179179
}
180180
InlineAsmOperand::Const { ref anon_const } => {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
947947
params: &'hir [hir::Param<'hir>],
948948
value: hir::Expr<'hir>,
949949
) -> hir::BodyId {
950-
let body = hir::Body { generator_kind: self.generator_kind, params, value };
950+
let body = hir::Body {
951+
generator_kind: self.generator_kind,
952+
params,
953+
value: self.arena.alloc(value),
954+
};
951955
let id = body.id();
952956
debug_assert_eq!(id.hir_id.owner, self.current_hir_id_owner);
953957
self.bodies.push((id.hir_id.local_id, self.arena.alloc(body)));

compiler/rustc_hir/src/hir.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ pub struct BodyId {
14381438
#[derive(Debug, HashStable_Generic)]
14391439
pub struct Body<'hir> {
14401440
pub params: &'hir [Param<'hir>],
1441-
pub value: Expr<'hir>,
1441+
pub value: &'hir Expr<'hir>,
14421442
pub generator_kind: Option<GeneratorKind>,
14431443
}
14441444

@@ -2561,23 +2561,23 @@ pub enum TyKind<'hir> {
25612561
pub enum InlineAsmOperand<'hir> {
25622562
In {
25632563
reg: InlineAsmRegOrRegClass,
2564-
expr: Expr<'hir>,
2564+
expr: &'hir Expr<'hir>,
25652565
},
25662566
Out {
25672567
reg: InlineAsmRegOrRegClass,
25682568
late: bool,
2569-
expr: Option<Expr<'hir>>,
2569+
expr: Option<&'hir Expr<'hir>>,
25702570
},
25712571
InOut {
25722572
reg: InlineAsmRegOrRegClass,
25732573
late: bool,
2574-
expr: Expr<'hir>,
2574+
expr: &'hir Expr<'hir>,
25752575
},
25762576
SplitInOut {
25772577
reg: InlineAsmRegOrRegClass,
25782578
late: bool,
2579-
in_expr: Expr<'hir>,
2580-
out_expr: Option<Expr<'hir>>,
2579+
in_expr: &'hir Expr<'hir>,
2580+
out_expr: Option<&'hir Expr<'hir>>,
25812581
},
25822582
Const {
25832583
anon_const: AnonConst,
@@ -3496,7 +3496,7 @@ mod size_asserts {
34963496
use super::*;
34973497
// These are in alphabetical order, which is easy to maintain.
34983498
static_assert_size!(Block<'_>, 48);
3499-
static_assert_size!(Body<'_>, 80);
3499+
static_assert_size!(Body<'_>, 32);
35003500
static_assert_size!(Expr<'_>, 56);
35013501
static_assert_size!(ExprKind<'_>, 40);
35023502
static_assert_size!(FnDecl<'_>, 40);

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ impl<'tcx> DumpVisitor<'tcx> {
974974
self.process_macro_use(trait_item.span);
975975
match trait_item.kind {
976976
hir::TraitItemKind::Const(ref ty, body) => {
977-
let body = body.map(|b| &self.tcx.hir().body(b).value);
977+
let body = body.map(|b| self.tcx.hir().body(b).value);
978978
let attrs = self.tcx.hir().attrs(trait_item.hir_id());
979979
self.process_assoc_const(
980980
trait_item.def_id,

src/tools/clippy/clippy_lints/src/loops/never_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
178178
InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => {
179179
never_loop_expr(expr, main_loop_id)
180180
},
181-
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id),
181+
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter().copied(), main_loop_id),
182182
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
183-
never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id)
183+
never_loop_expr_all(&mut once(*in_expr).chain(out_expr.iter().copied()), main_loop_id)
184184
},
185185
InlineAsmOperand::Const { .. }
186186
| InlineAsmOperand::SymFn { .. }

src/tools/clippy/clippy_lints/src/utils/author.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
595595
}
596596

597597
fn body(&self, body_id: &Binding<hir::BodyId>) {
598-
let expr = &self.cx.tcx.hir().body(body_id.value).value;
598+
let expr = self.cx.tcx.hir().body(body_id.value).value;
599599
bind!(self, expr);
600600
out!("let {expr} = &cx.tcx.hir().body({body_id}).value;");
601601
self.expr(expr);

src/tools/clippy/clippy_utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool
18041804
}
18051805
};
18061806

1807-
let mut expr = &func.value;
1807+
let mut expr = func.value;
18081808
loop {
18091809
match expr.kind {
18101810
#[rustfmt::skip]

0 commit comments

Comments
 (0)