11use if_chain:: if_chain;
2- use rustc_hir:: { PatKind , Stmt , StmtKind } ;
2+ use rustc_hir:: { Local , PatKind } ;
33use rustc_lint:: { LateContext , LateLintPass } ;
44use rustc_middle:: lint:: in_external_macro;
55use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -66,13 +66,12 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
6666] ;
6767
6868impl < ' 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 ) {
7171 return ;
7272 }
7373
7474 if_chain ! {
75- if let StmtKind :: Local ( ref local) = stmt. kind;
7675 if let PatKind :: Wild = local. pat. kind;
7776 if let Some ( ref init) = local. init;
7877 then {
@@ -81,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
8180 span_lint_and_help(
8281 cx,
8382 LET_UNDERSCORE_LOCK ,
84- stmt . span,
83+ local . span,
8584 "non-binding let on a synchronization lock" ,
8685 "consider using an underscore-prefixed named \
8786 binding or dropping explicitly with `std::mem::drop`"
@@ -90,15 +89,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
9089 span_lint_and_help(
9190 cx,
9291 LET_UNDERSCORE_MUST_USE ,
93- stmt . span,
92+ local . span,
9493 "non-binding let on an expression with `#[must_use]` type" ,
9594 "consider explicitly using expression value"
9695 )
9796 } else if is_must_use_func_call( cx, init) {
9897 span_lint_and_help(
9998 cx,
10099 LET_UNDERSCORE_MUST_USE ,
101- stmt . span,
100+ local . span,
102101 "non-binding let on a result of a `#[must_use]` function" ,
103102 "consider explicitly using function result"
104103 )
0 commit comments