diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 9d21dd71e0e8..7a65b849a664 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,4 +1,4 @@ -use clippy_utils::diagnostics::span_lint; +use clippy_utils::diagnostics::span_lint_hir; use clippy_utils::ty::contains_ty; use rustc_hir::intravisit; use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node}; @@ -118,9 +118,10 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { }); for node in v.set { - span_lint( + span_lint_hir( cx, BOXED_LOCAL, + node, cx.tcx.hir().span(node), "local variable doesn't need to be boxed here", ); diff --git a/tests/ui/escape_analysis.rs b/tests/ui/boxed_local.rs similarity index 97% rename from tests/ui/escape_analysis.rs rename to tests/ui/boxed_local.rs index 13e2b6c7a2e7..7c74aa758225 100644 --- a/tests/ui/escape_analysis.rs +++ b/tests/ui/boxed_local.rs @@ -1,4 +1,5 @@ #![feature(box_syntax)] +#![feature(lint_reasons)] #![allow( clippy::borrowed_box, clippy::needless_pass_by_value, @@ -202,3 +203,8 @@ mod issue4804 { fn foo(x: Box) {} } } + +#[expect(clippy::boxed_local)] +fn check_expect(x: Box) { + x.foo(); +} diff --git a/tests/ui/escape_analysis.stderr b/tests/ui/boxed_local.stderr similarity index 81% rename from tests/ui/escape_analysis.stderr rename to tests/ui/boxed_local.stderr index 4a82b4419f99..9036529f39c5 100644 --- a/tests/ui/escape_analysis.stderr +++ b/tests/ui/boxed_local.stderr @@ -1,5 +1,5 @@ error: local variable doesn't need to be boxed here - --> $DIR/escape_analysis.rs:40:13 + --> $DIR/boxed_local.rs:41:13 | LL | fn warn_arg(x: Box) { | ^ @@ -7,19 +7,19 @@ LL | fn warn_arg(x: Box) { = note: `-D clippy::boxed-local` implied by `-D warnings` error: local variable doesn't need to be boxed here - --> $DIR/escape_analysis.rs:131:12 + --> $DIR/boxed_local.rs:132:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> $DIR/escape_analysis.rs:195:44 + --> $DIR/boxed_local.rs:196:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> $DIR/escape_analysis.rs:202:16 + --> $DIR/boxed_local.rs:203:16 | LL | fn foo(x: Box) {} | ^