File tree 6 files changed +92
-1
lines changed
6 files changed +92
-1
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
108
108
if !matches ! ( local. pat. kind, hir:: PatKind :: Wild ) {
109
109
return ;
110
110
}
111
+
112
+ if matches ! ( local. source, rustc_hir:: LocalSource :: AsyncFn ) {
113
+ return ;
114
+ }
111
115
if let Some ( init) = local. init {
112
116
let init_ty = cx. typeck_results ( ) . expr_ty ( init) ;
113
117
// If the type has a trivial Drop implementation, then it doesn't
@@ -126,6 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
126
130
suggestion : local. pat . span ,
127
131
multi_suggestion_start : local. span . until ( init. span ) ,
128
132
multi_suggestion_end : init. span . shrink_to_hi ( ) ,
133
+ default_binding_mode : local. pat . default_binding_modes ,
129
134
} ;
130
135
if is_sync_lock {
131
136
let mut span = MultiSpan :: from_spans ( vec ! [ local. pat. span, init. span] ) ;
Original file line number Diff line number Diff line change @@ -950,6 +950,7 @@ pub struct NonBindingLetSub {
950
950
pub suggestion : Span ,
951
951
pub multi_suggestion_start : Span ,
952
952
pub multi_suggestion_end : Span ,
953
+ pub default_binding_mode : bool ,
953
954
}
954
955
955
956
impl AddToDiagnostic for NonBindingLetSub {
@@ -960,10 +961,11 @@ impl AddToDiagnostic for NonBindingLetSub {
960
961
rustc_errors:: SubdiagnosticMessage ,
961
962
) -> rustc_errors:: SubdiagnosticMessage ,
962
963
{
964
+ let prefix = if self . default_binding_mode { "" } else { "let " } ;
963
965
diag. span_suggestion_verbose (
964
966
self . suggestion ,
965
967
fluent:: lint_non_binding_let_suggestion,
966
- " _unused",
968
+ format ! ( "{prefix} _unused") ,
967
969
Applicability :: MachineApplicable ,
968
970
) ;
969
971
diag. multipart_suggestion (
Original file line number Diff line number Diff line change
1
+ // edition: 2021
2
+
3
+ #![ deny( let_underscore_drop) ]
4
+ fn main ( ) {
5
+ let _ = foo ( ) ; //~ ERROR non-binding let on a type that implements `Drop`
6
+ }
7
+
8
+ async fn from_config ( _: Config ) { }
9
+
10
+ async fn foo ( ) {
11
+ from_config ( Config {
12
+ nickname : None ,
13
+ ..Default :: default ( )
14
+ } )
15
+ . await ;
16
+ }
17
+
18
+ #[ derive( Default ) ]
19
+ struct Config {
20
+ nickname : Option < Box < u8 > > ,
21
+ }
Original file line number Diff line number Diff line change
1
+ error: non-binding let on a type that implements `Drop`
2
+ --> $DIR/issue-119696-err-on-fn.rs:5:5
3
+ |
4
+ LL | let _ = foo();
5
+ | ^^^^^^^^^^^^^^
6
+ |
7
+ note: the lint level is defined here
8
+ --> $DIR/issue-119696-err-on-fn.rs:3:9
9
+ |
10
+ LL | #![deny(let_underscore_drop)]
11
+ | ^^^^^^^^^^^^^^^^^^^
12
+ help: consider binding to an unused variable to avoid immediately dropping the value
13
+ |
14
+ LL | let _unused = foo();
15
+ | ~~~~~~~
16
+ help: consider immediately dropping the value
17
+ |
18
+ LL | drop(foo());
19
+ | ~~~~~ +
20
+
21
+ error: aborting due to 1 previous error
22
+
Original file line number Diff line number Diff line change
1
+ #![ deny( let_underscore_drop) ]
2
+ #![ feature( type_alias_impl_trait) ]
3
+
4
+ pub struct Foo {
5
+ /// This type must have nontrivial drop glue
6
+ field : String ,
7
+ }
8
+
9
+ pub type Tait = impl Sized ;
10
+
11
+ pub fn ice_cold ( beverage : Tait ) {
12
+ // Must destructure at least one field of `Foo`
13
+ let Foo { field } = beverage;
14
+ // boom
15
+ _ = field; //~ ERROR non-binding let on a type that implements `Drop`
16
+ }
17
+
18
+
19
+ pub fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: non-binding let on a type that implements `Drop`
2
+ --> $DIR/issue-119697-extra-let.rs:15:5
3
+ |
4
+ LL | _ = field;
5
+ | ^^^^^^^^^
6
+ |
7
+ note: the lint level is defined here
8
+ --> $DIR/issue-119697-extra-let.rs:1:9
9
+ |
10
+ LL | #![deny(let_underscore_drop)]
11
+ | ^^^^^^^^^^^^^^^^^^^
12
+ help: consider binding to an unused variable to avoid immediately dropping the value
13
+ |
14
+ LL | let _unused = field;
15
+ | ~~~~~~~~~~~
16
+ help: consider immediately dropping the value
17
+ |
18
+ LL | drop(field);
19
+ | ~~~~~ +
20
+
21
+ error: aborting due to 1 previous error
22
+
You can’t perform that action at this time.
0 commit comments