Skip to content

Commit a5ae904

Browse files
committed
make note less verbose
1 parent b6f194b commit a5ae904

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

clippy_lints/src/drop_forget_ref.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
120120
let arg_ty = cx.typeck_results().expr_ty(arg);
121121
let is_copy = is_copy(cx, arg_ty);
122122
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
123-
let (lint, msg) = match fn_name {
123+
let (lint, msg, note_span) = match fn_name {
124124
// early return for uplifted lints: dropping_references, dropping_copy_types, forgetting_references, forgetting_copy_types
125125
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return,
126126
sym::mem_forget if arg_ty.is_ref() => return,
@@ -144,20 +144,24 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
144144
|| drop_is_single_call_in_arm
145145
) =>
146146
{
147-
(DROP_NON_DROP, DROP_NON_DROP_SUMMARY.into())
147+
(DROP_NON_DROP, DROP_NON_DROP_SUMMARY.into(), Some(arg.span))
148148
},
149149
sym::mem_forget => {
150150
if arg_ty.needs_drop(cx.tcx, cx.param_env) {
151-
(MEM_FORGET, Cow::Owned(format!(
152-
"usage of `mem::forget` on {}",
153-
if arg_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) {
154-
"`Drop` type"
155-
} else {
156-
"type with `Drop` fields"
157-
}
158-
)))
151+
(
152+
MEM_FORGET,
153+
Cow::Owned(format!(
154+
"usage of `mem::forget` on {}",
155+
if arg_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) {
156+
"`Drop` type"
157+
} else {
158+
"type with `Drop` fields"
159+
}
160+
)),
161+
None,
162+
)
159163
} else {
160-
(FORGET_NON_DROP, FORGET_NON_DROP_SUMMARY.into())
164+
(FORGET_NON_DROP, FORGET_NON_DROP_SUMMARY.into(), Some(arg.span))
161165
}
162166
}
163167
_ => return,
@@ -167,7 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
167171
lint,
168172
expr.span,
169173
&msg,
170-
Some(arg.span),
174+
note_span,
171175
&format!("argument has type `{arg_ty}`"),
172176
);
173177
}

tests/ui/mem_forget.stderr

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ error: usage of `mem::forget` on `Drop` type
44
LL | memstuff::forget(six);
55
| ^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: argument has type `std::sync::Arc<i32>`
8-
--> $DIR/mem_forget.rs:14:22
9-
|
10-
LL | memstuff::forget(six);
11-
| ^^^
7+
= note: argument has type `std::sync::Arc<i32>`
128
= note: `-D clippy::mem-forget` implied by `-D warnings`
139

1410
error: usage of `mem::forget` on `Drop` type
@@ -17,35 +13,23 @@ error: usage of `mem::forget` on `Drop` type
1713
LL | std::mem::forget(seven);
1814
| ^^^^^^^^^^^^^^^^^^^^^^^
1915
|
20-
note: argument has type `std::rc::Rc<i32>`
21-
--> $DIR/mem_forget.rs:17:22
22-
|
23-
LL | std::mem::forget(seven);
24-
| ^^^^^
16+
= note: argument has type `std::rc::Rc<i32>`
2517

2618
error: usage of `mem::forget` on `Drop` type
2719
--> $DIR/mem_forget.rs:20:5
2820
|
2921
LL | forgetSomething(eight);
3022
| ^^^^^^^^^^^^^^^^^^^^^^
3123
|
32-
note: argument has type `std::vec::Vec<i32>`
33-
--> $DIR/mem_forget.rs:20:21
34-
|
35-
LL | forgetSomething(eight);
36-
| ^^^^^
24+
= note: argument has type `std::vec::Vec<i32>`
3725

3826
error: usage of `mem::forget` on type with `Drop` fields
3927
--> $DIR/mem_forget.rs:23:5
4028
|
4129
LL | std::mem::forget(string);
4230
| ^^^^^^^^^^^^^^^^^^^^^^^^
4331
|
44-
note: argument has type `std::string::String`
45-
--> $DIR/mem_forget.rs:23:22
46-
|
47-
LL | std::mem::forget(string);
48-
| ^^^^^^
32+
= note: argument has type `std::string::String`
4933

5034
error: aborting due to 4 previous errors
5135

0 commit comments

Comments
 (0)