make note less verbose

This commit is contained in:
Catherine 2023-06-25 04:28:40 -05:00
parent b6f194b48c
commit a5ae9044fb
2 changed files with 20 additions and 32 deletions

View File

@ -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}`"),
);
}

View File

@ -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