diff options
| -rw-r--r-- | clippy_lints/src/escape.rs | 5 | ||||
| -rw-r--r-- | tests/ui/boxed_local.rs (renamed from tests/ui/escape_analysis.rs) | 6 | ||||
| -rw-r--r-- | tests/ui/boxed_local.stderr (renamed from tests/ui/escape_analysis.stderr) | 8 |
3 files changed, 13 insertions, 6 deletions
diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 9d21dd71e0e..7a65b849a66 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 index 13e2b6c7a2e..7c74aa75822 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<u32>) {} } } + +#[expect(clippy::boxed_local)] +fn check_expect(x: Box<A>) { + x.foo(); +} diff --git a/tests/ui/escape_analysis.stderr b/tests/ui/boxed_local.stderr index 4a82b4419f9..9036529f39c 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<A>) { | ^ @@ -7,19 +7,19 @@ LL | fn warn_arg(x: Box<A>) { = 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<PeekableSeekable<&()>>) -> () {} | ^^^^^^^^^^^ 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<Self>, x: Box<u32>) -> 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<u32>) {} | ^ |
