Skip to content

Commit e280df5

Browse files
committed
Add note to suggest using let _ = x to ignore the value
1 parent d23f895 commit e280df5

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

compiler/rustc_lint/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,16 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound
523523
524524
lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value does nothing
525525
.label = argument has type `{$arg_ty}`
526+
.note = use `let _ = ...` to ignore the expression or result
526527
527528
lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy` does nothing
528529
.label = argument has type `{$arg_ty}`
530+
.note = use `let _ = ...` to ignore the expression or result
529531
530532
lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value does nothing
531533
.label = argument has type `{$arg_ty}`
534+
.note = use `let _ = ...` to ignore the expression or result
532535
533536
lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy` does nothing
534537
.label = argument has type `{$arg_ty}`
538+
.note = use `let _ = ...` to ignore the expression or result

compiler/rustc_lint/src/lints.rs

+4
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ pub struct ForLoopsOverFalliblesSuggestion<'a> {
665665
// drop_ref.rs
666666
#[derive(LintDiagnostic)]
667667
#[diag(lint_drop_ref)]
668+
#[note]
668669
pub struct DropRefDiag<'a> {
669670
pub arg_ty: Ty<'a>,
670671
#[label]
@@ -673,6 +674,7 @@ pub struct DropRefDiag<'a> {
673674

674675
#[derive(LintDiagnostic)]
675676
#[diag(lint_drop_copy)]
677+
#[note]
676678
pub struct DropCopyDiag<'a> {
677679
pub arg_ty: Ty<'a>,
678680
#[label]
@@ -681,6 +683,7 @@ pub struct DropCopyDiag<'a> {
681683

682684
#[derive(LintDiagnostic)]
683685
#[diag(lint_forget_ref)]
686+
#[note]
684687
pub struct ForgetRefDiag<'a> {
685688
pub arg_ty: Ty<'a>,
686689
#[label]
@@ -689,6 +692,7 @@ pub struct ForgetRefDiag<'a> {
689692

690693
#[derive(LintDiagnostic)]
691694
#[diag(lint_forget_copy)]
695+
#[note]
692696
pub struct ForgetCopyDiag<'a> {
693697
pub arg_ty: Ty<'a>,
694698
#[label]

tests/ui/lint/drop_copy.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | drop(s1);
66
| |
77
| argument has type `SomeStruct`
88
|
9+
= note: use `let _ = ...` to ignore the expression or result
910
note: the lint level is defined here
1011
--> $DIR/drop_copy.rs:3:9
1112
|
@@ -19,6 +20,8 @@ LL | drop(s2);
1920
| ^^^^^--^
2021
| |
2122
| argument has type `SomeStruct`
23+
|
24+
= note: use `let _ = ...` to ignore the expression or result
2225

2326
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
2427
--> $DIR/drop_copy.rs:36:5
@@ -28,6 +31,7 @@ LL | drop(s3);
2831
| |
2932
| argument has type `&SomeStruct`
3033
|
34+
= note: use `let _ = ...` to ignore the expression or result
3135
= note: `#[warn(drop_ref)]` on by default
3236

3337
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
@@ -37,6 +41,8 @@ LL | drop(s4);
3741
| ^^^^^--^
3842
| |
3943
| argument has type `SomeStruct`
44+
|
45+
= note: use `let _ = ...` to ignore the expression or result
4046

4147
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
4248
--> $DIR/drop_copy.rs:38:5
@@ -45,6 +51,8 @@ LL | drop(s5);
4551
| ^^^^^--^
4652
| |
4753
| argument has type `&SomeStruct`
54+
|
55+
= note: use `let _ = ...` to ignore the expression or result
4856

4957
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
5058
--> $DIR/drop_copy.rs:50:5
@@ -53,6 +61,8 @@ LL | drop(a2);
5361
| ^^^^^--^
5462
| |
5563
| argument has type `&AnotherStruct`
64+
|
65+
= note: use `let _ = ...` to ignore the expression or result
5666

5767
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
5868
--> $DIR/drop_copy.rs:52:5
@@ -61,6 +71,8 @@ LL | drop(a4);
6171
| ^^^^^--^
6272
| |
6373
| argument has type `&AnotherStruct`
74+
|
75+
= note: use `let _ = ...` to ignore the expression or result
6476

6577
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
6678
--> $DIR/drop_copy.rs:71:13
@@ -69,6 +81,8 @@ LL | drop(println_and(13));
6981
| ^^^^^---------------^
7082
| |
7183
| argument has type `i32`
84+
|
85+
= note: use `let _ = ...` to ignore the expression or result
7286

7387
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
7488
--> $DIR/drop_copy.rs:74:14
@@ -77,6 +91,8 @@ LL | 3 if drop(println_and(14)) == () => (),
7791
| ^^^^^---------------^
7892
| |
7993
| argument has type `i32`
94+
|
95+
= note: use `let _ = ...` to ignore the expression or result
8096

