From ad0e7c8e7fc0bff76c245fef53527f3df79a3a96 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 25 Sep 2019 08:49:23 -0700 Subject: [PATCH] map_unit_fn: fix applicability --- clippy_lints/src/map_unit_fn.rs | 12 ++++++------ tests/ui/option_map_unit_fn_fixable.stderr | 6 +++--- tests/ui/result_map_unit_fn_fixable.stderr | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 0df14c266..a88883455 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -217,15 +217,15 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr if is_unit_function(cx, fn_arg) { let msg = suggestion_msg("function", map_type); let suggestion = format!( - "if let {0}({1}) = {2} {{ {3}(...) }}", + "if let {0}({binding}) = {1} {{ {2}({binding}) }}", variant, - let_binding_name(cx, var_arg), snippet(cx, var_arg.span, "_"), - snippet(cx, fn_arg.span, "_") + snippet(cx, fn_arg.span, "_"), + binding = let_binding_name(cx, var_arg) ); span_lint_and_then(cx, lint, expr.span, &msg, |db| { - db.span_suggestion(stmt.span, "try this", suggestion, Applicability::Unspecified); + db.span_suggestion(stmt.span, "try this", suggestion, Applicability::MachineApplicable); }); } else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) { let msg = suggestion_msg("closure", map_type); @@ -250,9 +250,9 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr "if let {0}({1}) = {2} {{ ... }}", variant, snippet(cx, binding.pat.span, "_"), - snippet(cx, var_arg.span, "_") + snippet(cx, var_arg.span, "_"), ); - db.span_suggestion(stmt.span, "try this", suggestion, Applicability::Unspecified); + db.span_suggestion(stmt.span, "try this", suggestion, Applicability::HasPlaceholders); } }); } diff --git a/tests/ui/option_map_unit_fn_fixable.stderr b/tests/ui/option_map_unit_fn_fixable.stderr index 7c7ad39c3..a15be8825 100644 --- a/tests/ui/option_map_unit_fn_fixable.stderr +++ b/tests/ui/option_map_unit_fn_fixable.stderr @@ -4,7 +4,7 @@ error: called `map(f)` on an Option value where `f` is a unit function LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- | | - | help: try this: `if let Some(x_field) = x.field { do_nothing(...) }` + | help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }` | = note: `-D clippy::option-map-unit-fn` implied by `-D warnings` @@ -14,7 +14,7 @@ error: called `map(f)` on an Option value where `f` is a unit function LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- | | - | help: try this: `if let Some(x_field) = x.field { do_nothing(...) }` + | help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }` error: called `map(f)` on an Option value where `f` is a unit function --> $DIR/option_map_unit_fn_fixable.rs:36:5 @@ -22,7 +22,7 @@ error: called `map(f)` on an Option value where `f` is a unit function LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- | | - | help: try this: `if let Some(x_field) = x.field { diverge(...) }` + | help: try this: `if let Some(x_field) = x.field { diverge(x_field) }` error: called `map(f)` on an Option value where `f` is a unit closure --> $DIR/option_map_unit_fn_fixable.rs:42:5 diff --git a/tests/ui/result_map_unit_fn_fixable.stderr b/tests/ui/result_map_unit_fn_fixable.stderr index e48fb7c14..94ed07976 100644 --- a/tests/ui/result_map_unit_fn_fixable.stderr +++ b/tests/ui/result_map_unit_fn_fixable.stderr @@ -4,7 +4,7 @@ error: called `map(f)` on an Result value where `f` is a unit function LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- | | - | help: try this: `if let Ok(x_field) = x.field { do_nothing(...) }` + | help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }` | = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` @@ -14,7 +14,7 @@ error: called `map(f)` on an Result value where `f` is a unit function LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- | | - | help: try this: `if let Ok(x_field) = x.field { do_nothing(...) }` + | help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }` error: called `map(f)` on an Result value where `f` is a unit function --> $DIR/result_map_unit_fn_fixable.rs:38:5 @@ -22,7 +22,7 @@ error: called `map(f)` on an Result value where `f` is a unit function LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- | | - | help: try this: `if let Ok(x_field) = x.field { diverge(...) }` + | help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }` error: called `map(f)` on an Result value where `f` is a unit closure --> $DIR/result_map_unit_fn_fixable.rs:44:5