]> git.lizzy.rs Git - rust.git/commitdiff
Allow let_underscore
authorpmk21 <prithvikrishna49@gmail.com>
Wed, 1 Apr 2020 19:18:16 +0000 (00:48 +0530)
committerpmk21 <prithvikrishna49@gmail.com>
Wed, 1 Apr 2020 19:18:16 +0000 (00:48 +0530)
clippy_lints/src/let_underscore.rs

index 1f5a6b77ed31e016367d6a1e92fb80ace130025d..a68f7edd8370f57adf4aae8e619d5d63adc4ecd6 100644 (file)
@@ -1,5 +1,5 @@
 use if_chain::if_chain;
-use rustc_hir::{PatKind, Stmt, StmtKind};
+use rustc_hir::{Local, PatKind};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::lint::in_external_macro;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 ];
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
-    fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
-        if in_external_macro(cx.tcx.sess, stmt.span) {
+    fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) {
+        if in_external_macro(cx.tcx.sess, local.span) {
             return;
         }
 
         if_chain! {
-            if let StmtKind::Local(ref local) = stmt.kind;
             if let PatKind::Wild = local.pat.kind;
             if let Some(ref init) = local.init;
             then {
@@ -81,7 +80,7 @@ fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
                     span_lint_and_help(
                         cx,
                         LET_UNDERSCORE_LOCK,
-                        stmt.span,
+                        local.span,
                         "non-binding let on a synchronization lock",
                         "consider using an underscore-prefixed named \
                             binding or dropping explicitly with `std::mem::drop`"
@@ -90,7 +89,7 @@ fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
                     span_lint_and_help(
                         cx,
                         LET_UNDERSCORE_MUST_USE,
-                        stmt.span,
+                        local.span,
                         "non-binding let on an expression with `#[must_use]` type",
                         "consider explicitly using expression value"
                     )
@@ -98,7 +97,7 @@ fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
                     span_lint_and_help(
                         cx,
                         LET_UNDERSCORE_MUST_USE,
-                        stmt.span,
+                        local.span,
                         "non-binding let on a result of a `#[must_use]` function",
                         "consider explicitly using function result"
                     )