8197
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
8298
--> $DIR/drop_copy.rs:76:14
@@ -85,6 +101,8 @@ LL | 4 => drop(2),
85101
| ^^^^^-^
86102
| |
87103
| argument has type `i32`
104+
|
105+
= note: use `let _ = ...` to ignore the expression or result
88106

89107
warning: 10 warnings emitted
90108

tests/ui/lint/drop_ref.stderr

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | drop(&SomeStruct);
66
| |
77
| argument has type `&SomeStruct`
88
|
9+
= note: use `let _ = ...` to ignore the expression or result
910
note: the lint level is defined here
1011
--> $DIR/drop_ref.rs:3:9
1112
|
@@ -19,6 +20,8 @@ LL | drop(&owned1);
1920
| ^^^^^-------^
2021
| |
2122
| argument has type `&SomeStruct`
23+
|
24+
= note: use `let _ = ...` to ignore the expression or result
2225

2326
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
2427
--> $DIR/drop_ref.rs:12:5
@@ -27,6 +30,8 @@ LL | drop(&&owned1);
2730
| ^^^^^--------^
2831
| |
2932
| argument has type `&&SomeStruct`
33+
|
34+
= note: use `let _ = ...` to ignore the expression or result
3035

3136
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
3237
--> $DIR/drop_ref.rs:13:5
@@ -35,6 +40,8 @@ LL | drop(&mut owned1);
3540
| ^^^^^-----------^
3641
| |
3742
| argument has type `&mut SomeStruct`
43+
|
44+
= note: use `let _ = ...` to ignore the expression or result
3845

3946
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
4047
--> $DIR/drop_ref.rs:17:5
@@ -43,6 +50,8 @@ LL | drop(reference1);
4350
| ^^^^^----------^
4451
| |
4552
| argument has type `&SomeStruct`
53+
|
54+
= note: use `let _ = ...` to ignore the expression or result
4655

4756
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
4857
--> $DIR/drop_ref.rs:20:5
@@ -51,6 +60,8 @@ LL | drop(reference2);
5160
| ^^^^^----------^
5261
| |
5362
| argument has type `&mut SomeStruct`
63+
|
64+
= note: use `let _ = ...` to ignore the expression or result
5465

5566
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
5667
--> $DIR/drop_ref.rs:23:5
@@ -59,6 +70,8 @@ LL | drop(reference3);
5970
| ^^^^^----------^
6071
| |
6172
| argument has type `&SomeStruct`
73+
|
74+
= note: use `let _ = ...` to ignore the expression or result
6275

6376
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
6477
--> $DIR/drop_ref.rs:28:5
@@ -67,6 +80,8 @@ LL | drop(&val);
6780
| ^^^^^----^
6881
| |
6982
| argument has type `&T`
83+
|
84+
= note: use `let _ = ...` to ignore the expression or result
7085

7186
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
7287
--> $DIR/drop_ref.rs:36:5
@@ -75,6 +90,8 @@ LL | std::mem::drop(&SomeStruct);
7590
| ^^^^^^^^^^^^^^^-----------^
7691
| |
7792
| argument has type `&SomeStruct`
93+
|
94+
= note: use `let _ = ...` to ignore the expression or result
7895

7996
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
8097
--> $DIR/drop_ref.rs:91:13
@@ -83,6 +100,8 @@ LL | drop(println_and(&13));
83100
| ^^^^^----------------^
84101
| |
85102
| argument has type `&i32`
103+
|
104+
= note: use `let _ = ...` to ignore the expression or result
86105

87106
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
88107
--> $DIR/drop_ref.rs:94:14
@@ -91,6 +110,8 @@ LL | 3 if drop(println_and(&14)) == () => (),
91110
| ^^^^^----------------^
92111
| |
93112
| argument has type `&i32`
113+
|
114+
= note: use `let _ = ...` to ignore the expression or result
94115

95116
warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
96117
--> $DIR/drop_ref.rs:96:14
@@ -99,6 +120,8 @@ LL | 4 => drop(&2),
99120
| ^^^^^--^
100121
| |
101122
| argument has type `&i32`
123+
|
124+
= note: use `let _ = ...` to ignore the expression or result
102125

103126
warning: 12 warnings emitted
104127

tests/ui/lint/forget_copy.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | forget(s1);
66
| |
77
| argument has type `SomeStruct`
88
|
9+
= note: use `let _ = ...` to ignore the expression or result
910
note: the lint level is defined here
1011
--> $DIR/forget_copy.rs:3:9
1112
|
@@ -19,6 +20,8 @@ LL | forget(s2);
1920
| ^^^^^^^--^
2021
| |
2122
| argument has type `SomeStruct`
23+
|
24+
= note: use `let _ = ...` to ignore the expression or result
2225

