From db35b685a77d3a50fef2d1f5acec0c25a55df403 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 26 Aug 2022 15:43:00 +1000 Subject: [PATCH] Use `&'hir Expr` everywhere. For consistency, and because it makes HIR measurement simpler and more accurate. --- compiler/rustc_ast_lowering/src/asm.rs | 10 +++++----- compiler/rustc_ast_lowering/src/item.rs | 6 +++++- compiler/rustc_hir/src/hir.rs | 14 +++++++------- compiler/rustc_save_analysis/src/dump_visitor.rs | 2 +- .../clippy/clippy_lints/src/loops/never_loop.rs | 4 ++-- src/tools/clippy/clippy_lints/src/utils/author.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 2 +- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 0dba9da63da2..b0e9fe0469c4 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -155,26 +155,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let op = match *op { InlineAsmOperand::In { reg, ref expr } => hir::InlineAsmOperand::In { reg: lower_reg(reg), - expr: self.lower_expr_mut(expr), + expr: self.lower_expr(expr), }, InlineAsmOperand::Out { reg, late, ref expr } => hir::InlineAsmOperand::Out { reg: lower_reg(reg), late, - expr: expr.as_ref().map(|expr| self.lower_expr_mut(expr)), + expr: expr.as_ref().map(|expr| self.lower_expr(expr)), }, InlineAsmOperand::InOut { reg, late, ref expr } => { hir::InlineAsmOperand::InOut { reg: lower_reg(reg), late, - expr: self.lower_expr_mut(expr), + expr: self.lower_expr(expr), } } InlineAsmOperand::SplitInOut { reg, late, ref in_expr, ref out_expr } => { hir::InlineAsmOperand::SplitInOut { reg: lower_reg(reg), late, - in_expr: self.lower_expr_mut(in_expr), - out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)), + in_expr: self.lower_expr(in_expr), + out_expr: out_expr.as_ref().map(|expr| self.lower_expr(expr)), } } InlineAsmOperand::Const { ref anon_const } => { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index fd338ffc0c5e..8e1ba064d64d 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -947,7 +947,11 @@ impl<'hir> LoweringContext<'_, 'hir> { params: &'hir [hir::Param<'hir>], value: hir::Expr<'hir>, ) -> hir::BodyId { - let body = hir::Body { generator_kind: self.generator_kind, params, value }; + let body = hir::Body { + generator_kind: self.generator_kind, + params, + value: self.arena.alloc(value), + }; let id = body.id(); debug_assert_eq!(id.hir_id.owner, self.current_hir_id_owner); self.bodies.push((id.hir_id.local_id, self.arena.alloc(body))); diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 6ef6e47a16a0..b4c60c4be68d 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1438,7 +1438,7 @@ pub struct BodyId { #[derive(Debug, HashStable_Generic)] pub struct Body<'hir> { pub params: &'hir [Param<'hir>], - pub value: Expr<'hir>, + pub value: &'hir Expr<'hir>, pub generator_kind: Option, } @@ -2561,23 +2561,23 @@ pub enum TyKind<'hir> { pub enum InlineAsmOperand<'hir> { In { reg: InlineAsmRegOrRegClass, - expr: Expr<'hir>, + expr: &'hir Expr<'hir>, }, Out { reg: InlineAsmRegOrRegClass, late: bool, - expr: Option>, + expr: Option<&'hir Expr<'hir>>, }, InOut { reg: InlineAsmRegOrRegClass, late: bool, - expr: Expr<'hir>, + expr: &'hir Expr<'hir>, }, SplitInOut { reg: InlineAsmRegOrRegClass, late: bool, - in_expr: Expr<'hir>, - out_expr: Option>, + in_expr: &'hir Expr<'hir>, + out_expr: Option<&'hir Expr<'hir>>, }, Const { anon_const: AnonConst, @@ -3496,7 +3496,7 @@ mod size_asserts { use super::*; // These are in alphabetical order, which is easy to maintain. static_assert_size!(Block<'_>, 48); - static_assert_size!(Body<'_>, 80); + static_assert_size!(Body<'_>, 32); static_assert_size!(Expr<'_>, 56); static_assert_size!(ExprKind<'_>, 40); static_assert_size!(FnDecl<'_>, 40); diff --git a/compiler/rustc_save_analysis/src/dump_visitor.rs b/compiler/rustc_save_analysis/src/dump_visitor.rs index e2e0e1f5b300..ce0d5cbc479b 100644 --- a/compiler/rustc_save_analysis/src/dump_visitor.rs +++ b/compiler/rustc_save_analysis/src/dump_visitor.rs @@ -974,7 +974,7 @@ impl<'tcx> DumpVisitor<'tcx> { self.process_macro_use(trait_item.span); match trait_item.kind { hir::TraitItemKind::Const(ref ty, body) => { - let body = body.map(|b| &self.tcx.hir().body(b).value); + let body = body.map(|b| self.tcx.hir().body(b).value); let attrs = self.tcx.hir().attrs(trait_item.hir_id()); self.process_assoc_const( trait_item.def_id, diff --git a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs index 32de20f6531f..5448360049d2 100644 --- a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs @@ -178,9 +178,9 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => { never_loop_expr(expr, main_loop_id) }, - InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id), + InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter().copied(), main_loop_id), InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { - never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id) + never_loop_expr_all(&mut once(*in_expr).chain(out_expr.iter().copied()), main_loop_id) }, InlineAsmOperand::Const { .. } | InlineAsmOperand::SymFn { .. } diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index 429c64ac1564..3ffcaa90af3e 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -595,7 +595,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { } fn body(&self, body_id: &Binding) { - let expr = &self.cx.tcx.hir().body(body_id.value).value; + let expr = self.cx.tcx.hir().body(body_id.value).value; bind!(self, expr); out!("let {expr} = &cx.tcx.hir().body({body_id}).value;"); self.expr(expr); diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index f716f009ff3f..dd1ceb6a4dc4 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1804,7 +1804,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool } }; - let mut expr = &func.value; + let mut expr = func.value; loop { match expr.kind { #[rustfmt::skip]