@@ -18,63 +18,61 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
18
18
return ;
19
19
}
20
20
21
- if_chain ! {
22
- if let Some ( init) = local. init;
23
- if !local. pat. span. from_expansion( ) ;
24
- if !in_external_macro( cx. sess( ) , local. span) ;
25
- if cx. typeck_results( ) . pat_ty( local. pat) . is_unit( ) ;
26
- then {
27
- // skip `let awa = ()`
28
- if let ExprKind :: Tup ( elements) = init. kind && elements. is_empty( ) {
29
- return ;
30
- }
21
+ if let Some ( init) = local. init
22
+ && !local. pat . span . from_expansion ( )
23
+ && !in_external_macro ( cx. sess ( ) , local. span )
24
+ && cx. typeck_results ( ) . pat_ty ( local. pat ) . is_unit ( )
25
+ {
26
+ // skip `let awa = ()`
27
+ if let ExprKind :: Tup ( elements) = init. kind && elements. is_empty ( ) {
28
+ return ;
29
+ }
31
30
32
- if ( local. ty. map_or( false , |ty| !matches!( ty. kind, TyKind :: Infer ) )
33
- || matches!( local. pat. kind, PatKind :: Tuple ( [ ] , ddpos) if ddpos. as_opt_usize( ) . is_none( ) ) )
34
- && expr_needs_inferred_result( cx, init)
31
+ if ( local. ty . map_or ( false , |ty| !matches ! ( ty. kind, TyKind :: Infer ) )
32
+ || matches ! ( local. pat. kind, PatKind :: Tuple ( [ ] , ddpos) if ddpos. as_opt_usize( ) . is_none( ) ) )
33
+ && expr_needs_inferred_result ( cx, init)
34
+ {
35
+ if !matches ! ( local. pat. kind, PatKind :: Wild )
36
+ && !matches ! ( local. pat. kind, PatKind :: Tuple ( [ ] , ddpos) if ddpos. as_opt_usize( ) . is_none( ) )
35
37
{
36
- if !matches!( local. pat. kind, PatKind :: Wild )
37
- && !matches!( local. pat. kind, PatKind :: Tuple ( [ ] , ddpos) if ddpos. as_opt_usize( ) . is_none( ) )
38
- {
39
- span_lint_and_then(
40
- cx,
41
- LET_UNIT_VALUE ,
42
- local. span,
43
- "this let-binding has unit value" ,
44
- |diag| {
45
- diag. span_suggestion(
46
- local. pat. span,
47
- "use a wild (`_`) binding" ,
48
- "_" ,
49
- Applicability :: MaybeIncorrect , // snippet
50
- ) ;
51
- } ,
52
- ) ;
53
- }
54
- } else {
55
- if let ExprKind :: Match ( _, _, MatchSource :: AwaitDesugar ) = init. kind {
56
- return
57
- }
58
-
59
38
span_lint_and_then (
60
39
cx,
61
40
LET_UNIT_VALUE ,
62
41
local. span ,
63
42
"this let-binding has unit value" ,
64
43
|diag| {
65
- if let Some ( expr) = & local. init {
66
- let mut app = Applicability :: MachineApplicable ;
67
- let snip = snippet_with_context( cx, expr. span, local. span. ctxt( ) , "()" , & mut app) . 0 ;
68
- diag. span_suggestion(
69
- local. span,
70
- "omit the `let` binding" ,
71
- format!( "{snip};" ) ,
72
- app,
73
- ) ;
74
- }
44
+ diag. span_suggestion (
45
+ local. pat . span ,
46
+ "use a wild (`_`) binding" ,
47
+ "_" ,
48
+ Applicability :: MaybeIncorrect , // snippet
49
+ ) ;
75
50
} ,
76
51
) ;
77
52
}
53
+ } else {
54
+ if let ExprKind :: Match ( _, _, MatchSource :: AwaitDesugar ) = init. kind {
55
+ return
56
+ }
57
+
58
+ span_lint_and_then (
59
+ cx,
60
+ LET_UNIT_VALUE ,
61
+ local. span ,
62
+ "this let-binding has unit value" ,
63
+ |diag| {
64
+ if let Some ( expr) = & local. init {
65
+ let mut app = Applicability :: MachineApplicable ;
66
+ let snip = snippet_with_context ( cx, expr. span , local. span . ctxt ( ) , "()" , & mut app) . 0 ;
67
+ diag. span_suggestion (
68
+ local. span ,
69
+ "omit the `let` binding" ,
70
+ format ! ( "{snip};" ) ,
71
+ app,
72
+ ) ;
73
+ }
74
+ } ,
75
+ ) ;
78
76
}
79
77
}
80
78
}
0 commit comments