From a5ae9044fbe53996a6d914de539b0fabd95232b4 Mon Sep 17 00:00:00 2001 From: Catherine <114838443+Centri3@users.noreply.github.com> Date: Sun, 25 Jun 2023 04:28:40 -0500 Subject: [PATCH] make note less verbose --- clippy_lints/src/drop_forget_ref.rs | 28 ++++++++++++++++------------ tests/ui/mem_forget.stderr | 24 ++++-------------------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 36b231023a7..6f8261ed84e 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -120,7 +120,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { let arg_ty = cx.typeck_results().expr_ty(arg); let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); - let (lint, msg) = match fn_name { + let (lint, msg, note_span) = match fn_name { // early return for uplifted lints: dropping_references, dropping_copy_types, forgetting_references, forgetting_copy_types sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => return, @@ -144,20 +144,24 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { || drop_is_single_call_in_arm ) => { - (DROP_NON_DROP, DROP_NON_DROP_SUMMARY.into()) + (DROP_NON_DROP, DROP_NON_DROP_SUMMARY.into(), Some(arg.span)) }, sym::mem_forget => { if arg_ty.needs_drop(cx.tcx, cx.param_env) { - (MEM_FORGET, Cow::Owned(format!( - "usage of `mem::forget` on {}", - if arg_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { - "`Drop` type" - } else { - "type with `Drop` fields" - } - ))) + ( + MEM_FORGET, + Cow::Owned(format!( + "usage of `mem::forget` on {}", + if arg_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) { + "`Drop` type" + } else { + "type with `Drop` fields" + } + )), + None, + ) } else { - (FORGET_NON_DROP, FORGET_NON_DROP_SUMMARY.into()) + (FORGET_NON_DROP, FORGET_NON_DROP_SUMMARY.into(), Some(arg.span)) } } _ => return, @@ -167,7 +171,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { lint, expr.span, &msg, - Some(arg.span), + note_span, &format!("argument has type `{arg_ty}`"), ); } diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr index 6e3c31804d7..8004b2aa8db 100644 --- a/tests/ui/mem_forget.stderr +++ b/tests/ui/mem_forget.stderr @@ -4,11 +4,7 @@ error: usage of `mem::forget` on `Drop` type LL | memstuff::forget(six); | ^^^^^^^^^^^^^^^^^^^^^ | -note: argument has type `std::sync::Arc` - --> $DIR/mem_forget.rs:14:22 - | -LL | memstuff::forget(six); - | ^^^ + = note: argument has type `std::sync::Arc` = note: `-D clippy::mem-forget` implied by `-D warnings` error: usage of `mem::forget` on `Drop` type @@ -17,11 +13,7 @@ error: usage of `mem::forget` on `Drop` type LL | std::mem::forget(seven); | ^^^^^^^^^^^^^^^^^^^^^^^ | -note: argument has type `std::rc::Rc` - --> $DIR/mem_forget.rs:17:22 - | -LL | std::mem::forget(seven); - | ^^^^^ + = note: argument has type `std::rc::Rc` error: usage of `mem::forget` on `Drop` type --> $DIR/mem_forget.rs:20:5 @@ -29,11 +21,7 @@ error: usage of `mem::forget` on `Drop` type LL | forgetSomething(eight); | ^^^^^^^^^^^^^^^^^^^^^^ | -note: argument has type `std::vec::Vec` - --> $DIR/mem_forget.rs:20:21 - | -LL | forgetSomething(eight); - | ^^^^^ + = note: argument has type `std::vec::Vec` error: usage of `mem::forget` on type with `Drop` fields --> $DIR/mem_forget.rs:23:5 @@ -41,11 +29,7 @@ error: usage of `mem::forget` on type with `Drop` fields LL | std::mem::forget(string); | ^^^^^^^^^^^^^^^^^^^^^^^^ | -note: argument has type `std::string::String` - --> $DIR/mem_forget.rs:23:22 - | -LL | std::mem::forget(string); - | ^^^^^^ + = note: argument has type `std::string::String` error: aborting due to 4 previous errors