Add note to suggest using let _ = x to ignore the value

This commit is contained in:
Urgau 2023-04-14 22:20:27 +02:00
parent d23f8957ae
commit e280df556d
6 changed files with 80 additions and 0 deletions

View File

@ -523,12 +523,16 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound
lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy` does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy` does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result

View File

@ -665,6 +665,7 @@ pub struct ForLoopsOverFalliblesSuggestion<'a> {
// drop_ref.rs
#[derive(LintDiagnostic)]
#[diag(lint_drop_ref)]
#[note]
pub struct DropRefDiag<'a> {
pub arg_ty: Ty<'a>,
#[label]
@ -673,6 +674,7 @@ pub struct DropRefDiag<'a> {
#[derive(LintDiagnostic)]
#[diag(lint_drop_copy)]
#[note]
pub struct DropCopyDiag<'a> {
pub arg_ty: Ty<'a>,
#[label]
@ -681,6 +683,7 @@ pub struct DropCopyDiag<'a> {
#[derive(LintDiagnostic)]
#[diag(lint_forget_ref)]
#[note]
pub struct ForgetRefDiag<'a> {
pub arg_ty: Ty<'a>,
#[label]
@ -689,6 +692,7 @@ pub struct ForgetRefDiag<'a> {
#[derive(LintDiagnostic)]
#[diag(lint_forget_copy)]
#[note]
pub struct ForgetCopyDiag<'a> {
pub arg_ty: Ty<'a>,
#[label]

View File

@ -6,6 +6,7 @@ LL | drop(s1);
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
note: the lint level is defined here
--> $DIR/drop_copy.rs:3:9
|
@ -19,6 +20,8 @@ LL | drop(s2);
| ^^^^^--^
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_copy.rs:36:5
@ -28,6 +31,7 @@ LL | drop(s3);
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
= note: `#[warn(drop_ref)]` on by default
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
@ -37,6 +41,8 @@ LL | drop(s4);
| ^^^^^--^
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_copy.rs:38:5
@ -45,6 +51,8 @@ LL | drop(s5);
| ^^^^^--^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_copy.rs:50:5
@ -53,6 +61,8 @@ LL | drop(a2);
| ^^^^^--^
| |
| argument has type `&AnotherStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_copy.rs:52:5
@ -61,6 +71,8 @@ LL | drop(a4);
| ^^^^^--^
| |
| argument has type `&AnotherStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/drop_copy.rs:71:13
@ -69,6 +81,8 @@ LL | drop(println_and(13));
| ^^^^^---------------^
| |
| argument has type `i32`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/drop_copy.rs:74:14
@ -77,6 +91,8 @@ LL | 3 if drop(println_and(14)) == () => (),
| ^^^^^---------------^
| |
| argument has type `i32`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/drop_copy.rs:76:14
@ -85,6 +101,8 @@ LL | 4 => drop(2),
| ^^^^^-^
| |
| argument has type `i32`
|
= note: use `let _ = ...` to ignore the expression or result
warning: 10 warnings emitted

View File

@ -6,6 +6,7 @@ LL | drop(&SomeStruct);
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
note: the lint level is defined here
--> $DIR/drop_ref.rs:3:9
|
@ -19,6 +20,8 @@ LL | drop(&owned1);
| ^^^^^-------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:12:5
@ -27,6 +30,8 @@ LL | drop(&&owned1);
| ^^^^^--------^
| |
| argument has type `&&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:13:5
@ -35,6 +40,8 @@ LL | drop(&mut owned1);
| ^^^^^-----------^
| |
| argument has type `&mut SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:17:5
@ -43,6 +50,8 @@ LL | drop(reference1);
| ^^^^^----------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:20:5
@ -51,6 +60,8 @@ LL | drop(reference2);
| ^^^^^----------^
| |
| argument has type `&mut SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:23:5
@ -59,6 +70,8 @@ LL | drop(reference3);
| ^^^^^----------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:28:5
@ -67,6 +80,8 @@ LL | drop(&val);
| ^^^^^----^
| |
| argument has type `&T`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:36:5
@ -75,6 +90,8 @@ LL | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^^^^^-----------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:91:13
@ -83,6 +100,8 @@ LL | drop(println_and(&13));
| ^^^^^----------------^
| |
| argument has type `&i32`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:94:14
@ -91,6 +110,8 @@ LL | 3 if drop(println_and(&14)) == () => (),
| ^^^^^----------------^
| |
| argument has type `&i32`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/drop_ref.rs:96:14
@ -99,6 +120,8 @@ LL | 4 => drop(&2),
| ^^^^^--^
| |
| argument has type `&i32`
|
= note: use `let _ = ...` to ignore the expression or result
warning: 12 warnings emitted

View File

@ -6,6 +6,7 @@ LL | forget(s1);
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
note: the lint level is defined here
--> $DIR/forget_copy.rs:3:9
|
@ -19,6 +20,8 @@ LL | forget(s2);
| ^^^^^^^--^
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_copy.rs:36:5
@ -28,6 +31,7 @@ LL | forget(s3);
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
= note: `#[warn(forget_ref)]` on by default
warning: calls to `std::mem::forget` with a value that implements `Copy` does nothing
@ -37,6 +41,8 @@ LL | forget(s4);
| ^^^^^^^--^
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_copy.rs:38:5
@ -45,6 +51,8 @@ LL | forget(s5);
| ^^^^^^^--^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_copy.rs:50:5
@ -53,6 +61,8 @@ LL | forget(a2);
| ^^^^^^^--^
| |
| argument has type `&AnotherStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_copy.rs:52:5
@ -61,6 +71,8 @@ LL | forget(a3);
| ^^^^^^^--^
| |
| argument has type `&AnotherStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_copy.rs:53:5
@ -69,6 +81,8 @@ LL | forget(a4);
| ^^^^^^^--^
| |
| argument has type `&AnotherStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: 8 warnings emitted

View File

@ -6,6 +6,7 @@ LL | forget(&SomeStruct);
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
note: the lint level is defined here
--> $DIR/forget_ref.rs:3:9
|
@ -19,6 +20,8 @@ LL | forget(&owned);
| ^^^^^^^------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_ref.rs:14:5
@ -27,6 +30,8 @@ LL | forget(&&owned);
| ^^^^^^^-------^
| |
| argument has type `&&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_ref.rs:15:5
@ -35,6 +40,8 @@ LL | forget(&mut owned);
| ^^^^^^^----------^
| |
| argument has type `&mut SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_ref.rs:19:5
@ -43,6 +50,8 @@ LL | forget(&*reference1);
| ^^^^^^^------------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_ref.rs:22:5
@ -51,6 +60,8 @@ LL | forget(reference2);
| ^^^^^^^----------^
| |
| argument has type `&mut SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_ref.rs:25:5
@ -59,6 +70,8 @@ LL | forget(reference3);
| ^^^^^^^----------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_ref.rs:30:5
@ -67,6 +80,8 @@ LL | forget(&val);
| ^^^^^^^----^
| |
| argument has type `&T`
|
= note: use `let _ = ...` to ignore the expression or result
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
--> $DIR/forget_ref.rs:38:5
@ -75,6 +90,8 @@ LL | std::mem::forget(&SomeStruct);
| ^^^^^^^^^^^^^^^^^-----------^
| |
| argument has type `&SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
warning: 9 warnings emitted