Skip to content

Commit ceb45d5

Browse files
committed
Don't require visit_body to take a lifetime that must outlive the function call
1 parent 5870f1c commit ceb45d5

File tree

20 files changed

+27
-31
lines changed

20 files changed

+27
-31
lines changed

compiler/rustc_hir/src/intravisit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub trait Visitor<'v>: Sized {
299299
walk_item(self, i)
300300
}
301301

302-
fn visit_body(&mut self, b: &'v Body<'v>) -> Self::Result {
302+
fn visit_body(&mut self, b: &Body<'v>) -> Self::Result {
303303
walk_body(self, b)
304304
}
305305

@@ -578,7 +578,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
578578
V::Result::output()
579579
}
580580

581-
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) -> V::Result {
581+
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &Body<'v>) -> V::Result {
582582
walk_list!(visitor, visit_param, body.params);
583583
visitor.visit_expr(body.value)
584584
}

compiler/rustc_hir_analysis/src/check/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
818818
resolve_block(self, b);
819819
}
820820

821-
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
821+
fn visit_body(&mut self, body: &hir::Body<'tcx>) {
822822
let body_id = body.id();
823823
let owner_id = self.tcx.hir().body_owner_def_id(body_id);
824824

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
11631163

11641164
/// For closures, we first visit the parameters and then the content,
11651165
/// as we prefer those.
1166-
fn visit_body(&mut self, body: &'tcx Body<'tcx>) {
1166+
fn visit_body(&mut self, body: &Body<'tcx>) {
11671167
for param in body.params {
11681168
debug!(
11691169
"param: span {:?}, ty_span {:?}, pat.span {:?}",

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

-4
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
578578
walk_stmt(self, ex)
579579
}
580580
}
581-
582-
fn visit_body(&mut self, body: &'v hir::Body<'v>) -> Self::Result {
583-
hir::intravisit::walk_body(self, body)
584-
}
585581
}
586582

587583
self.tcx.hir().maybe_body_owned_by(cause.body_id).and_then(|body_id| {

compiler/rustc_lint/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
125125
});
126126
}
127127

128-
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
128+
fn visit_body(&mut self, body: &hir::Body<'tcx>) {
129129
lint_callback!(self, check_body, body);
130130
hir_visit::walk_body(self, body);
131131
lint_callback!(self, check_body_post, body);

compiler/rustc_lint/src/non_local_def.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ impl_lint_pass!(NonLocalDefinitions => [NON_LOCAL_DEFINITIONS]);
6868
// instead check_mod is called after every body has been handled.
6969

7070
impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
71-
fn check_body(&mut self, _cx: &LateContext<'tcx>, _body: &'tcx Body<'tcx>) {
71+
fn check_body(&mut self, _cx: &LateContext<'tcx>, _body: &Body<'tcx>) {
7272
self.body_depth += 1;
7373
}
7474

75-
fn check_body_post(&mut self, _cx: &LateContext<'tcx>, _body: &'tcx Body<'tcx>) {
75+
fn check_body_post(&mut self, _cx: &LateContext<'tcx>, _body: &Body<'tcx>) {
7676
self.body_depth -= 1;
7777
}
7878

compiler/rustc_lint/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_session::lint::LintPass;
77
macro_rules! late_lint_methods {
88
($macro:path, $args:tt) => (
99
$macro!($args, [
10-
fn check_body(a: &'tcx rustc_hir::Body<'tcx>);
11-
fn check_body_post(a: &'tcx rustc_hir::Body<'tcx>);
10+
fn check_body(a: &rustc_hir::Body<'tcx>);
11+
fn check_body_post(a: &rustc_hir::Body<'tcx>);
1212
fn check_crate();
1313
fn check_crate_post();
1414
fn check_mod(a: &'tcx rustc_hir::Mod<'tcx>, b: rustc_hir::HirId);

compiler/rustc_passes/src/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
196196
self.recurse_into(kind, None, |this| intravisit::walk_anon_const(this, anon));
197197
}
198198

199-
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
199+
fn visit_body(&mut self, body: &hir::Body<'tcx>) {
200200
let owner = self.tcx.hir().body_owner_def_id(body.id());
201201
let kind = self.tcx.hir().body_const_context(owner);
202202
self.recurse_into(kind, Some(owner), |this| intravisit::walk_body(this, body));

compiler/rustc_passes/src/hir_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
246246
hir_visit::walk_item(self, i)
247247
}
248248

249-
fn visit_body(&mut self, b: &'v hir::Body<'v>) {
249+
fn visit_body(&mut self, b: &hir::Body<'v>) {
250250
self.record("Body", Id::None, b);
251251
hir_visit::walk_body(self, b);
252252
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4748,7 +4748,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> {
47484748
}
47494749
}
47504750

4751-
fn visit_body(&mut self, body: &'v hir::Body<'v>) {
4751+
fn visit_body(&mut self, body: &hir::Body<'v>) {
47524752
assert!(!self.in_block_tail);
47534753
self.in_block_tail = true;
47544754
hir::intravisit::walk_body(self, body);

src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RustdocVisitor<'a, 'tcx> {
614614
// Unneeded.
615615
}
616616

617-
fn visit_body(&mut self, b: &'tcx hir::Body<'tcx>) {
617+
fn visit_body(&mut self, b: &hir::Body<'tcx>) {
618618
let prev = mem::replace(&mut self.inside_body, true);
619619
walk_body(self, b);
620620
self.inside_body = prev;

src/tools/clippy/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())),

src/tools/clippy/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;

src/tools/clippy/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;

src/tools/clippy/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
}

src/tools/clippy/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
}) {

src/tools/clippy/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();

src/tools/clippy/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
}

src/tools/clippy/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

src/tools/clippy/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

0 commit comments

Comments
 (0)