1
1
use if_chain:: if_chain;
2
- use rustc_hir:: { PatKind , Stmt , StmtKind } ;
2
+ use rustc_hir:: { Local , PatKind } ;
3
3
use rustc_lint:: { LateContext , LateLintPass } ;
4
4
use rustc_middle:: lint:: in_external_macro;
5
5
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -66,13 +66,12 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
66
66
] ;
67
67
68
68
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for LetUnderscore {
69
- fn check_stmt ( & mut self , cx : & LateContext < ' _ , ' _ > , stmt : & Stmt < ' _ > ) {
70
- if in_external_macro ( cx. tcx . sess , stmt . span ) {
69
+ fn check_local ( & mut self , cx : & LateContext < ' _ , ' _ > , local : & Local < ' _ > ) {
70
+ if in_external_macro ( cx. tcx . sess , local . span ) {
71
71
return ;
72
72
}
73
73
74
74
if_chain ! {
75
- if let StmtKind :: Local ( ref local) = stmt. kind;
76
75
if let PatKind :: Wild = local. pat. kind;
77
76
if let Some ( ref init) = local. init;
78
77
then {
@@ -81,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
81
80
span_lint_and_help(
82
81
cx,
83
82
LET_UNDERSCORE_LOCK ,
84
- stmt . span,
83
+ local . span,
85
84
"non-binding let on a synchronization lock" ,
86
85
"consider using an underscore-prefixed named \
87
86
binding or dropping explicitly with `std::mem::drop`"
@@ -90,15 +89,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
90
89
span_lint_and_help(
91
90
cx,
92
91
LET_UNDERSCORE_MUST_USE ,
93
- stmt . span,
92
+ local . span,
94
93
"non-binding let on an expression with `#[must_use]` type" ,
95
94
"consider explicitly using expression value"
96
95
)
97
96
} else if is_must_use_func_call( cx, init) {
98
97
span_lint_and_help(
99
98
cx,
100
99
LET_UNDERSCORE_MUST_USE ,
101
- stmt . span,
100
+ local . span,
102
101
"non-binding let on a result of a `#[must_use]` function" ,
103
102
"consider explicitly using function result"
104
103
)
0 commit comments