Skip to content

Commit 8299d49

Browse files
committed
Auto merge of rust-lang#125711 - oli-obk:const_block_ice2, r=Nadrieril
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes rust-lang#125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
2 parents d38920f + f44a6a7 commit 8299d49

14 files changed

+21
-22
lines changed

clippy_lints/src/default_numeric_fallback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ declare_clippy_lint! {
4949
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
5050

5151
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
52-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
52+
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
5353
let hir = cx.tcx.hir();
5454
let is_parent_const = matches!(
5555
hir.body_const_context(hir.body_owner_def_id(body.id())),

clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
641641
}
642642
}
643643

644-
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
644+
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
645645
if Some(body.id()) == self.current_body {
646646
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
647647
let replacements = pat.replacements;

clippy_lints/src/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
328328
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
329329
type NestedFilter = nested_filter::OnlyBodies;
330330

331-
fn visit_body(&mut self, body: &'tcx Body<'_>) {
331+
fn visit_body(&mut self, body: &Body<'tcx>) {
332332
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id()));
333333
walk_body(self, body);
334334
self.maybe_typeck_results = old_maybe_typeck_results;

clippy_lints/src/macro_metavars_in_unsafe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BodyVisitor<'a, 'tcx> {
186186
}
187187

188188
impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
189-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) {
189+
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) {
190190
if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) {
191191
return;
192192
}

clippy_lints/src/methods/option_map_unwrap_or.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ pub(super) fn check<'tcx>(
5959
};
6060

6161
let map = cx.tcx.hir();
62-
let body = map.body(map.body_owned_by(map.enclosing_body_owner(expr.hir_id)));
63-
reference_visitor.visit_body(body);
62+
let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id));
63+
reference_visitor.visit_body(&body);
6464

6565
if reference_visitor.found_reference {
6666
return;

clippy_lints/src/needless_borrows_for_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> {
129129
}
130130
}
131131

132-
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
132+
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
133133
if self.possible_borrowers.last().map_or(false, |&(local_def_id, _)| {
134134
local_def_id == cx.tcx.hir().body_owner_def_id(body.id())
135135
}) {

clippy_lints/src/only_used_in_recursion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub struct OnlyUsedInRecursion {
221221
}
222222

223223
impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
224-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
224+
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
225225
if body.value.span.from_expansion() {
226226
return;
227227
}
@@ -350,7 +350,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
350350
}
351351
}
352352

353-
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
353+
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
354354
if self.entered_body == Some(body.value.hir_id) {
355355
self.entered_body = None;
356356
self.params.flag_for_linting();

clippy_lints/src/operators/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -868,11 +868,11 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
868868
self.arithmetic_context.expr_post(e.hir_id);
869869
}
870870

871-
fn check_body(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) {
871+
fn check_body(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) {
872872
self.arithmetic_context.enter_body(cx, b);
873873
}
874874

875-
fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) {
875+
fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) {
876876
self.arithmetic_context.body_post(cx, b);
877877
}
878878
}

clippy_lints/src/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
188188
}
189189
}
190190

191-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
191+
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
192192
let hir = cx.tcx.hir();
193193
let mut parents = hir.parent_iter(body.value.hir_id);
194194
let (item_id, sig, is_trait_item) = match parents.next() {
@@ -525,7 +525,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
525525
})
526526
}
527527

528-
fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'_>>) {
528+
fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&Body<'tcx>>) {
529529
if let FnRetTy::Return(ty) = sig.decl.output
530530
&& let Some((out, Mutability::Mut, _)) = get_ref_lm(ty)
531531
{
@@ -559,7 +559,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
559559
}
560560

561561
#[expect(clippy::too_many_lines)]
562-
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
562+
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
563563
struct V<'cx, 'tcx> {
564564
cx: &'cx LateContext<'tcx>,
565565
/// Map from a local id to which argument it came from (index into `Self::args` and

clippy_lints/src/question_mark.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
370370
}
371371
}
372372

373-
fn check_body(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
373+
fn check_body(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
374374
self.try_block_depth_stack.push(0);
375375
}
376376

377-
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
377+
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
378378
self.try_block_depth_stack.pop();
379379
}
380380

clippy_lints/src/single_call_fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ impl SingleCallFn {
7979
.tcx
8080
.hir()
8181
.maybe_body_owned_by(fn_def_id)
82-
.map(|body| cx.tcx.hir().body(body))
8382
.map_or(true, |body| is_in_test_function(cx.tcx, body.value.hir_id))
8483
|| match cx.tcx.hir_node(fn_hir_id) {
8584
Node::Item(item) => is_from_proc_macro(cx, item),

clippy_lints/src/transmute/missing_transmute_annotations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId)
3030

3131
fn is_function_block(cx: &LateContext<'_>, expr_hir_id: HirId) -> bool {
3232
let def_id = cx.tcx.hir().enclosing_body_owner(expr_hir_id);
33-
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id) {
34-
let body = cx.tcx.hir().body(body_id);
33+
if let Some(body) = cx.tcx.hir().maybe_body_owned_by(def_id) {
34+
let body = cx.tcx.hir().body(body.id());
3535
return body.value.peel_blocks().hir_id == expr_hir_id;
3636
}
3737
false

clippy_lints/src/unconditional_recursion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl UnconditionalRecursion {
336336
// We need to use typeck here to infer the actual function being called.
337337
&& let body_def_id = cx.tcx.hir().enclosing_body_owner(call_expr.hir_id)
338338
&& let Some(body_owner) = cx.tcx.hir().maybe_body_owned_by(body_def_id)
339-
&& let typeck = cx.tcx.typeck_body(body_owner)
339+
&& let typeck = cx.tcx.typeck_body(body_owner.id())
340340
&& let Some(call_def_id) = typeck.type_dependent_def_id(call_expr.hir_id)
341341
{
342342
self.default_impl_for_type.insert(self_def_id, call_def_id);

clippy_lints/src/utils/author.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ impl<'tcx> LateLintPass<'tcx> for Author {
137137

138138
fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
139139
let hir = cx.tcx.hir();
140-
if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
140+
if let Some(body) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
141141
check_node(cx, hir_id, |v| {
142-
v.expr(&v.bind("expr", hir.body(body_id).value));
142+
v.expr(&v.bind("expr", body.value));
143143
});
144144
}
145145
}

0 commit comments

Comments
 (0)