Don't require visit_body
to take a lifetime that must outlive the function call
This commit is contained in:
parent
5870f1ccbb
commit
ceb45d5519
@ -299,7 +299,7 @@ fn visit_item(&mut self, i: &'v Item<'v>) -> Self::Result {
|
|||||||
walk_item(self, i)
|
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)
|
walk_body(self, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,7 +578,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
|||||||
V::Result::output()
|
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);
|
walk_list!(visitor, visit_param, body.params);
|
||||||
visitor.visit_expr(body.value)
|
visitor.visit_expr(body.value)
|
||||||
}
|
}
|
||||||
|
@ -818,7 +818,7 @@ fn visit_block(&mut self, b: &'tcx Block<'tcx>) {
|
|||||||
resolve_block(self, b);
|
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 body_id = body.id();
|
||||||
let owner_id = self.tcx.hir().body_owner_def_id(body_id);
|
let owner_id = self.tcx.hir().body_owner_def_id(body_id);
|
||||||
|
|
||||||
|
@ -1163,7 +1163,7 @@ fn visit_local(&mut self, local: &'tcx LetStmt<'tcx>) {
|
|||||||
|
|
||||||
/// For closures, we first visit the parameters and then the content,
|
/// For closures, we first visit the parameters and then the content,
|
||||||
/// as we prefer those.
|
/// 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 {
|
for param in body.params {
|
||||||
debug!(
|
debug!(
|
||||||
"param: span {:?}, ty_span {:?}, pat.span {:?}",
|
"param: span {:?}, ty_span {:?}, pat.span {:?}",
|
||||||
|
@ -578,10 +578,6 @@ fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) -> Self::Result {
|
|||||||
walk_stmt(self, ex)
|
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| {
|
self.tcx.hir().maybe_body_owned_by(cause.body_id).and_then(|body_id| {
|
||||||
|
@ -125,7 +125,7 @@ fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
lint_callback!(self, check_body, body);
|
||||||
hir_visit::walk_body(self, body);
|
hir_visit::walk_body(self, body);
|
||||||
lint_callback!(self, check_body_post, body);
|
lint_callback!(self, check_body_post, body);
|
||||||
|
@ -68,11 +68,11 @@ pub struct NonLocalDefinitions {
|
|||||||
// instead check_mod is called after every body has been handled.
|
// instead check_mod is called after every body has been handled.
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
|
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;
|
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;
|
self.body_depth -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
macro_rules! late_lint_methods {
|
macro_rules! late_lint_methods {
|
||||||
($macro:path, $args:tt) => (
|
($macro:path, $args:tt) => (
|
||||||
$macro!($args, [
|
$macro!($args, [
|
||||||
fn check_body(a: &'tcx rustc_hir::Body<'tcx>);
|
fn check_body(a: &rustc_hir::Body<'tcx>);
|
||||||
fn check_body_post(a: &'tcx rustc_hir::Body<'tcx>);
|
fn check_body_post(a: &rustc_hir::Body<'tcx>);
|
||||||
fn check_crate();
|
fn check_crate();
|
||||||
fn check_crate_post();
|
fn check_crate_post();
|
||||||
fn check_mod(a: &'tcx rustc_hir::Mod<'tcx>, b: rustc_hir::HirId);
|
fn check_mod(a: &'tcx rustc_hir::Mod<'tcx>, b: rustc_hir::HirId);
|
||||||
|
@ -196,7 +196,7 @@ fn visit_anon_const(&mut self, anon: &'tcx hir::AnonConst) {
|
|||||||
self.recurse_into(kind, None, |this| intravisit::walk_anon_const(this, anon));
|
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 owner = self.tcx.hir().body_owner_def_id(body.id());
|
||||||
let kind = self.tcx.hir().body_const_context(owner);
|
let kind = self.tcx.hir().body_const_context(owner);
|
||||||
self.recurse_into(kind, Some(owner), |this| intravisit::walk_body(this, body));
|
self.recurse_into(kind, Some(owner), |this| intravisit::walk_body(this, body));
|
||||||
|
@ -246,7 +246,7 @@ fn visit_item(&mut self, i: &'v hir::Item<'v>) {
|
|||||||
hir_visit::walk_item(self, i)
|
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);
|
self.record("Body", Id::None, b);
|
||||||
hir_visit::walk_body(self, b);
|
hir_visit::walk_body(self, b);
|
||||||
}
|
}
|
||||||
|
@ -4748,7 +4748,7 @@ fn visit_expr(&mut self, ex: &'v hir::Expr<'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);
|
assert!(!self.in_block_tail);
|
||||||
self.in_block_tail = true;
|
self.in_block_tail = true;
|
||||||
hir::intravisit::walk_body(self, body);
|
hir::intravisit::walk_body(self, body);
|
||||||
|
@ -614,7 +614,7 @@ fn visit_lifetime(&mut self, _: &hir::Lifetime) {
|
|||||||
// Unneeded.
|
// 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);
|
let prev = mem::replace(&mut self.inside_body, true);
|
||||||
walk_body(self, b);
|
walk_body(self, b);
|
||||||
self.inside_body = prev;
|
self.inside_body = prev;
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
|
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
|
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 hir = cx.tcx.hir();
|
||||||
let is_parent_const = matches!(
|
let is_parent_const = matches!(
|
||||||
hir.body_const_context(hir.body_owner_def_id(body.id())),
|
hir.body_const_context(hir.body_owner_def_id(body.id())),
|
||||||
|
@ -641,7 +641,7 @@ fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
if Some(body.id()) == self.current_body {
|
||||||
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
|
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
|
||||||
let replacements = pat.replacements;
|
let replacements = pat.replacements;
|
||||||
|
@ -328,7 +328,7 @@ fn new(cx: &'a LateContext<'tcx>, target: &'b ImplicitHasherType<'tcx>) -> Self
|
|||||||
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
|
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
|
||||||
type NestedFilter = nested_filter::OnlyBodies;
|
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()));
|
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id()));
|
||||||
walk_body(self, body);
|
walk_body(self, body);
|
||||||
self.maybe_typeck_results = old_maybe_typeck_results;
|
self.maybe_typeck_results = old_maybe_typeck_results;
|
||||||
|
@ -186,7 +186,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
|
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) {
|
if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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, _)| {
|
if self.possible_borrowers.last().map_or(false, |&(local_def_id, _)| {
|
||||||
local_def_id == cx.tcx.hir().body_owner_def_id(body.id())
|
local_def_id == cx.tcx.hir().body_owner_def_id(body.id())
|
||||||
}) {
|
}) {
|
||||||
|
@ -221,7 +221,7 @@ pub struct OnlyUsedInRecursion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for 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() {
|
if body.value.span.from_expansion() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if self.entered_body == Some(body.value.hir_id) {
|
||||||
self.entered_body = None;
|
self.entered_body = None;
|
||||||
self.params.flag_for_linting();
|
self.params.flag_for_linting();
|
||||||
|
@ -868,11 +868,11 @@ fn check_expr_post(&mut self, _: &LateContext<'_>, e: &Expr<'_>) {
|
|||||||
self.arithmetic_context.expr_post(e.hir_id);
|
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);
|
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);
|
self.arithmetic_context.body_post(cx, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 hir = cx.tcx.hir();
|
||||||
let mut parents = hir.parent_iter(body.value.hir_id);
|
let mut parents = hir.parent_iter(body.value.hir_id);
|
||||||
let (item_id, sig, is_trait_item) = match parents.next() {
|
let (item_id, sig, is_trait_item) = match parents.next() {
|
||||||
@ -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
|
if let FnRetTy::Return(ty) = sig.decl.output
|
||||||
&& let Some((out, Mutability::Mut, _)) = get_ref_lm(ty)
|
&& let Some((out, Mutability::Mut, _)) = get_ref_lm(ty)
|
||||||
{
|
{
|
||||||
@ -559,7 +559,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[expect(clippy::too_many_lines)]
|
#[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> {
|
struct V<'cx, 'tcx> {
|
||||||
cx: &'cx LateContext<'tcx>,
|
cx: &'cx LateContext<'tcx>,
|
||||||
/// Map from a local id to which argument it came from (index into `Self::args` and
|
/// Map from a local id to which argument it came from (index into `Self::args` and
|
||||||
|
@ -370,11 +370,11 @@ fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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();
|
self.try_block_depth_stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user