about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCatherine <114838443+Centri3@users.noreply.github.com>2023-06-25 04:28:40 -0500
committerCatherine <114838443+Centri3@users.noreply.github.com>2023-06-25 04:28:40 -0500
commita5ae9044fbe53996a6d914de539b0fabd95232b4 (patch)
tree770ecdb6c63a43864efdb4cb8cf4ad1e4e2b65f9
parentb6f194b48c2b7b1cd6a19592a8376056a826d223 (diff)
downloadrust-a5ae9044fbe53996a6d914de539b0fabd95232b4.tar.gz
rust-a5ae9044fbe53996a6d914de539b0fabd95232b4.zip
make note less verbose
-rw-r--r--clippy_lints/src/drop_forget_ref.rs28
-rw-r--r--tests/ui/mem_forget.stderr24
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 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
             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 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
                         || 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 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
                 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<i32>`
-  --> $DIR/mem_forget.rs:14:22
-   |
-LL |     memstuff::forget(six);
-   |                      ^^^
+   = note: argument has type `std::sync::Arc<i32>`
    = 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<i32>`
-  --> $DIR/mem_forget.rs:17:22
-   |
-LL |     std::mem::forget(seven);
-   |                      ^^^^^
+   = note: argument has type `std::rc::Rc<i32>`
 
 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<i32>`
-  --> $DIR/mem_forget.rs:20:21
-   |
-LL |     forgetSomething(eight);
-   |                     ^^^^^
+   = note: argument has type `std::vec::Vec<i32>`
 
 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