diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 9cea3519cf94e..babca94628891 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1216,7 +1216,7 @@ impl<'hir> LoweringContext<'_, 'hir> { params: &'hir [hir::Param<'hir>], value: hir::Expr<'hir>, ) -> hir::BodyId { - let body = hir::Body { params, value: self.arena.alloc(value) }; + let body = hir::Body { params, value }; let id = body.id(); assert_eq!(id.hir_id.owner, self.curr_owner.owner_id()); self.curr_owner.bodies.push((id.hir_id.local_id, self.arena.alloc(body))); diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2f8ff159ceb0a..bd8d69bceed97 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -408,7 +408,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { } let tcx = self.infcx.tcx; if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) { - let expr = body.value; + let expr = &body.value; let place = &self.move_data.move_paths[mpi].place; let span = place.as_local().map(|local| self.body.local_decls[local].source_info.span); let mut finder = ExpressionFinder { @@ -2134,7 +2134,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { let mut expr_finder = FindUselessClone::new(tcx, self.mir_def_id()); - let body = tcx.hir_body(body_id).value; + let body = &tcx.hir_body(body_id).value; expr_finder.visit_expr(body); struct Holds<'tcx> { @@ -2323,7 +2323,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { let tcx = self.infcx.tcx; let body_id = tcx.hir_node(self.mir_hir_id()).body_id()?; let mut expr_finder = FindExprBySpan::new(span, tcx); - expr_finder.visit_expr(tcx.hir_body(body_id).value); + expr_finder.visit_expr(&tcx.hir_body(body_id).value); expr_finder.result } @@ -2554,7 +2554,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { } } let mut finder = ExprFinder { tcx, expr_span: span, issue_span, .. }; - finder.visit_expr(tcx.hir_body(body_id).value); + finder.visit_expr(&tcx.hir_body(body_id).value); if let Some(body_expr) = finder.body_expr && let Some(loop_span) = finder.loop_span @@ -2705,7 +2705,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { // Get the body the error happens in let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return }; - let body_expr = tcx.hir_body(body_id).value; + let body_expr = &tcx.hir_body(body_id).value; struct ClosureFinder<'hir> { tcx: TyCtxt<'hir>, @@ -2809,7 +2809,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { } let mut finder = VariableUseFinder { local_id, spans: Vec::new() }; - finder.visit_expr(tcx.hir_body(closure.body).value); + finder.visit_expr(&tcx.hir_body(closure.body).value); spans = finder.spans; } else { @@ -4747,7 +4747,7 @@ fn find_for_loop_span<'hir>( } } let mut finder = ExprFinder { tcx, issue_span, result: None }; - finder.visit_expr(tcx.hir_body(body_id).value); + finder.visit_expr(&tcx.hir_body(body_id).value); finder.result } diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 2bc361968a761..706a60d84f402 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -73,7 +73,7 @@ impl<'tcx> BorrowExplanation<'tcx> { { let body = tcx.hir_body(body_id); let mut expr_finder = FindExprBySpan::new(span, tcx); - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); if let Some(mut expr) = expr_finder.result { while let hir::ExprKind::AddrOf(_, _, inner) | hir::ExprKind::Unary(hir::UnOp::Deref, inner) @@ -308,7 +308,7 @@ impl<'tcx> BorrowExplanation<'tcx> { && let hir_body = tcx.hir_body(body_id) && let mut expr_finder = (FindLetExpr { span: old, result: None, tcx }) && let Some((let_expr_span, let_expr_pat, let_expr_init)) = { - expr_finder.visit_expr(hir_body.value); + expr_finder.visit_expr(&hir_body.value); expr_finder.result } && !let_expr_span.contains(new) diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 4d65410455118..c78c91e9ce0be 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -339,7 +339,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { // Find the closure that captured the binding. let mut expr_finder = FindExprBySpan::new(args_span, tcx); expr_finder.include_closures = true; - expr_finder.visit_expr(tcx.hir_body(body_id).value); + expr_finder.visit_expr(&tcx.hir_body(body_id).value); let Some(closure_expr) = expr_finder.result else { return }; let ExprKind::Closure(closure) = closure_expr.kind else { return }; // We'll only suggest cloning the binding if it's a `move` closure. @@ -349,7 +349,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { let use_span = use_spans.var_or_use(); let mut expr_finder = FindExprBySpan::new(use_span, tcx); expr_finder.include_closures = true; - expr_finder.visit_expr(tcx.hir_body(body_id).value); + expr_finder.visit_expr(&tcx.hir_body(body_id).value); let Some(use_expr) = expr_finder.result else { return }; let parent = tcx.parent_hir_node(use_expr.hir_id); if let Node::Expr(expr) = parent diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index ceb7f38c2a416..bb9f44fbdbb24 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1957,7 +1957,7 @@ pub struct BodyId { #[derive(Debug, Clone, Copy, StableHash)] pub struct Body<'hir> { pub params: &'hir [Param<'hir>], - pub value: &'hir Expr<'hir>, + pub value: Expr<'hir>, } impl<'hir> Body<'hir> { @@ -5275,7 +5275,7 @@ mod size_asserts { use super::*; // tidy-alphabetical-start static_assert_size!(Block<'_>, 48); - static_assert_size!(Body<'_>, 24); + static_assert_size!(Body<'_>, 80); static_assert_size!(Expr<'_>, 64); static_assert_size!(ExprKind<'_>, 48); static_assert_size!(FnDecl<'_>, 40); diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index b404d1708b85b..5d02c895f9a8f 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -296,7 +296,7 @@ pub trait Visitor<'v>: Sized { walk_item(self, i) } - fn visit_body(&mut self, b: &Body<'v>) -> Self::Result { + fn visit_body(&mut self, b: &'v Body<'v>) -> Self::Result { walk_body(self, b) } @@ -662,10 +662,10 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V:: V::Result::output() } -pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &Body<'v>) -> V::Result { +pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) -> V::Result { let Body { params, value } = body; walk_list!(visitor, visit_param, *params); - visitor.visit_expr(*value) + visitor.visit_expr(value) } pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) -> V::Result { diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 96acfd2f97177..b4be6c3fd5d01 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -762,7 +762,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> { resolve_block(self, b, false); } - fn visit_body(&mut self, body: &hir::Body<'tcx>) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { let body_id = body.id(); let owner_id = self.tcx.hir_body_owner_def_id(body_id); @@ -783,7 +783,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> { } // The body of the every fn is a root scope. - resolve_expr(this, body.value, true); + resolve_expr(this, &body.value, true); } else { // All bodies have an outer temporary drop scope, but temporaries // and `super let` bindings in constant initializers may be extended @@ -808,7 +808,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> { local_id: body.value.hir_id.local_id, data: ScopeData::Destruction, }); - resolve_local(this, None, Some(body.value), LetKind::Regular); + resolve_local(this, None, Some(&body.value), LetKind::Regular); } }) } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index b81b7aafb8c1d..3583606672dab 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1705,7 +1705,7 @@ fn coroutine_for_closure(tcx: TyCtxt<'_>, def_id: LocalDefId) -> DefId { bug!() }; - let &hir::Expr { + let hir::Expr { kind: hir::ExprKind::Closure(&rustc_hir::Closure { def_id, diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index d8c57bfbdb56b..a697c919f1202 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -63,7 +63,7 @@ impl PpAnn for &dyn rustc_hir::intravisit::HirTyCtxt<'_> { Nested::TraitItem(id) => state.print_trait_item(self.hir_trait_item(id)), Nested::ImplItem(id) => state.print_impl_item(self.hir_impl_item(id)), Nested::ForeignItem(id) => state.print_foreign_item(self.hir_foreign_item(id)), - Nested::Body(id) => state.print_expr(self.hir_body(id).value), + Nested::Body(id) => state.print_expr(&self.hir_body(id).value), Nested::BodyParamPat(id, i) => state.print_pat(self.hir_body(id).params[i].pat), } } diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs index 8061e522f43aa..912c2b72a907a 100644 --- a/compiler/rustc_hir_typeck/src/check.rs +++ b/compiler/rustc_hir_typeck/src/check.rs @@ -127,7 +127,7 @@ pub(super) fn check_fn<'a, 'tcx>( } fcx.is_whole_body.set(true); - fcx.check_return_or_body_tail(body.value, false); + fcx.check_return_or_body_tail(&body.value, false); // Finalize the return check by taking the LUB of the return types // we saw and assigning it to the expected return type. This isn't diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index e1ad43f0c00c9..36e0a22c76133 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -333,7 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut expr_finder = FindExprs { hir_id: local_hir_id, uses: init.into_iter().collect() }; let body = self.tcx.hir_body_owned_by(self.body_def_id); - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); // Replaces all of the variables in the given type with a fresh inference variable. let mut fudger = BottomUpFolder { diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index a301cb6a397d9..098990e8da2bb 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1723,7 +1723,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let def_id = block.def_id; let fcx = FnCtxt::new(self, self.param_env, def_id); - let ty = fcx.check_expr_with_expectation(body.value, expected); + let ty = fcx.check_expr_with_expectation(&body.value, expected); fcx.require_type_is_sized(ty, body.value.span, ObligationCauseCode::SizedConstOrStatic); fcx.write_ty(block.hir_id, ty); ty @@ -3730,7 +3730,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let body = self.tcx.hir_body(anon_const.body); let fcx = FnCtxt::new(self, self.param_env, anon_const.def_id); - let ty = fcx.check_expr(body.value); + let ty = fcx.check_expr(&body.value); let target_ty = match self.structurally_resolve_type(body.value.span, ty).kind() { ty::FnDef(..) => { diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index 0c49ec002671d..3186533ad4b5f 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -316,7 +316,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx self.walk_pat(¶m_place, param.pat, false)?; } - self.consume_expr(body.value)?; + self.consume_expr(&body.value)?; Ok(()) } diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index 8dd38d2eaa407..6459948143fde 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -341,7 +341,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { let reachable_vids = graph::depth_first_search_as_undirected(coercions, vid).collect(); AnnotateUnitFallbackVisitor { reachable_vids, fcx: self } - .visit_expr(body.value) + .visit_expr(&body.value) .break_value() }) .collect(); diff --git a/compiler/rustc_hir_typeck/src/inline_asm.rs b/compiler/rustc_hir_typeck/src/inline_asm.rs index b3c7071199963..597107f94162d 100644 --- a/compiler/rustc_hir_typeck/src/inline_asm.rs +++ b/compiler/rustc_hir_typeck/src/inline_asm.rs @@ -584,7 +584,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { } } hir::InlineAsmOperand::Const { anon_const } => { - let ty = self.expr_ty(self.tcx().hir_body(anon_const.body).value); + let ty = self.expr_ty(&self.tcx().hir_body(anon_const.body).value); match ty.kind() { ty::Error(_) => {} _ if ty.is_integral() => {} diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 2945a6b3b5136..67a4c63da4f93 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -133,7 +133,7 @@ fn typeck_with_inspect<'tcx>( if let hir::Node::Item(hir::Item { kind: hir::ItemKind::GlobalAsm { .. }, .. }) = node { // Check the fake body of a global ASM. There's not much to do here except // for visit the asm expr of the body. - let ty = fcx.check_expr(body.value); + let ty = fcx.check_expr(&body.value); fcx.write_ty(id, ty); } else if let Some(hir::FnSig { header, decl, span: _ }) = node.fn_sig() { let fn_sig = if decl.output.is_suggestable_infer_ty().is_some() { @@ -204,7 +204,7 @@ fn typeck_with_inspect<'tcx>( ); } - fcx.check_expr_coercible_to_type_or_error(body.value, expected_type, None, |err, _| { + fcx.check_expr_coercible_to_type_or_error(&body.value, expected_type, None, |err, _| { extend_err_with_const_context(err, tcx, node, expected_type); }); diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 98155d9a8d5ef..9cde49aac0ffc 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -575,7 +575,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // for the inner coroutine may actually be more restrictive. if infer_kind { let ty::Coroutine(_, coroutine_args) = - *self.typeck_results.borrow().expr_ty(body.value).kind() + *self.typeck_results.borrow().expr_ty(&body.value).kind() else { bug!(); }; diff --git a/compiler/rustc_lint/src/async_closures.rs b/compiler/rustc_lint/src/async_closures.rs index 36ab33b44c0ff..d9733753a33e8 100644 --- a/compiler/rustc_lint/src/async_closures.rs +++ b/compiler/rustc_lint/src/async_closures.rs @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncClosureUsage { return; }; - let mut body = cx.tcx.hir_body(body).value; + let mut body = &cx.tcx.hir_body(body).value; // Only peel blocks that have no expressions. while let hir::ExprKind::Block(&hir::Block { stmts: [], expr: Some(tail), .. }, None) = diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 15c60c920ce37..87802a2afb53f 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -924,7 +924,7 @@ impl<'tcx> LateContext<'tcx> { hir::Node::Item(item) => match item.kind { // FIXME(mgca): figure out how to handle ConstArgKind::Path (or don't but add warning in docs here) hir::ItemKind::Const(.., hir::ConstItemRhs::Body(body_id)) - | hir::ItemKind::Static(.., body_id) => Some(self.tcx.hir_body(body_id).value), + | hir::ItemKind::Static(.., body_id) => Some(&self.tcx.hir_body(body_id).value), _ => None, }, _ => None, diff --git a/compiler/rustc_lint/src/for_loops_over_fallibles.rs b/compiler/rustc_lint/src/for_loops_over_fallibles.rs index bb0f2a2793ab8..71cab7125695a 100644 --- a/compiler/rustc_lint/src/for_loops_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loops_over_fallibles.rs @@ -165,7 +165,7 @@ fn suggest_question_mark<'tcx>( // Check that the function/closure/constant we are in has a `Result` type. // Otherwise suggesting using `?` may not be a good idea. { - let ty = cx.typeck_results().expr_ty(cx.tcx.hir_body(body_id).value); + let ty = cx.typeck_results().expr_ty(&cx.tcx.hir_body(body_id).value); let ty::Adt(ret_adt, ..) = ty.kind() else { return false }; if !cx.tcx.is_diagnostic_item(sym::Result, ret_adt.did()) { return false; diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 93ce4118c0ab7..c932a19eb33d9 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -122,7 +122,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas }); } - fn visit_body(&mut self, body: &hir::Body<'tcx>) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { lint_callback!(self, check_body, body); hir_visit::walk_body(self, body); lint_callback!(self, check_body_post, body); diff --git a/compiler/rustc_lint/src/passes.rs b/compiler/rustc_lint/src/passes.rs index 98ab44c37e26a..30a81f3c5f3ef 100644 --- a/compiler/rustc_lint/src/passes.rs +++ b/compiler/rustc_lint/src/passes.rs @@ -7,8 +7,8 @@ macro_rules! late_lint_methods { ($macro:path, $args:tt) => ( // `_post` methods are called *after* recursing into the node. $macro!($args, [ - fn check_body(a: &rustc_hir::Body<'tcx>); - fn check_body_post(a: &rustc_hir::Body<'tcx>); + fn check_body(a: &'tcx rustc_hir::Body<'tcx>); + fn check_body_post(a: &'tcx rustc_hir::Body<'tcx>); fn check_crate(); fn check_crate_post(); fn check_mod(a: &'tcx rustc_hir::Mod<'tcx>, b: rustc_span::def_id::LocalModId); diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 38dbf8d428a20..f9f4c52b79d3b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2839,7 +2839,7 @@ pub(crate) fn provide(providers: &mut Providers) { /// use a different method for pretty-printing. Ideally this function /// should only ever be used as a fallback. pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body<'_>, def_id: LocalDefId) -> String { - let value = body.value; + let value = &body.value; #[derive(PartialEq, Eq)] enum Classification { diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index ad1227bb51df0..9ee80e229ed71 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -53,7 +53,7 @@ pub(crate) fn thir_body<'tcx>( } } - let expr = cx.mirror_expr(body.value); + let expr = cx.mirror_expr(&body.value); Ok((tcx.alloc_steal_thir(cx.thir), expr)) } diff --git a/compiler/rustc_mir_transform/src/coverage/hir_info.rs b/compiler/rustc_mir_transform/src/coverage/hir_info.rs index d863aa4c4b80e..5bb102f8c3223 100644 --- a/compiler/rustc_mir_transform/src/coverage/hir_info.rs +++ b/compiler/rustc_mir_transform/src/coverage/hir_info.rs @@ -99,7 +99,10 @@ fn hash_mir_source<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &'tcx hir::Body<'tcx>) -> .as_u64() } -fn extract_hole_spans_from_hir<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &hir::Body<'tcx>) -> Vec { +fn extract_hole_spans_from_hir<'tcx>( + tcx: TyCtxt<'tcx>, + hir_body: &'tcx hir::Body<'tcx>, +) -> Vec { struct HolesVisitor<'tcx> { tcx: TyCtxt<'tcx>, hole_spans: Vec, @@ -156,7 +159,7 @@ fn extract_hole_spans_from_hir<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &hir::Body<'tc fn find_nodes_to_ignore<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, - hir_body: &hir::Body<'tcx>, + hir_body: &'tcx hir::Body<'tcx>, ) -> FxHashSet { /// Top-level visitor used by [`find_nodes_to_ignore`]. struct FindNodesToIgnoreVisitor<'tcx> { diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index d8524efb35bc2..9392469251848 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -272,7 +272,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_item(self, i) } - fn visit_body(&mut self, b: &hir::Body<'v>) { + fn visit_body(&mut self, b: &'v hir::Body<'v>) { self.record("Body", None, b); hir_visit::walk_body(self, b); } diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index e4cf2a40bd3fc..a2c2b5f82e6ef 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -522,7 +522,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if let Some(body) = self.tcx.hir_maybe_body_owned_by(self.tcx.typeck_root_def_id_local(body_def_id)) { - let expr = body.value; + let expr = &body.value; local_visitor.visit_expr(expr); body_from_expansion = body.value.span.from_expansion(); } @@ -1380,7 +1380,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> { /// For closures, we first visit the parameters and then the content, /// as we prefer those. - fn visit_body(&mut self, body: &Body<'tcx>) { + fn visit_body(&mut self, body: &'tcx Body<'tcx>) { for param in body.params { debug!( "param: span {:?}, ty_span {:?}, pat.span {:?}", diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 1614899ece03d..d1d999a477a65 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -4080,7 +4080,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } else if let ty::AliasConstKind::Anon { def_id } = alias_const.kind && let Some(local_def_id) = def_id.as_local() && let Some(local_body) = self.tcx.hir_maybe_body_owned_by(local_def_id) - && expr_needs_parens(local_body.value) + && expr_needs_parens(&local_body.value) { format!("[(); ({snippet}) as usize]:") } else { diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index a2aae724228ba..ce0c498c06ea6 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -1271,7 +1271,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { parenthesized_cast(span) } else if let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) { let mut expr_finder = FindExprBySpan::new(span, self.tcx); - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); if let Some(expr) = expr_finder.result && let hir::ExprKind::AddrOf(_, _, expr) = expr.kind { @@ -1311,7 +1311,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) else { return; }; - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); let Some(expr) = expr_finder.result else { return; }; @@ -1641,7 +1641,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { }; let mut expr_finder = FindExprBySpan::new(obligation.cause.span, self.tcx); - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); let Some(expr) = expr_finder.result else { return true; }; @@ -2018,7 +2018,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { return false; }; let mut expr_finder = FindExprBySpan::new(span, self.tcx); - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); if let Some(ty) = expr_finder.ty_result { if let hir::Node::Expr(expr) = self.tcx.parent_hir_node(ty.hir_id) @@ -2243,7 +2243,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) else { return false; }; - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); let mut maybe_suggest = |suggested_ty, count, suggestions| { // Remapping bound vars here let trait_pred_and_suggested_ty = @@ -2783,7 +2783,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { }; let body = self.tcx.hir_body(body_id); let mut expr_finder = FindExprBySpan::new(span, self.tcx); - expr_finder.visit_expr(body.value); + expr_finder.visit_expr(&body.value); let Some(expr) = expr_finder.result else { return; }; @@ -5215,7 +5215,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_def_id) && let Some(expr) = { let mut finder = FindExprBySpan::new(span, self.tcx); - finder.visit_expr(body.value); + finder.visit_expr(&body.value); finder.result } && let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, borrowed) = @@ -5659,7 +5659,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { { expr } else { - body.value + &body.value }; if let hir::ExprKind::MethodCall(path_segment, rcvr, [], span) = expr.kind && path_segment.ident.name == sym::clone @@ -6935,7 +6935,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> { } } - fn visit_body(&mut self, body: &hir::Body<'v>) { + fn visit_body(&mut self, body: &'v hir::Body<'v>) { assert!(!self.in_block_tail); self.in_block_tail = true; hir::intravisit::walk_body(self, body); diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 5415662154daf..96edc32145111 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -68,7 +68,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { let Some(body) = self.tcx.hir_maybe_body_owned_by(self.item) else { return; }; - let body = body.value; + let body = &body.value; struct TaitInBodyFinder<'a, 'tcx> { collector: &'a mut OpaqueTypeCollector<'tcx>, } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index df55626ffb05d..78b602e25dce8 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -720,7 +720,7 @@ impl<'tcx> Visitor<'tcx> for RustdocVisitor<'_, 'tcx> { // Unneeded. } - fn visit_body(&mut self, b: &hir::Body<'tcx>) { + fn visit_body(&mut self, b: &'tcx hir::Body<'tcx>) { let prev = mem::replace(&mut self.inside_body, true); walk_body(self, b); self.inside_body = prev; diff --git a/src/tools/clippy/clippy_lints/src/async_yields_async.rs b/src/tools/clippy/clippy_lints/src/async_yields_async.rs index c13818363640e..1d2fc60abf4c2 100644 --- a/src/tools/clippy/clippy_lints/src/async_yields_async.rs +++ b/src/tools/clippy/clippy_lints/src/async_yields_async.rs @@ -63,12 +63,12 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { // XXXkhuey maybe we should? return; }, - CoroutineSource::Block => cx.tcx.hir_body(*body_id).value, + CoroutineSource::Block => &cx.tcx.hir_body(*body_id).value, CoroutineSource::Closure => { // Like `async fn`, async closures are wrapped in an additional block // to move all of the closure's arguments into the future. - let async_closure_body = cx.tcx.hir_body(*body_id).value; + let async_closure_body = &cx.tcx.hir_body(*body_id).value; let ExprKind::Block(block, _) = async_closure_body.kind else { return; }; diff --git a/src/tools/clippy/clippy_lints/src/attrs/inline_always.rs b/src/tools/clippy/clippy_lints/src/attrs/inline_always.rs index fd03ec47da543..fc7a3b9b335e5 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/inline_always.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/inline_always.rs @@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Att } if let Some(span) = find_attr!(attrs, Inline(InlineAttr::Always, span) => *span) - && body.is_none_or(|body| is_relevant_expr(cx, cx.tcx.hir_body(body).value)) + && body.is_none_or(|body| is_relevant_expr(cx, &cx.tcx.hir_body(body).value)) { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/booleans.rs b/src/tools/clippy/clippy_lints/src/booleans.rs index b2c21377a0a3f..601085d1ac72b 100644 --- a/src/tools/clippy/clippy_lints/src/booleans.rs +++ b/src/tools/clippy/clippy_lints/src/booleans.rs @@ -459,7 +459,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: Msrv, expr: &Expr<'_>) -> Optio .map(|param| param.span.get_text(cx).map(|t| t.to_string())) .collect::>>()? .join(", "); - let negated = simplify_not(cx, curr_msrv, body.value)?; + let negated = simplify_not(cx, curr_msrv, &body.value)?; Some(format!("|{params}| {negated}")) }, ExprKind::Unary(UnOp::Not, expr) => expr.span.get_text(cx).map(|t| t.to_string()), diff --git a/src/tools/clippy/clippy_lints/src/casts/mod.rs b/src/tools/clippy/clippy_lints/src/casts/mod.rs index 35806284d3b31..59d3c4ed88f4f 100644 --- a/src/tools/clippy/clippy_lints/src/casts/mod.rs +++ b/src/tools/clippy/clippy_lints/src/casts/mod.rs @@ -953,7 +953,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts { ptr_cast_constness::check_null_ptr_cast_method(cx, expr); } - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) { needless_type_cast::check(cx, body); } } diff --git a/src/tools/clippy/clippy_lints/src/casts/needless_type_cast.rs b/src/tools/clippy/clippy_lints/src/casts/needless_type_cast.rs index 09f72b18d18f0..077a58037849a 100644 --- a/src/tools/clippy/clippy_lints/src/casts/needless_type_cast.rs +++ b/src/tools/clippy/clippy_lints/src/casts/needless_type_cast.rs @@ -24,10 +24,10 @@ struct UsageInfo<'a> { in_generic_context: bool, } -pub(super) fn check<'a>(cx: &LateContext<'a>, body: &Body<'a>) { +pub(super) fn check<'a>(cx: &LateContext<'a>, body: &'a Body<'a>) { let mut bindings: FxHashMap> = FxHashMap::default(); - for_each_expr_without_closures(body.value, |expr| { + for_each_expr_without_closures(&body.value, |expr| { match expr.kind { ExprKind::Block(block, _) => { for stmt in block.stmts { @@ -246,10 +246,10 @@ fn can_coerce_to_target_type(expr: &Expr<'_>) -> bool { } } -fn check_binding_usages<'a>(cx: &LateContext<'a>, body: &Body<'a>, hir_id: HirId, binding_info: &BindingInfo<'a>) { +fn check_binding_usages<'a>(cx: &LateContext<'a>, body: &'a Body<'a>, hir_id: HirId, binding_info: &BindingInfo<'a>) { let mut usages = Vec::new(); - for_each_expr(cx.tcx, body.value, |expr| { + for_each_expr(cx.tcx, &body.value, |expr| { if let ExprKind::Path(ref qpath) = expr.kind && !expr.span.from_expansion() && let Res::Local(id) = cx.qpath_res(qpath, expr.hir_id) diff --git a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs index a28e9d58f2caf..4a64995e69745 100644 --- a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs +++ b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs @@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity { }, } } else { - body.value + &body.value }; self.check(cx, kind, decl, expr, span); diff --git a/src/tools/clippy/clippy_lints/src/collection_is_never_read.rs b/src/tools/clippy/clippy_lints/src/collection_is_never_read.rs index 099100bf9d1f6..607ebbc246e7c 100644 --- a/src/tools/clippy/clippy_lints/src/collection_is_never_read.rs +++ b/src/tools/clippy/clippy_lints/src/collection_is_never_read.rs @@ -120,7 +120,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI // To keep things simple, we only check the first param to see if its read. && let Body { params: [param, ..], value } = cx.tcx.hir_body(closure.body) { - !has_no_read_access(cx, param.hir_id, *value) + !has_no_read_access(cx, param.hir_id, value) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs index 5bfe936880a85..af98312e011c8 100644 --- a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs +++ b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs @@ -50,7 +50,7 @@ declare_clippy_lint! { declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]); impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) { // NOTE: this is different from `clippy_utils::is_inside_always_const_context`. // Inline const supports type inference. let is_parent_const = matches!( diff --git a/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs b/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs index 5a69a5e0d2e84..a2b1f801d8b65 100644 --- a/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs +++ b/src/tools/clippy/clippy_lints/src/doc/missing_headers.rs @@ -74,7 +74,7 @@ pub fn check( && let Some(future) = cx.tcx.lang_items().future_trait() && let typeck = cx.tcx.typeck_body(body_id) && let body = cx.tcx.hir_body(body_id) - && let ret_ty = typeck.expr_ty(body.value) + && let ret_ty = typeck.expr_ty(&body.value) && implements_trait_with_env( cx.tcx, ty::TypingEnv::non_body_analysis(cx.tcx, owner_id.def_id), diff --git a/src/tools/clippy/clippy_lints/src/eta_reduction.rs b/src/tools/clippy/clippy_lints/src/eta_reduction.rs index e3674fcf0d0b6..98ce2e3cd1d7c 100644 --- a/src/tools/clippy/clippy_lints/src/eta_reduction.rs +++ b/src/tools/clippy/clippy_lints/src/eta_reduction.rs @@ -100,7 +100,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx if body.value.span.from_expansion() { if body.params.is_empty() - && let Some(VecArgs::Vec(&[])) = VecArgs::hir(cx, body.value) + && let Some(VecArgs::Vec(&[])) = VecArgs::hir(cx, &body.value) { let vec_crate = if is_no_std_crate(cx) { "alloc" } else { "std" }; // replace `|| vec![]` with `Vec::new` @@ -124,7 +124,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx return; } - if is_adjusted(cx, body.value) { + if is_adjusted(cx, &body.value) { return; } @@ -170,7 +170,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx _ => { if typeck.type_dependent_def_id(body.value.hir_id).is_some() && let subs = typeck.node_args(body.value.hir_id) - && let output = typeck.expr_ty(body.value) + && let output = typeck.expr_ty(&body.value) && let ty::Tuple(tys) = *subs.type_at(1).kind() { cx.tcx.mk_fn_sig_safe_rust_abi(tys, output) diff --git a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs index 99137c8591e47..095846ab5dfb5 100644 --- a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs +++ b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs @@ -105,7 +105,7 @@ fn lint_impl_body(cx: &LateContext<'_>, item_def_id: hir::OwnerId, impl_span: Sp typeck_results: cx.tcx.typeck(impl_item_def_id), result: Vec::new(), }; - fpu.visit_expr(body.value); + fpu.visit_expr(&body.value); // if we've found one, lint if !fpu.result.is_empty() { diff --git a/src/tools/clippy/clippy_lints/src/from_over_into.rs b/src/tools/clippy/clippy_lints/src/from_over_into.rs index ed936e7f14aec..fd7985e462eed 100644 --- a/src/tools/clippy/clippy_lints/src/from_over_into.rs +++ b/src/tools/clippy/clippy_lints/src/from_over_into.rs @@ -232,7 +232,7 @@ fn convert_to_from( lower: Vec::new(), }; - if finder.visit_expr(body.value).is_break() { + if finder.visit_expr(&body.value).is_break() { return None; } diff --git a/src/tools/clippy/clippy_lints/src/functions/must_use.rs b/src/tools/clippy/clippy_lints/src/functions/must_use.rs index 4cb798c67a7d2..12ad676581171 100644 --- a/src/tools/clippy/clippy_lints/src/functions/must_use.rs +++ b/src/tools/clippy/clippy_lints/src/functions/must_use.rs @@ -327,7 +327,7 @@ fn is_mutated_static(e: &hir::Expr<'_>) -> bool { } fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bool { - for_each_expr_without_closures(body.value, |e| { + for_each_expr_without_closures(&body.value, |e| { use hir::ExprKind::{AddrOf, Assign, AssignOp, Call, MethodCall}; match e.kind { diff --git a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 7555a6719b6de..42c4aba60c5af 100644 --- a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -50,7 +50,7 @@ fn check_raw_ptr<'tcx>( if !raw_ptrs.is_empty() { let typeck = cx.tcx.typeck_body(body.id()); - let _: Option = for_each_expr(cx.tcx, body.value, |e| { + let _: Option = for_each_expr(cx.tcx, &body.value, |e| { match e.kind { hir::ExprKind::Call(f, args) if is_unsafe_fn(cx, typeck.expr_ty(f)) => { for arg in args { diff --git a/src/tools/clippy/clippy_lints/src/functions/ref_option.rs b/src/tools/clippy/clippy_lints/src/functions/ref_option.rs index 733f10b3506f8..f6fa5ebcd5e3b 100644 --- a/src/tools/clippy/clippy_lints/src/functions/ref_option.rs +++ b/src/tools/clippy/clippy_lints/src/functions/ref_option.rs @@ -96,7 +96,7 @@ pub(crate) fn check_fn<'a>( }; // Figure out the signature of the closure - let ty::Closure(_, args) = cx.typeck_results().expr_ty(body.value).kind() else { + let ty::Closure(_, args) = cx.typeck_results().expr_ty(&body.value).kind() else { return; }; let sig = args.as_closure().sig().skip_binder(); diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs index ea443487df9ba..70f0fa0a3b478 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs @@ -312,7 +312,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> { impl<'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'_, '_, 'tcx> { type NestedFilter = nested_filter::OnlyBodies; - fn visit_body(&mut self, body: &Body<'tcx>) { + fn visit_body(&mut self, body: &'tcx Body<'tcx>) { let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id())); walk_body(self, body); self.maybe_typeck_results = old_maybe_typeck_results; diff --git a/src/tools/clippy/clippy_lints/src/implicit_return.rs b/src/tools/clippy/clippy_lints/src/implicit_return.rs index 633a3e9e42bd8..4867cbabcc4bc 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_return.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_return.rs @@ -234,7 +234,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn { return; } - let res_ty = cx.typeck_results().expr_ty(body.value); + let res_ty = cx.typeck_results().expr_ty(&body.value); if res_ty.is_unit() || res_ty.is_never() { return; } @@ -244,10 +244,10 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn { Some(e) => e, None => return, } - } else if let Some(expr) = get_async_closure_expr(cx.tcx, body.value) { + } else if let Some(expr) = get_async_closure_expr(cx.tcx, &body.value) { expr } else { - body.value + &body.value }; if is_from_proc_macro(cx, expr) { diff --git a/src/tools/clippy/clippy_lints/src/infinite_iter.rs b/src/tools/clippy/clippy_lints/src/infinite_iter.rs index e9b30ab93b9b9..aa75a16ae8cb8 100644 --- a/src/tools/clippy/clippy_lints/src/infinite_iter.rs +++ b/src/tools/clippy/clippy_lints/src/infinite_iter.rs @@ -161,7 +161,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness { && let ExprKind::Closure(&Closure { body, .. }) = args[0].kind { let body = cx.tcx.hir_body(body); - return is_infinite(cx, body.value); + return is_infinite(cx, &body.value); } Finite }, diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 408d78ae623c0..174139fbcbb66 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -345,7 +345,7 @@ fn could_use_elision<'tcx>( } let mut checker = BodyLifetimeChecker::new(cx); - if checker.visit_expr(body.value).is_break() { + if checker.visit_expr(&body.value).is_break() { return None; } } diff --git a/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs b/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs index 404ff33838b15..9745f4393e3e3 100644 --- a/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs @@ -49,7 +49,7 @@ pub(super) fn check<'tcx>( if let FnRetTy::DefaultReturn(ret_span) = parent_fn_ret && cx .enclosing_body - .is_some_and(|id| matches!(is_never_expr(cx, cx.tcx.hir_body(id).value), Some(RequiresSemi::No))) + .is_some_and(|id| matches!(is_never_expr(cx, &cx.tcx.hir_body(id).value), Some(RequiresSemi::No))) { diag.span_suggestion( ret_span, diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs index fb648050439b9..ee9f26b7961f8 100644 --- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs @@ -450,7 +450,7 @@ impl<'tcx> Visitor<'tcx> for VarVisitor<'_, 'tcx> { }, ExprKind::Closure(&Closure { body, .. }) => { let body = self.cx.tcx.hir_body(body); - self.visit_expr(body.value); + self.visit_expr(&body.value); }, _ => walk_expr(self, expr), } 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 43fa115f7e749..09dcff2c5c8e1 100644 --- a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs @@ -91,8 +91,8 @@ pub(super) fn check_iterator_reduction<'tcx>( recv: &'tcx Expr<'tcx>, closure: &'tcx Closure<'tcx>, ) { - let closure_body = cx.tcx.hir_body(closure.body).value; - let body_ty = cx.typeck_results().expr_ty(closure_body); + let closure_body = &cx.tcx.hir_body(closure.body).value; + let body_ty = cx.typeck_results().expr_ty(&closure_body); if body_ty.is_never() && !contains_return(closure_body) { span_lint_and_then( cx, diff --git a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs index 3d46991d1c224..0b136f60bceac 100644 --- a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs +++ b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs @@ -80,6 +80,6 @@ pub(super) fn check_method<'tcx>( } else { None }; - check(cx, recv, param.pat, ty_spans, body.value); + check(cx, recv, param.pat, ty_spans, &body.value); } } diff --git a/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs b/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs index 68b4865de4752..ff82e2f55812f 100644 --- a/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs +++ b/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs @@ -351,7 +351,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: & loop_id: loop_expr.hir_id, after_loop: false, }; - v.visit_expr(cx.tcx.hir_body(cx.enclosing_body.unwrap()).value) + v.visit_expr(&cx.tcx.hir_body(cx.enclosing_body.unwrap()).value) .is_break() } } diff --git a/src/tools/clippy/clippy_lints/src/macro_metavars_in_unsafe.rs b/src/tools/clippy/clippy_lints/src/macro_metavars_in_unsafe.rs index 82af5d67e6f23..462aff30f1d41 100644 --- a/src/tools/clippy/clippy_lints/src/macro_metavars_in_unsafe.rs +++ b/src/tools/clippy/clippy_lints/src/macro_metavars_in_unsafe.rs @@ -212,7 +212,7 @@ impl<'tcx> Visitor<'tcx> for BodyVisitor<'_, 'tcx> { } impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe { - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) { if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) { return; } diff --git a/src/tools/clippy/clippy_lints/src/manual_noop_waker.rs b/src/tools/clippy/clippy_lints/src/manual_noop_waker.rs index deedde8cdc302..4f38a32d1c8ac 100644 --- a/src/tools/clippy/clippy_lints/src/manual_noop_waker.rs +++ b/src/tools/clippy/clippy_lints/src/manual_noop_waker.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNoopWaker { if let ImplItemKind::Fn(_, body_id) = &impl_item.kind { let body = cx.tcx.hir_body(*body_id); - if !is_empty_block(body.value) { + if !is_empty_block(&body.value) { return; } } diff --git a/src/tools/clippy/clippy_lints/src/manual_option_as_slice.rs b/src/tools/clippy/clippy_lints/src/manual_option_as_slice.rs index c4a3ac96b1f89..ab3e4645f56f0 100644 --- a/src/tools/clippy/clippy_lints/src/manual_option_as_slice.rs +++ b/src/tools/clippy/clippy_lints/src/manual_option_as_slice.rs @@ -178,7 +178,7 @@ fn check_arms(cx: &LateContext<'_>, none_arm: &Arm<'_>, some_arm: &Arm<'_>) -> b fn returns_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { match expr.kind { ExprKind::Path(_) => expr.res(cx).is_diag_item(cx, sym::default_fn), - ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir_body(cl.body).value), + ExprKind::Closure(cl) => is_empty_slice(cx, &cx.tcx.hir_body(cl.body).value), _ => false, } } diff --git a/src/tools/clippy/clippy_lints/src/manual_pop_if.rs b/src/tools/clippy/clippy_lints/src/manual_pop_if.rs index afafe25f8ffd0..cdaef65d3c574 100644 --- a/src/tools/clippy/clippy_lints/src/manual_pop_if.rs +++ b/src/tools/clippy/clippy_lints/src/manual_pop_if.rs @@ -219,7 +219,7 @@ fn check_is_some_and_pattern<'tcx>( return Some(ManualPopIfPattern { kind, collection_expr, - predicate: body.value, + predicate: &body.value, param_name: ident.name, if_span: if_expr_span, spans: MultiSpan::from(vec![if_expr_span.with_hi(cond.span.hi()), pop_span]), @@ -370,7 +370,7 @@ fn check_map_unwrap_or_pattern<'tcx>( && kind.is_diag_item(cx, collection_expr) && let ExprKind::Closure(closure) = closure_arg.kind && let body = cx.tcx.hir_body(closure.body) - && cx.typeck_results().expr_ty(body.value).is_bool() + && cx.typeck_results().expr_ty(&body.value).is_bool() && let Some((pop_collection, pop_span, suggestable)) = check_pop_unwrap(cx, then_block, pop_method) && eq_expr_value(cx, if_expr_span.ctxt(), collection_expr, pop_collection) && let Some(param) = body.params.first() @@ -379,7 +379,7 @@ fn check_map_unwrap_or_pattern<'tcx>( return Some(ManualPopIfPattern { kind, collection_expr, - predicate: body.value, + predicate: &body.value, param_name: ident.name, if_span: if_expr_span, spans: MultiSpan::from(vec![if_expr_span.with_hi(cond.span.hi()), pop_span]), diff --git a/src/tools/clippy/clippy_lints/src/matches/manual_filter.rs b/src/tools/clippy/clippy_lints/src/matches/manual_filter.rs index 94a2910cef3b9..571bb095252ab 100644 --- a/src/tools/clippy/clippy_lints/src/matches/manual_filter.rs +++ b/src/tools/clippy/clippy_lints/src/matches/manual_filter.rs @@ -106,7 +106,7 @@ pub(crate) fn check_and_then_method<'tcx>( && let Some(fn_arg_span) = closure.fn_arg_span && let [param] = body.params && let expr_span_ctxt = expr.span.ctxt() - && let Some(some_expr) = get_cond_expr(cx, param.pat, body.value, expr_span_ctxt) + && let Some(some_expr) = get_cond_expr(cx, param.pat, &body.value, expr_span_ctxt) { span_lint_and_then( cx, diff --git a/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs b/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs index 2a15d732939c3..a997d3a93be66 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs @@ -227,7 +227,7 @@ impl<'tcx> Visitor<'tcx> for VarBindingVisitor<'_, 'tcx> { self.identifiers.remove(&ident.name); }); } - self.visit_expr(body.value)?; + self.visit_expr(&body.value)?; self.identifiers = before; ControlFlow::Continue(()) }, diff --git a/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs b/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs index d298bb1a11d9e..b5c730ee992d7 100644 --- a/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs @@ -166,7 +166,7 @@ impl BindInsteadOfMap { match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) => { let closure_body = cx.tcx.hir_body(body); - let closure_expr = peel_blocks(closure_body.value); + let closure_expr = peel_blocks(&closure_body.value); if self.lint_closure_autofixable(cx, expr, recv, closure_expr, fn_decl_span) { true diff --git a/src/tools/clippy/clippy_lints/src/methods/filter_map.rs b/src/tools/clippy/clippy_lints/src/methods/filter_map.rs index f42b73fce6bdc..29fc0180d5fb5 100644 --- a/src/tools/clippy/clippy_lints/src/methods/filter_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/filter_map.rs @@ -23,7 +23,7 @@ fn is_method(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol) -> bool ExprKind::MethodCall(segment, _, _, _) => segment.ident.name == method_name, ExprKind::Closure(Closure { body, .. }) => { let body = cx.tcx.hir_body(*body); - let closure_expr = peel_blocks(body.value); + let closure_expr = peel_blocks(&body.value); match closure_expr.kind { ExprKind::MethodCall(PathSegment { ident, .. }, receiver, ..) => { if ident.name == method_name @@ -189,7 +189,7 @@ impl<'tcx> OffendingFilterExpr<'tcx> { // ^^^^ ^^^^^^^ ^ ^^^^^^^^^^^^^^ // scrutinee variant_span variant_ident else_ let (scrutinee, else_, variant_ident, variant_span) = - match higher::IfLetOrMatch::parse(cx, map_body.value) { + match higher::IfLetOrMatch::parse(cx, &map_body.value) { // For `if let` we want to check that the variant matching arm references the local created by // its pattern Some(higher::IfLetOrMatch::IfLet(sc, pat, then, Some(else_), ..)) @@ -418,7 +418,7 @@ fn is_find_or_filter<'a>( } && let PatKind::Binding(_, filter_param_id, _, None) = filter_pat.kind - && let Some(offending_expr) = OffendingFilterExpr::hir(cx, filter_body.value, filter_param_id) + && let Some(offending_expr) = OffendingFilterExpr::hir(cx, &filter_body.value, filter_param_id) && let ExprKind::Closure(&Closure { body: map_body_id, .. }) = map_arg.kind && let map_body = cx.tcx.hir_body(map_body_id) diff --git a/src/tools/clippy/clippy_lints/src/methods/filter_map_bool_then.rs b/src/tools/clippy/clippy_lints/src/methods/filter_map_bool_then.rs index 00c7ca82d10dd..1c637dceca978 100644 --- a/src/tools/clippy/clippy_lints/src/methods/filter_map_bool_then.rs +++ b/src/tools/clippy/clippy_lints/src/methods/filter_map_bool_then.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: & if cx.ty_based_def(expr).opt_parent(cx).is_diag_item(cx, sym::Iterator) && let ExprKind::Closure(closure) = arg.kind && let body = cx.tcx.hir_body(closure.body) - && let value = peel_blocks(body.value) + && let value = peel_blocks(&body.value) // Indexing should be fine as `filter_map` always has 1 input, we unfortunately need both // `inputs` and `params` here as we need both the type and the span && let param_ty = closure.fn_decl.inputs[0] @@ -33,7 +33,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: & && is_copy(cx, param_ty) && let ExprKind::MethodCall(_, recv, [then_arg], _) = value.kind && let ExprKind::Closure(then_closure) = then_arg.kind - && let then_body = peel_blocks(cx.tcx.hir_body(then_closure.body).value) + && let then_body = peel_blocks(&cx.tcx.hir_body(then_closure.body).value) && let Some(def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id) && cx.tcx.is_diagnostic_item(sym::bool_then, def_id) && !expr.span.in_external_macro(cx.sess().source_map()) diff --git a/src/tools/clippy/clippy_lints/src/methods/format_collect.rs b/src/tools/clippy/clippy_lints/src/methods/format_collect.rs index 112906a7d01e1..a49f8f5c9f9c0 100644 --- a/src/tools/clippy/clippy_lints/src/methods/format_collect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/format_collect.rs @@ -21,7 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, map_arg: &Expr<'_>, m if cx.typeck_results().expr_ty(expr).is_lang_item(cx, LangItem::String) && let ExprKind::Closure(closure) = map_arg.kind && let body = cx.tcx.hir_body(closure.body) - && let Some(value) = peel_non_expn_blocks(body.value) + && let Some(value) = peel_non_expn_blocks(&body.value) && let Some(mac) = root_macro_call_first_node(cx, value) && is_format_macro(cx, mac.def_id) { diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_filter.rs b/src/tools/clippy/clippy_lints/src/methods/iter_filter.rs index 1f5b48a6f78f2..8743fd50d386e 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_filter.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_filter.rs @@ -96,7 +96,7 @@ fn is_method( }, ExprKind::Closure(&hir::Closure { body, .. }) => { let body = cx.tcx.hir_body(body); - let closure_expr = peel_blocks(body.value); + let closure_expr = peel_blocks(&body.value); let params = body.params.iter().map(|param| param.pat).collect::>(); is_method(cx, closure_expr, type_symbol, method_name, params.as_slice()) }, diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs b/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs index 241791e57c8e6..e21004f87a264 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -67,7 +67,7 @@ pub(super) fn check<'tcx>( return; }; - if param_captured_by_move_block(cx, body.value, p) { + if param_captured_by_move_block(cx, &body.value, p) { return; } diff --git a/src/tools/clippy/clippy_lints/src/methods/lines_filter_map_ok.rs b/src/tools/clippy/clippy_lints/src/methods/lines_filter_map_ok.rs index 607979719f894..770097b91378c 100644 --- a/src/tools/clippy/clippy_lints/src/methods/lines_filter_map_ok.rs +++ b/src/tools/clippy/clippy_lints/src/methods/lines_filter_map_ok.rs @@ -49,7 +49,7 @@ pub(super) fn check_filter_or_flat_map( { method.ident.name == sym::ok && receiver.res_local_id() == Some(param.pat.hir_id) - && cx.ty_based_def(*value).is_diag_item(cx, sym::result_ok_method) + && cx.ty_based_def(value).is_diag_item(cx, sym::result_ok_method) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs b/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs index aff6477c32547..f324e5437232e 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_inspect.rs @@ -47,7 +47,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name: let can_lint = for_each_expr_without_closures(block.stmts, |e| { if let ExprKind::Closure(c) = e.kind { // Nested closures don't need to treat returns specially. - let _: Option = for_each_expr(cx.tcx, cx.tcx.hir_body(c.body).value, |e| { + let _: Option = for_each_expr(cx.tcx, &cx.tcx.hir_body(c.body).value, |e| { if e.res_local_id() == Some(arg_id) { let (kind, same_ctxt) = check_use(cx, ctxt, e); match (kind, same_ctxt && e.span.ctxt() == ctxt) { diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_is_variant_and.rs b/src/tools/clippy/clippy_lints/src/methods/manual_is_variant_and.rs index bd2b1ba299185..26d1188faff43 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_is_variant_and.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_is_variant_and.rs @@ -149,7 +149,7 @@ impl<'hir> MapFunc<'hir> { fn sugg(self, cx: &LateContext<'hir>, invert: bool, app: &mut Applicability) -> String { match self { Self::Closure(closure) => { - let body = Sugg::hir_with_applicability(cx, cx.tcx.hir_body(closure.body).value, "..", app); + let body = Sugg::hir_with_applicability(cx, &cx.tcx.hir_body(closure.body).value, "..", app); format!( "{} {}", snippet_with_applicability(cx, closure.fn_decl_span, "|..|", app), diff --git a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs index 072f56b897014..c91f81a80c429 100644 --- a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs +++ b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs @@ -49,7 +49,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ match arg.kind { hir::ExprKind::Closure(&hir::Closure { body, .. }) => { let closure_body = cx.tcx.hir_body(body); - let closure_expr = peel_blocks(closure_body.value); + let closure_expr = peel_blocks(&closure_body.value); match closure_body.params[0].pat.kind { hir::PatKind::Ref(inner, Pinnedness::Not, Mutability::Not) => { if let hir::PatKind::Binding(hir::BindingMode::NONE, .., name, None) = inner.kind diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index f4b8c08321da9..1edf3bd2a7199 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -5487,7 +5487,7 @@ impl Methods { && let body = cx.tcx.hir_body(arg.body) && let [param] = body.params => { - string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), self.msrv); + string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(&body.value), self.msrv); }, Some((sym::map, _, [map_arg], _, map_call_span)) => { map_all_any_identity::check(cx, expr, recv, map_call_span, map_arg, call_span, arg, "any"); diff --git a/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs b/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs index aac4a344f5f99..6ad961ec9dbd1 100644 --- a/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs +++ b/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs @@ -108,7 +108,7 @@ pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, while let ExprKind::MethodCall(_, new_recv, _, _) = recv.kind { recv = new_recv; } - let body_expr = peel_blocks(body.value); + let body_expr = peel_blocks(&body.value); handle_expr( cx, diff --git a/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs b/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs index 31f294ff27d37..c26e3c0052ae9 100644 --- a/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs +++ b/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs @@ -47,7 +47,7 @@ pub(super) fn check( }), hir::ExprKind::Closure(&hir::Closure { body, .. }) => { let closure_body = cx.tcx.hir_body(body); - let closure_expr = peel_blocks(closure_body.value); + let closure_expr = peel_blocks(&closure_body.value); match &closure_expr.kind { hir::ExprKind::MethodCall(_, receiver, [], _) => { diff --git a/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs b/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs index aa1ef9a37374a..b155412057104 100644 --- a/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs +++ b/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs @@ -61,7 +61,7 @@ pub(super) fn check<'tcx>( if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) = map_arg.kind && let arg_snippet = snippet(cx, fn_decl_span, "..") && let body = cx.tcx.hir_body(body) - && let Some((func, [arg_char])) = reduce_unit_expression(body.value) + && let Some((func, [arg_char])) = reduce_unit_expression(&body.value) && let Some(id) = func.res(cx).opt_def_id().map(|ctor_id| cx.tcx.parent(ctor_id)) && Some(id) == cx.tcx.lang_items().option_some_variant() { diff --git a/src/tools/clippy/clippy_lints/src/methods/result_map_or_else_none.rs b/src/tools/clippy/clippy_lints/src/methods/result_map_or_else_none.rs index 4f496de99bb1e..15752016e5b82 100644 --- a/src/tools/clippy/clippy_lints/src/methods/result_map_or_else_none.rs +++ b/src/tools/clippy/clippy_lints/src/methods/result_map_or_else_none.rs @@ -25,7 +25,7 @@ pub(super) fn check<'tcx>( && let hir::ExprKind::Closure(&hir::Closure { body, .. }) = def_arg.kind && let body = cx.tcx.hir_body(body) // And finally we check that we return a `None` in the "else case". - && is_none_expr(cx, peel_blocks(body.value)) + && is_none_expr(cx, peel_blocks(&body.value)) { let msg = "called `map_or_else(|_| None, Some)` on a `Result` value"; let self_snippet = snippet(cx, recv.span, ".."); diff --git a/src/tools/clippy/clippy_lints/src/methods/return_and_then.rs b/src/tools/clippy/clippy_lints/src/methods/return_and_then.rs index 404ad551919f5..e08115940999c 100644 --- a/src/tools/clippy/clippy_lints/src/methods/return_and_then.rs +++ b/src/tools/clippy/clippy_lints/src/methods/return_and_then.rs @@ -44,7 +44,7 @@ pub(super) fn check<'tcx>( }; let closure_arg = fn_decl.inputs[0]; - let closure_expr = peel_blocks(cx.tcx.hir_body(body).value); + let closure_expr = peel_blocks(&cx.tcx.hir_body(body).value); let mut applicability = Applicability::MachineApplicable; let arg_snip = snippet_with_applicability(cx, closure_arg.span, "_", &mut applicability); diff --git a/src/tools/clippy/clippy_lints/src/methods/suspicious_map.rs b/src/tools/clippy/clippy_lints/src/methods/suspicious_map.rs index 35cd23c49ecef..26cf5d6017d5a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/suspicious_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/suspicious_map.rs @@ -15,9 +15,9 @@ pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr< .is_diag_item(cx, sym::Iterator) && let hir::ExprKind::Closure(closure) = expr_or_init(cx, map_arg).kind && let closure_body = cx.tcx.hir_body(closure.body) - && !cx.typeck_results().expr_ty(closure_body.value).is_unit() + && !cx.typeck_results().expr_ty(&closure_body.value).is_unit() { - if let Some(map_mutated_vars) = mutated_variables(closure_body.value, cx) + if let Some(map_mutated_vars) = mutated_variables(&closure_body.value, cx) // A variable is used mutably inside of the closure. Suppress the lint. && !map_mutated_vars.is_empty() { diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs index 31f21492dfedd..e70d825f75bbc 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -27,12 +27,12 @@ pub(super) fn check<'tcx>( if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind { let body = cx.tcx.hir_body(body); let arg_id = body.params[0].pat.hir_id; - let mutates_arg = mutated_variables(body.value, cx).is_none_or(|used_mutably| used_mutably.contains(&arg_id)); - let (clone_or_copy_needed, _) = clone_or_copy_needed(cx, body.params[0].pat, body.value); + let mutates_arg = mutated_variables(&body.value, cx).is_none_or(|used_mutably| used_mutably.contains(&arg_id)); + let (clone_or_copy_needed, _) = clone_or_copy_needed(cx, body.params[0].pat, &body.value); - let (mut found_mapping, mut found_filtering) = check_expression(cx, arg_id, body.value); + let (mut found_mapping, mut found_filtering) = check_expression(cx, arg_id, &body.value); - let _: Option = for_each_expr_without_closures(body.value, |e| { + let _: Option = for_each_expr_without_closures(&body.value, |e| { if let hir::ExprKind::Ret(Some(e)) = &e.kind { let (found_mapping_res, found_filtering_res) = check_expression(cx, arg_id, e); found_mapping |= found_mapping_res; @@ -46,7 +46,7 @@ pub(super) fn check<'tcx>( let sugg = if !found_filtering { // Check if the closure is .filter_map(|x| Some(x)) if kind.is_filter_map() - && let Some(arg) = as_some_expr(cx, body.value) + && let Some(arg) = as_some_expr(cx, &body.value) && let hir::ExprKind::Path(_) = arg.kind { span_lint( @@ -62,7 +62,7 @@ pub(super) fn check<'tcx>( Kind::FindMap => "map(..).next()", } } else if !found_mapping && !mutates_arg && (!clone_or_copy_needed || is_copy(cx, in_ty)) { - let ty = cx.typeck_results().expr_ty(body.value); + let ty = cx.typeck_results().expr_ty(&body.value); if option_arg_ty(cx, ty).is_some_and(|t| t == in_ty) { match kind { Kind::FilterMap => "filter(..)", diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs index c7207bb4dd4bc..914388129914c 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs @@ -126,7 +126,7 @@ fn check_fold_with_op( if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = acc.kind // Extract the body of the closure passed to fold && let closure_body = cx.tcx.hir_body(body) - && let closure_expr = peel_blocks(closure_body.value) + && let closure_expr = peel_blocks(&closure_body.value) // Check if the closure body is of the form `acc some_expr(x)` && let hir::ExprKind::Binary(ref bin_op, left_expr, right_expr) = closure_expr.kind @@ -353,7 +353,7 @@ fn check_option_fold<'tcx>( let mut acc_uses: Vec = Vec::new(); let mut acc_uses_ok = true; if let Some(acc_id) = acc_id { - for_each_expr(cx.tcx, closure_body.value, |sub_expr| { + for_each_expr(cx.tcx, &closure_body.value, |sub_expr| { if sub_expr.res_local_id() == Some(acc_id) { if sub_expr.span.ctxt() == ctxt { acc_uses.push(sub_expr.span); diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_map_or.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_map_or.rs index dff23e1cce061..79c76ad747657 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_map_or.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_map_or.rs @@ -54,7 +54,7 @@ fn closure_bool_constant(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option let [_] = body.params else { return None; }; - bool_constant(cx, body.value) + bool_constant(cx, &body.value) } /// Checks whether a `Result::{map_or, map_or_else}` call is a variant query. diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs index 48333cd2d85f3..852c6f1414b29 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -256,7 +256,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) -> Option< && let ExprKind::MethodCall(method_path, left_expr, [right_expr], _) = closure_body.value.kind && method_path.ident.name == sym::cmp && let Some(ord_trait) = cx.tcx.get_diagnostic_item(sym::Ord) - && cx.ty_based_def(closure_body.value).opt_parent(cx).opt_def_id() == Some(ord_trait) + && cx.ty_based_def(&closure_body.value).opt_parent(cx).opt_def_id() == Some(ord_trait) { let (closure_body, closure_arg, reverse) = if mirrored_exprs(left_expr, right_expr, &binding_map, BindingSource::Left) { diff --git a/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs b/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs index 057bb3a3a538d..70ff2dcccd348 100644 --- a/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs +++ b/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs @@ -152,7 +152,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { && let [param] = closure_body.params && let hir::PatKind::Binding(_, local_id, ..) = strip_pat_refs(param.pat).kind => { - let closure_expr = peel_blocks(closure_body.value); + let closure_expr = peel_blocks(&closure_body.value); match closure_expr.kind { hir::ExprKind::MethodCall(method, obj, [], _) => { if method.ident.name == sym::clone diff --git a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs index bb615ff4ef110..c2e62f1128653 100644 --- a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs @@ -436,7 +436,7 @@ impl LateLintPass<'_> for MissingAssertsForIndexing { fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) { let mut map = UnindexMap::default(); - for_each_expr_without_closures(body.value, |expr| { + for_each_expr_without_closures(&body.value, |expr| { check_index(cx, expr, &mut map); check_assert(cx, expr, &mut map); ControlFlow::::Continue(()) diff --git a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 19c3abd2576f6..4967d2aefd53b 100644 --- a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -276,7 +276,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeExprCollector<'tcx> { walk_expr(self, expr); } - fn visit_body(&mut self, body: &hir::Body<'tcx>) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { let saved_typeck_results = self.typeck_results; self.typeck_results = self.tcx.typeck_body(body.id()); walk_body(self, body); diff --git a/src/tools/clippy/clippy_lints/src/needless_for_each.rs b/src/tools/clippy/clippy_lints/src/needless_for_each.rs index 13a3c99274d5f..ff61edbd26ce7 100644 --- a/src/tools/clippy/clippy_lints/src/needless_for_each.rs +++ b/src/tools/clippy/clippy_lints/src/needless_for_each.rs @@ -101,7 +101,7 @@ fn check_expr(cx: &LateContext<'_>, expr: &Expr<'_>, outer_span: Span) { } let mut ret_collector = RetCollector::default(); - ret_collector.visit_expr(body.value); + ret_collector.visit_expr(&body.value); // Skip the lint if `return` is used in `Loop` in order not to suggest using `'label`. if ret_collector.ret_in_loop { diff --git a/src/tools/clippy/clippy_lints/src/non_canonical_impls.rs b/src/tools/clippy/clippy_lints/src/non_canonical_impls.rs index 32cf04908911f..1509400d6c97c 100644 --- a/src/tools/clippy/clippy_lints/src/non_canonical_impls.rs +++ b/src/tools/clippy/clippy_lints/src/non_canonical_impls.rs @@ -187,7 +187,7 @@ impl LateLintPass<'_> for NonCanonicalImpls { && implements_trait(cx, trait_impl.self_ty(), copy_trait, &[]) { for (assoc, body, _) in assoc_fns { - check_clone_on_copy(cx, assoc, body.value); + check_clone_on_copy(cx, assoc, &body.value); } } }, diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index a9d747e2757f7..8abefc0df0034 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -964,9 +964,9 @@ fn get_const_hir_value<'tcx>( _ => return None, }; match ct_rhs { - ConstItemRhs::Body(body_id) => Some((tcx.typeck(did), tcx.hir_body(body_id).value)), + ConstItemRhs::Body(body_id) => Some((tcx.typeck(did), &tcx.hir_body(body_id).value)), ConstItemRhs::Direct(ct_arg) => match ct_arg.kind { - ConstArgKind::Anon(anon_const) => Some((tcx.typeck(did), tcx.hir_body(anon_const.body).value)), + ConstArgKind::Anon(anon_const) => Some((tcx.typeck(did), &tcx.hir_body(anon_const.body).value)), _ => None, }, } diff --git a/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs b/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs index 185acc53fa52d..144a0ac7a63eb 100644 --- a/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs +++ b/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs @@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn { fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir::Body<'tcx>) { let mut panics = Vec::new(); - let _: Option = for_each_expr(cx.tcx, body.value, |e| { + let _: Option = for_each_expr(cx.tcx, &body.value, |e| { let Some(macro_call) = root_macro_call_first_node(cx, e) else { return ControlFlow::Continue(Descend::Yes); }; diff --git a/src/tools/clippy/clippy_lints/src/ptr/mod.rs b/src/tools/clippy/clippy_lints/src/ptr/mod.rs index 04393dcf60d58..ce55c3f89514a 100644 --- a/src/tools/clippy/clippy_lints/src/ptr/mod.rs +++ b/src/tools/clippy/clippy_lints/src/ptr/mod.rs @@ -149,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } } - fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) { let mut parents = cx.tcx.hir_parent_iter(body.value.hir_id); let (item_id, sig, is_trait_item) = match parents.next() { Some((_, Node::Item(i))) => { diff --git a/src/tools/clippy/clippy_lints/src/ptr/mut_from_ref.rs b/src/tools/clippy/clippy_lints/src/ptr/mut_from_ref.rs index bc0fac8684cf1..ad44efd120fe5 100644 --- a/src/tools/clippy/clippy_lints/src/ptr/mut_from_ref.rs +++ b/src/tools/clippy/clippy_lints/src/ptr/mut_from_ref.rs @@ -7,7 +7,7 @@ use rustc_hir::{self as hir, Body, FnRetTy, FnSig, GenericArg, Lifetime, Mutabil use rustc_lint::LateContext; use rustc_span::Span; -pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&Body<'tcx>>) { +pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'tcx>>) { let FnRetTy::Return(ty) = sig.decl.output else { return }; for (out, mutability, out_span) in get_lifetimes(ty) { if mutability != Some(Mutability::Mut) { @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option< .collect(); if let Some(args_immut_refs) = args_immut_refs && !args_immut_refs.is_empty() - && body.is_none_or(|body| sig.header.is_unsafe() || contains_unsafe_block(cx, body.value)) + && body.is_none_or(|body| sig.header.is_unsafe() || contains_unsafe_block(cx, &body.value)) { span_lint_and_then( cx, diff --git a/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs b/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs index b5fcc10f613ee..c78ff74744b7d 100644 --- a/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs +++ b/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs @@ -24,7 +24,7 @@ use std::{fmt, iter}; pub(super) fn check_body<'tcx>( cx: &LateContext<'tcx>, - body: &Body<'tcx>, + body: &'tcx Body<'tcx>, item_id: OwnerId, sig: &FnSig<'tcx>, is_trait_item: bool, @@ -306,7 +306,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( } #[expect(clippy::too_many_lines)] -fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[PtrArg<'tcx>]) -> Vec { +fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>, args: &[PtrArg<'tcx>]) -> Vec { struct V<'cx, 'tcx> { cx: &'cx LateContext<'tcx>, /// Map from a local id to which argument it came from (index into `Self::args` and @@ -449,7 +449,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[ results, skip_count, }; - v.visit_expr(body.value); + v.visit_expr(&body.value); v.results } diff --git a/src/tools/clippy/clippy_lints/src/redundant_async_block.rs b/src/tools/clippy/clippy_lints/src/redundant_async_block.rs index d696296301893..e2076d1731261 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_async_block.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_async_block.rs @@ -89,7 +89,7 @@ fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Op .all(|place| matches!(place.info.capture_kind, UpvarCapture::ByValue)) }) }) - .then_some(body.value) + .then_some(&body.value) } else { None } diff --git a/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs b/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs index 25c137dec7375..2cb17fcd586b5 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_closure_call.rs @@ -94,29 +94,29 @@ fn find_innermost_closure<'tcx>( while let ExprKind::Closure(closure) = expr.kind && let body = cx.tcx.hir_body(closure.body) - && !contains_early_return(body.value) + && !contains_early_return(&body.value) && steps > 0 { - let mut unwrapped_body_value = body.value; + let mut unwrapped_body_value = &body.value; let mut asyncness = ty::Asyncness::No; let mut capture_clause = closure.capture_clause; if let ExprKind::Closure(inner_closure) = body.value.kind { if matches!(inner_closure.kind, DESUGARED_ASYNC_CLOSURE_KIND) { asyncness = ty::Asyncness::Yes; - unwrapped_body_value = cx.tcx.hir_body(inner_closure.body).value; + unwrapped_body_value = &cx.tcx.hir_body(inner_closure.body).value; } else if matches!(inner_closure.kind, DESUGARED_ASYNC_BLOCK_CLOSURE_KIND) { asyncness = ty::Asyncness::Yes; capture_clause = inner_closure.capture_clause; - unwrapped_body_value = cx.tcx.hir_body(inner_closure.body).value; + unwrapped_body_value = &cx.tcx.hir_body(inner_closure.body).value; } - if contains_early_return(unwrapped_body_value) { + if contains_early_return(&unwrapped_body_value) { break; } } - expr = body.value; + expr = &body.value; data = Some(( unwrapped_body_value, closure.fn_decl, @@ -201,7 +201,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall { if let ExprKind::Closure(closure) = body.kind { // Like `async fn`, async closures are wrapped in an additional block // to move all of the closure's arguments into the future. - body = cx.tcx.hir_body(closure.body).value; + body = &cx.tcx.hir_body(closure.body).value; } // `async x` is a syntax error, so it becomes `async { x }` diff --git a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs index 64a136d96a610..e3df1934e5ad1 100644 --- a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs +++ b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs @@ -70,7 +70,7 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'tcx>, kind: FnKind<'tcx>, body: & } else { RetReplacement::Empty }; - check_final_expr(cx, body.value, vec![], replacement, None); + check_final_expr(cx, &body.value, vec![], replacement, None); }, FnKind::ItemFn(..) | FnKind::Method(..) => { check_block_return(cx, &body.value.kind, sp, vec![]); diff --git a/src/tools/clippy/clippy_lints/src/returns/needless_return_with_question_mark.rs b/src/tools/clippy/clippy_lints/src/returns/needless_return_with_question_mark.rs index d0ac03766b670..86683860cbb47 100644 --- a/src/tools/clippy/clippy_lints/src/returns/needless_return_with_question_mark.rs +++ b/src/tools/clippy/clippy_lints/src/returns/needless_return_with_question_mark.rs @@ -22,7 +22,7 @@ pub(super) fn check_stmt<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { && maybe_constr.res(cx).ctor_parent(cx).is_lang_item(cx, ResultErr) // Ensure this is not the final stmt, otherwise removing it would cause a compile error - && let block = cx.tcx.hir_body_owned_by(cx.tcx.hir_enclosing_body_owner(expr.hir_id)).value + && let block = &cx.tcx.hir_body_owned_by(cx.tcx.hir_enclosing_body_owner(expr.hir_id)).value && let ExprKind::Block(block, _) = peel_async_body(block).kind && !is_inside_let_else(cx.tcx, expr) && let [.., final_stmt] = block.stmts diff --git a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs index 064c78d9d1eec..5e48b67fdb4db 100644 --- a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs +++ b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> { _: hir::def_id::LocalDefId, ) { self.apas.clear(); - let initial_dummy_stmt = dummy_stmt_expr(body.value); + let initial_dummy_stmt = dummy_stmt_expr(&body.value); let mut ap = AuxParams::new(&mut self.apas, &initial_dummy_stmt); StmtsChecker::new(&mut ap, cx, &mut self.type_cache).visit_body(body); for apa in ap.apas.values() { diff --git a/src/tools/clippy/clippy_lints/src/single_option_map.rs b/src/tools/clippy/clippy_lints/src/single_option_map.rs index 3ecb389fec896..66b62de82e2cd 100644 --- a/src/tools/clippy/clippy_lints/src/single_option_map.rs +++ b/src/tools/clippy/clippy_lints/src/single_option_map.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for SingleOptionMap { if let FnRetTy::Return(_ret) = decl.output && matches!(kind, FnKind::ItemFn(_, _, _) | FnKind::Method(_, _)) { - let func_body = peel_blocks(body.value); + let func_body = peel_blocks(&body.value); if let ExprKind::MethodCall(method_name, callee, args, _span) = func_body.kind && method_name.ident.name == sym::map && let callee_type = cx.typeck_results().expr_ty(callee) diff --git a/src/tools/clippy/clippy_lints/src/string_patterns.rs b/src/tools/clippy/clippy_lints/src/string_patterns.rs index 5f29ea35beaf1..74c416ee3f21b 100644 --- a/src/tools/clippy/clippy_lints/src/string_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/string_patterns.rs @@ -146,7 +146,7 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr< // We want to retrieve all the comparisons done. // They are ordered in a nested way and so we need to traverse the AST to collect them all. - if for_each_expr(cx.tcx, body.value, |sub_expr| -> ControlFlow<(), Descend> { + if for_each_expr(cx.tcx, &body.value, |sub_expr| -> ControlFlow<(), Descend> { match sub_expr.kind { ExprKind::Binary(op, left, right) if op.node == BinOpKind::Eq => { if left.res_local_id() == Some(binding) diff --git a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs index 0ba88b8ae9048..e248d287987b6 100644 --- a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs +++ b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs @@ -92,7 +92,7 @@ fn check_expr_inner<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, bin ] .iter() .find(|&(ts, _)| ts.iter().any(|&t| Some(trait_id) == cx.tcx.lang_items().get(t))) - && count_binops(body.value) == 1 + && count_binops(&body.value) == 1 { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs b/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs index 55089fbf1bcac..d9b593e2fa43e 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs @@ -67,7 +67,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t // `std::mem::transmute(const { u64::MIN as *const u64 });` if let ExprKind::ConstBlock(ConstBlock { body, .. }) = arg.kind { // Strip out the const and run again - let block = cx.tcx.hir_body(body).value; + let block = &cx.tcx.hir_body(body).value; return check(cx, expr, block, to_ty); } diff --git a/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs b/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs index 94fcfef353db3..3af5bab642fb4 100644 --- a/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs +++ b/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs @@ -286,7 +286,7 @@ fn find_binding_use_scope<'tcx>( Some((_, Node::ImplItem(i))) if let ImplItemKind::Fn(_, body) = i.kind => body, _ => break None, }; - break Some(BindingUseRange::Param(tcx.hir_body(body).value)); + break Some(BindingUseRange::Param(&tcx.hir_body(body).value)); }, Some((_, Node::LetStmt(_))) if let Some((id, Node::Stmt(_))) = iter.next() diff --git a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs index e3b76b2b83452..8e84f39ee6530 100644 --- a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs @@ -450,7 +450,7 @@ impl<'tcx> LateLintPass<'tcx> for UnconditionalRecursion { ) { // If the function is a method... if let FnKind::Method(name, _) = kind - && let expr = expr_or_init(cx, body.value).peel_blocks() + && let expr = expr_or_init(cx, &body.value).peel_blocks() // Doesn't have a conditional return. && !has_conditional_return(body, expr) { diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_literal_bound.rs b/src/tools/clippy/clippy_lints/src/unnecessary_literal_bound.rs index 59987ad7ad817..02191ea8dd747 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_literal_bound.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_literal_bound.rs @@ -142,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryLiteralBound { } // Check for all return statements returning literals - if check_explicit_returns_static_str(body.value) && check_implicit_returns_static_str(body) { + if check_explicit_returns_static_str(&body.value) && check_implicit_returns_static_str(body) { span_lint_and_sugg( cx, UNNECESSARY_LITERAL_BOUND, diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs index 0afb5c4d1d0ff..27019e756478a 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs @@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { // Check if all return expression respect the following condition and collect them. let mut suggs = Vec::new(); - let can_sugg = find_all_ret_expressions(cx, body.value, |ret_expr| { + let can_sugg = find_all_ret_expressions(cx, &body.value, |ret_expr| { if !ret_expr.span.from_expansion() // Check if a function call. && let ExprKind::Call(func, [arg]) = ret_expr.kind diff --git a/src/tools/clippy/clippy_lints/src/unused_self.rs b/src/tools/clippy/clippy_lints/src/unused_self.rs index 1e2d9ab27c3e6..8dc659f822206 100644 --- a/src/tools/clippy/clippy_lints/src/unused_self.rs +++ b/src/tools/clippy/clippy_lints/src/unused_self.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { && let body = cx.tcx.hir_body(*body_id) && let [self_param, ..] = body.params && !is_local_used(cx, body, self_param.pat.hir_id) - && !is_todo_unimplemented_stub(cx, body.value) + && !is_todo_unimplemented_stub(cx, &body.value) { span_lint_and_help( cx, diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index a32a641c34ee5..84fe5c10eb4a8 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -140,7 +140,7 @@ fn check_item(cx: &LateContext<'_>, hir_id: HirId) { cx, hir_id, |v| { - v.expr(&v.bind("expr", body.value)); + v.expr(&v.bind("expr", &body.value)); }, Some(body), ); @@ -727,7 +727,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); chain!(self, "{expr} = &cx.tcx.hir_body({body_id}).value"); self.expr(expr); diff --git a/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs b/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs index 9eba3834d0eb9..f21e588a893d8 100644 --- a/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs +++ b/src/tools/clippy/clippy_lints_internal/src/lint_without_lint_pass.rs @@ -162,7 +162,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { .owner_id .def_id, ); - collector.visit_expr(body.value); + collector.visit_expr(&body.value); } } } diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 828fb1d3313b4..48ec0c838f8c3 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -206,7 +206,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) { }, ExprKind::Closure(&Closure { body, .. }) => ( Pat::Str(""), - expr_search_pat_inner(tcx, tcx.hir_body(body).value, outer_span).1, + expr_search_pat_inner(tcx, &tcx.hir_body(body).value, outer_span).1, ), ExprKind::Block( Block { @@ -342,7 +342,7 @@ fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirI let (mut start_pat, end_pat) = match kind { FnKind::ItemFn(.., header) => (fn_header_search_pat(*header), Pat::Str("")), FnKind::Method(.., sig) => (fn_header_search_pat(sig.header), Pat::Str("")), - FnKind::Closure => return (Pat::Str(""), expr_search_pat(tcx, body.value).1), + FnKind::Closure => return (Pat::Str(""), expr_search_pat(tcx, &body.value).1), }; match tcx.hir_node(hir_id) { Node::Item(Item { vis_span, .. }) diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index 0c7a9b36d97c5..239cf7cae8bf2 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -622,7 +622,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { fn expr(&self, e: &Expr<'_>) -> Option { self.check_ctxt(e.span.ctxt()); match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir_body(body).value), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(&self.tcx.hir_body(body).value), ExprKind::DropTemps(e) => self.expr(e), ExprKind::Path(ref qpath) => self.qpath(qpath, e.hir_id), ExprKind::Block(block, _) => { @@ -695,7 +695,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { /// leaves the local crate. pub fn eval_is_empty(&self, e: &Expr<'_>) -> Option { match e.kind { - ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(self.tcx.hir_body(body).value), + ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(&self.tcx.hir_body(body).value), ExprKind::DropTemps(e) => self.eval_is_empty(e), ExprKind::Lit(lit) => { if is_direct_expn_of(e.span, sym::cfg).is_some() { @@ -1184,9 +1184,9 @@ pub fn is_zero_integer_const(cx: &LateContext<'_>, expr: &Expr<'_>, ctxt: Syntax pub fn const_item_rhs_to_expr<'tcx>(tcx: TyCtxt<'tcx>, ct_rhs: ConstItemRhs<'tcx>) -> Option<&'tcx Expr<'tcx>> { match ct_rhs { - ConstItemRhs::Body(body_id) => Some(tcx.hir_body(body_id).value), + ConstItemRhs::Body(body_id) => Some(&tcx.hir_body(body_id).value), ConstItemRhs::Direct(const_arg) => match const_arg.kind { - ConstArgKind::Anon(anon) => Some(tcx.hir_body(anon.body).value), + ConstArgKind::Anon(anon) => Some(&tcx.hir_body(anon.body).value), ConstArgKind::Struct(..) | ConstArgKind::Tup(..) | ConstArgKind::Literal { .. } diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index 4ef0a795b4766..15a778519f1cc 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -491,8 +491,8 @@ impl HirEqInterExpr<'_, '_, '_> { self.inner.cx.tcx.typeck_body(right), )); let res = self.eq_expr( - self.inner.cx.tcx.hir_body(left).value, - self.inner.cx.tcx.hir_body(right).value, + &self.inner.cx.tcx.hir_body(left).value, + &self.inner.cx.tcx.hir_body(right).value, ); self.inner.maybe_typeck_results = old_maybe_typeck_results; res @@ -1246,7 +1246,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { }) => { mem::discriminant(capture_clause).hash(&mut self.s); // closures inherit TypeckResults - self.hash_expr(self.cx.tcx.hir_body(*body).value); + self.hash_expr(&self.cx.tcx.hir_body(*body).value); }, ExprKind::ConstBlock(l_id) => { self.hash_body(l_id.body); @@ -1669,7 +1669,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { pub fn hash_body(&mut self, body_id: BodyId) { // swap out TypeckResults when hashing a body let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id)); - self.hash_expr(self.cx.tcx.hir_body(body_id).value); + self.hash_expr(&self.cx.tcx.hir_body(body_id).value); self.maybe_typeck_results = old_maybe_typeck_results; } @@ -1805,7 +1805,7 @@ pub fn has_ambiguous_literal_in_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> b ExprKind::Closure(Closure { body, .. }) => { let body = cx.tcx.hir_body(*body); - let closure_expr = crate::peel_blocks(body.value); + let closure_expr = crate::peel_blocks(&body.value); has_ambiguous_literal_in_expr(cx, closure_expr) }, diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index cc73396f72246..3e62654d23f75 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1779,7 +1779,7 @@ pub fn get_async_closure_expr<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Optio /// Peels away all the compiler generated code surrounding the body of an async function, pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'tcx Expr<'tcx>> { - get_async_closure_expr(tcx, body.value) + get_async_closure_expr(tcx, &body.value) } // check if expr is calling method or function with #[must_use] attribute @@ -1842,7 +1842,7 @@ fn is_body_identity_function<'hir>(cx: &LateContext<'_>, func: &Body<'hir>) -> b true }; - let mut expr = func.value; + let mut expr = &func.value; loop { match expr.kind { ExprKind::Block( diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index c5a101caebc21..df0435c62d457 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -299,7 +299,7 @@ where /// Checks if the given resolved path is used in the given body. pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool { - for_each_expr(cx.tcx, cx.tcx.hir_body(body).value, |e| { + for_each_expr(cx.tcx, &cx.tcx.hir_body(body).value, |e| { if let ExprKind::Path(p) = &e.kind && cx.qpath_res(p, e.hir_id) == res { diff --git a/tests/ui/stats/input-stats.stderr b/tests/ui/stats/input-stats.stderr index 420b01102e41e..45c42dd89ced7 100644 --- a/tests/ui/stats/input-stats.stderr +++ b/tests/ui/stats/input-stats.stderr @@ -94,6 +94,7 @@ hir-stats GenericParam 400 (NN.N%) 5 80 hir-stats Block 288 (NN.N%) 6 48 hir-stats GenericBound 256 (NN.N%) 4 64 hir-stats - Trait 256 (NN.N%) 4 +hir-stats Body 240 (NN.N%) 3 80 hir-stats Attribute 160 (NN.N%) 4 40 hir-stats Variant 144 (NN.N%) 2 72 hir-stats GenericArgs 144 (NN.N%) 3 48 @@ -107,7 +108,6 @@ hir-stats Arm 80 (NN.N%) 2 40 hir-stats WherePredicate 72 (NN.N%) 3 24 hir-stats - BoundPredicate 72 (NN.N%) 3 hir-stats InlineAsm 72 (NN.N%) 1 72 -hir-stats Body 72 (NN.N%) 3 24 hir-stats Param 64 (NN.N%) 2 32 hir-stats Local 64 (NN.N%) 1 64 hir-stats GenericArg 64 (NN.N%) 4 16 @@ -120,5 +120,5 @@ hir-stats TraitItemId 8 (NN.N%) 2 4 hir-stats ImplItemId 8 (NN.N%) 2 4 hir-stats ForeignItemId 4 (NN.N%) 1 4 hir-stats ---------------------------------------------------------------- -hir-stats Total 8_592 172 +hir-stats Total 8_760 172 hir-stats ================================================================