]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/map_unit_fn.rs
Fix `doc_markdown` lints
[rust.git] / clippy_lints / src / map_unit_fn.rs
index 096ef46555dc5288c4aae31d59ac8ec07082c57c..503a2ee7032e0a4fdae28aa384141d94aeedb835 100644 (file)
@@ -1,3 +1,13 @@
+// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
 use crate::rustc::hir;
 use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use crate::rustc::{declare_tool_lint, lint_array};
@@ -169,7 +179,7 @@ fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Op
     None
 }
 
-/// Builds a name for the let binding variable (var_arg)
+/// Builds a name for the let binding variable (`var_arg`)
 ///
 /// `x.field` => `x_field`
 /// `y` => `_y`
@@ -228,16 +238,23 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
                                          snippet(cx, binding.pat.span, "_"),
                                          snippet(cx, var_arg.span, "_"),
                                          snippet(cx, reduced_expr_span, "_"));
-                db.span_suggestion(stmt.span, "try this", suggestion);
+                db.span_suggestion_with_applicability(
+                    stmt.span,
+                    "try this",
+                    suggestion,
+                    Applicability::MachineApplicable, // snippet
+                );
             } else {
                 let suggestion = format!("if let {0}({1}) = {2} {{ ... }}",
                                          variant,
                                          snippet(cx, binding.pat.span, "_"),
                                          snippet(cx, var_arg.span, "_"));
-                db.span_suggestion_with_applicability(stmt.span,
-                                                      "try this",
-                                                      suggestion,
-                                                      Applicability::Unspecified);
+                db.span_suggestion_with_applicability(
+                    stmt.span,
+                    "try this",
+                    suggestion,
+                    Applicability::Unspecified,
+                );
             }
         });
     }
@@ -250,10 +267,8 @@ fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt) {
         }
 
         if let hir::StmtKind::Semi(ref expr, _) = stmt.node {
-            if let hir::ExprKind::MethodCall(_, _, _) = expr.node {
-                if let Some(arglists) = method_chain_args(expr, &["map"]) {
-                    lint_map_unit_fn(cx, stmt, expr, arglists[0]);
-                }
+            if let Some(arglists) = method_chain_args(expr, &["map"]) {
+                lint_map_unit_fn(cx, stmt, expr, arglists[0]);
             }
         }
     }