Skip to content

Commit

Permalink
Don't require visit_body to take a lifetime that must outlive the f…
Browse files Browse the repository at this point in the history
…unction call
  • Loading branch information
oli-obk committed May 29, 2024
1 parent 5870f1c commit ceb45d5
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 31 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub trait Visitor<'v>: Sized {
walk_item(self, i)
}

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

Expand Down Expand Up @@ -578,7 +578,7 @@ 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: &'v Body<'v>) -> V::Result {
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &Body<'v>) -> V::Result {
walk_list!(visitor, visit_param, body.params);
visitor.visit_expr(body.value)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
resolve_block(self, b);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,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: &'tcx Body<'tcx>) {
fn visit_body(&mut self, body: &Body<'tcx>) {
for param in body.params {
debug!(
"param: span {:?}, ty_span {:?}, pat.span {:?}",
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_infer/src/infer/error_reporting/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
walk_stmt(self, ex)
}
}

fn visit_body(&mut self, body: &'v hir::Body<'v>) -> Self::Result {
hir::intravisit::walk_body(self, body)
}
}

self.tcx.hir().maybe_body_owned_by(cause.body_id).and_then(|body_id| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
});
}

fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
fn visit_body(&mut self, body: &hir::Body<'tcx>) {
lint_callback!(self, check_body, body);
hir_visit::walk_body(self, body);
lint_callback!(self, check_body_post, body);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ impl_lint_pass!(NonLocalDefinitions => [NON_LOCAL_DEFINITIONS]);
// instead check_mod is called after every body has been handled.

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

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use rustc_session::lint::LintPass;
macro_rules! late_lint_methods {
($macro:path, $args:tt) => (
$macro!($args, [
fn check_body(a: &'tcx rustc_hir::Body<'tcx>);
fn check_body_post(a: &'tcx rustc_hir::Body<'tcx>);
fn check_body(a: &rustc_hir::Body<'tcx>);
fn check_body_post(a: &rustc_hir::Body<'tcx>);
fn check_crate();
fn check_crate_post();
fn check_mod(a: &'tcx rustc_hir::Mod<'tcx>, b: rustc_hir::HirId);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
self.recurse_into(kind, None, |this| intravisit::walk_anon_const(this, anon));
}

fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
fn visit_body(&mut self, body: &hir::Body<'tcx>) {
let owner = self.tcx.hir().body_owner_def_id(body.id());
let kind = self.tcx.hir().body_const_context(owner);
self.recurse_into(kind, Some(owner), |this| intravisit::walk_body(this, body));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/hir_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_item(self, i)
}

fn visit_body(&mut self, b: &'v hir::Body<'v>) {
fn visit_body(&mut self, b: &hir::Body<'v>) {
self.record("Body", Id::None, b);
hir_visit::walk_body(self, b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4748,7 +4748,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> {
}
}

fn visit_body(&mut self, body: &'v hir::Body<'v>) {
fn visit_body(&mut self, body: &hir::Body<'v>) {
assert!(!self.in_block_tail);
self.in_block_tail = true;
hir::intravisit::walk_body(self, body);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RustdocVisitor<'a, 'tcx> {
// Unneeded.
}

fn visit_body(&mut self, b: &'tcx hir::Body<'tcx>) {
fn visit_body(&mut self, b: &hir::Body<'tcx>) {
let prev = mem::replace(&mut self.inside_body, true);
walk_body(self, b);
self.inside_body = prev;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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: &'tcx Body<'_>) {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
let hir = cx.tcx.hir();
let is_parent_const = matches!(
hir.body_const_context(hir.body_owner_def_id(body.id())),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
}
}

fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
if Some(body.id()) == self.current_body {
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
let replacements = pat.replacements;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/implicit_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
type NestedFilter = nested_filter::OnlyBodies;

fn visit_body(&mut self, body: &'tcx Body<'_>) {
fn visit_body(&mut self, body: &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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BodyVisitor<'a, 'tcx> {
}

impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) {
if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> {
}
}

fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
if self.possible_borrowers.last().map_or(false, |&(local_def_id, _)| {
local_def_id == cx.tcx.hir().body_owner_def_id(body.id())
}) {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub struct OnlyUsedInRecursion {
}

impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
if body.value.span.from_expansion() {
return;
}
Expand Down Expand Up @@ -350,7 +350,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
}
}

fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
if self.entered_body == Some(body.value.hir_id) {
self.entered_body = None;
self.params.flag_for_linting();
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/operators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,11 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
self.arithmetic_context.expr_post(e.hir_id);
}

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

fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) {
fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) {
self.arithmetic_context.body_post(cx, b);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
}
}

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

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

#[expect(clippy::too_many_lines)]
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
struct V<'cx, 'tcx> {
cx: &'cx LateContext<'tcx>,
/// Map from a local id to which argument it came from (index into `Self::args` and
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
}
}

fn check_body(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
fn check_body(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
self.try_block_depth_stack.push(0);
}

fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
self.try_block_depth_stack.pop();
}

Expand Down

0 comments on commit ceb45d5

Please sign in to comment.