2326
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
2427
--> $DIR/forget_copy.rs:36:5
@@ -28,6 +31,7 @@ LL | forget(s3);
2831
| |
2932
| argument has type `&SomeStruct`
3033
|
34+
= note: use `let _ = ...` to ignore the expression or result
3135
= note: `#[warn(forget_ref)]` on by default
3236

3337
warning: calls to `std::mem::forget` with a value that implements `Copy` does nothing
@@ -37,6 +41,8 @@ LL | forget(s4);
3741
| ^^^^^^^--^
3842
| |
3943
| argument has type `SomeStruct`
44+
|
45+
= note: use `let _ = ...` to ignore the expression or result
4046

4147
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
4248
--> $DIR/forget_copy.rs:38:5
@@ -45,6 +51,8 @@ LL | forget(s5);
4551
| ^^^^^^^--^
4652
| |
4753
| argument has type `&SomeStruct`
54+
|
55+
= note: use `let _ = ...` to ignore the expression or result
4856

4957
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
5058
--> $DIR/forget_copy.rs:50:5
@@ -53,6 +61,8 @@ LL | forget(a2);
5361
| ^^^^^^^--^
5462
| |
5563
| argument has type `&AnotherStruct`
64+
|
65+
= note: use `let _ = ...` to ignore the expression or result
5666

5767
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
5868
--> $DIR/forget_copy.rs:52:5
@@ -61,6 +71,8 @@ LL | forget(a3);
6171
| ^^^^^^^--^
6272
| |
6373
| argument has type `&AnotherStruct`
74+
|
75+
= note: use `let _ = ...` to ignore the expression or result
6476

6577
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
6678
--> $DIR/forget_copy.rs:53:5
@@ -69,6 +81,8 @@ LL | forget(a4);
6981
| ^^^^^^^--^
7082
| |
7183
| argument has type `&AnotherStruct`
84+
|
85+
= note: use `let _ = ...` to ignore the expression or result
7286

7387
warning: 8 warnings emitted
7488

tests/ui/lint/forget_ref.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | forget(&SomeStruct);
66
| |
77
| argument has type `&SomeStruct`
88
|
9+
= note: use `let _ = ...` to ignore the expression or result
910
note: the lint level is defined here
1011
--> $DIR/forget_ref.rs:3:9
1112
|
@@ -19,6 +20,8 @@ LL | forget(&owned);
1920
| ^^^^^^^------^
2021
| |
2122
| argument has type `&SomeStruct`
23+
|
24+
= note: use `let _ = ...` to ignore the expression or result
2225

2326
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
2427
--> $DIR/forget_ref.rs:14:5
@@ -27,6 +30,8 @@ LL | forget(&&owned);
2730
| ^^^^^^^-------^
2831
| |
2932
| argument has type `&&SomeStruct`
33+
|
34+
= note: use `let _ = ...` to ignore the expression or result
3035

3136
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
3237
--> $DIR/forget_ref.rs:15:5
@@ -35,6 +40,8 @@ LL | forget(&mut owned);
3540
| ^^^^^^^----------^
3641
| |
3742
| argument has type `&mut SomeStruct`
43+
|
44+
= note: use `let _ = ...` to ignore the expression or result
3845

3946
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
4047
--> $DIR/forget_ref.rs:19:5
@@ -43,6 +50,8 @@ LL | forget(&*reference1);
4350
| ^^^^^^^------------^
4451
| |
4552
| argument has type `&SomeStruct`
53+
|
54+
= note: use `let _ = ...` to ignore the expression or result
4655

4756
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
4857
--> $DIR/forget_ref.rs:22:5
@@ -51,6 +60,8 @@ LL | forget(reference2);
5160
| ^^^^^^^----------^
5261
| |
5362
| argument has type `&mut SomeStruct`
63+
|
64+
= note: use `let _ = ...` to ignore the expression or result
5465

5566
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
5667
--> $DIR/forget_ref.rs:25:5
@@ -59,6 +70,8 @@ LL | forget(reference3);
5970
| ^^^^^^^----------^
6071
| |
6172
| argument has type `&SomeStruct`
73+
|
74+
= note: use `let _ = ...` to ignore the expression or result
6275

6376
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
6477
--> $DIR/forget_ref.rs:30:5
@@ -67,6 +80,8 @@ LL | forget(&val);
6780
| ^^^^^^^----^
6881
| |
6982
| argument has type `&T`
83+
|
84+
= note: use `let _ = ...` to ignore the expression or result
7085

7186
warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing
7287
--> $DIR/forget_ref.rs:38:5
@@ -75,6 +90,8 @@ LL | std::mem::forget(&SomeStruct);
7590
| ^^^^^^^^^^^^^^^^^-----------^
7691
| |
7792
| argument has type `&SomeStruct`
93+
|
94+
= note: use `let _ = ...` to ignore the expression or result
7895

7996
warning: 9 warnings emitted
8097

0 commit comments

Comments
 (0)