Skip to content

Commit 97b2ebd

Browse files
committed
map_unit_fn: fix applicability
1 parent 1f03567 commit 97b2ebd

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

clippy_lints/src/map_unit_fn.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
217217
if is_unit_function(cx, fn_arg) {
218218
let msg = suggestion_msg("function", map_type);
219219
let suggestion = format!(
220-
"if let {0}({1}) = {2} {{ {3}(...) }}",
220+
"if let {0}({binding}) = {1} {{ {2}({binding}) }}",
221221
variant,
222-
let_binding_name(cx, var_arg),
223222
snippet(cx, var_arg.span, "_"),
224-
snippet(cx, fn_arg.span, "_")
223+
snippet(cx, fn_arg.span, "_"),
224+
binding=let_binding_name(cx, var_arg)
225225
);
226226

227227
span_lint_and_then(cx, lint, expr.span, &msg, |db| {
228-
db.span_suggestion(stmt.span, "try this", suggestion, Applicability::Unspecified);
228+
db.span_suggestion(stmt.span, "try this", suggestion, Applicability::MachineApplicable);
229229
});
230230
} else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) {
231231
let msg = suggestion_msg("closure", map_type);
@@ -250,9 +250,9 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
250250
"if let {0}({1}) = {2} {{ ... }}",
251251
variant,
252252
snippet(cx, binding.pat.span, "_"),
253-
snippet(cx, var_arg.span, "_")
253+
snippet(cx, var_arg.span, "_"),
254254
);
255-
db.span_suggestion(stmt.span, "try this", suggestion, Applicability::Unspecified);
255+
db.span_suggestion(stmt.span, "try this", suggestion, Applicability::HasPlaceholders);
256256
}
257257
});
258258
}

tests/ui/option_map_unit_fn_fixable.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: called `map(f)` on an Option value where `f` is a unit function
44
LL | x.field.map(do_nothing);
55
| ^^^^^^^^^^^^^^^^^^^^^^^-
66
| |
7-
| help: try this: `if let Some(x_field) = x.field { do_nothing(...) }`
7+
| help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
88
|
99
= note: `-D clippy::option-map-unit-fn` implied by `-D warnings`
1010

@@ -14,15 +14,15 @@ error: called `map(f)` on an Option value where `f` is a unit function
1414
LL | x.field.map(do_nothing);
1515
| ^^^^^^^^^^^^^^^^^^^^^^^-
1616
| |
17-
| help: try this: `if let Some(x_field) = x.field { do_nothing(...) }`
17+
| help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
1818

1919
error: called `map(f)` on an Option value where `f` is a unit function
2020
--> $DIR/option_map_unit_fn_fixable.rs:36:5
2121
|
2222
LL | x.field.map(diverge);
2323
| ^^^^^^^^^^^^^^^^^^^^-
2424
| |
25-
| help: try this: `if let Some(x_field) = x.field { diverge(...) }`
25+
| help: try this: `if let Some(x_field) = x.field { diverge(x_field) }`
2626

2727
error: called `map(f)` on an Option value where `f` is a unit closure
2828
--> $DIR/option_map_unit_fn_fixable.rs:42:5

tests/ui/result_map_unit_fn_fixable.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: called `map(f)` on an Result value where `f` is a unit function
44
LL | x.field.map(do_nothing);
55
| ^^^^^^^^^^^^^^^^^^^^^^^-
66
| |
7-
| help: try this: `if let Ok(x_field) = x.field { do_nothing(...) }`
7+
| help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
88
|
99
= note: `-D clippy::result-map-unit-fn` implied by `-D warnings`
1010

@@ -14,15 +14,15 @@ error: called `map(f)` on an Result value where `f` is a unit function
1414
LL | x.field.map(do_nothing);
1515
| ^^^^^^^^^^^^^^^^^^^^^^^-
1616
| |
17-
| help: try this: `if let Ok(x_field) = x.field { do_nothing(...) }`
17+
| help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
1818

1919
error: called `map(f)` on an Result value where `f` is a unit function
2020
--> $DIR/result_map_unit_fn_fixable.rs:38:5
2121
|
2222
LL | x.field.map(diverge);
2323
| ^^^^^^^^^^^^^^^^^^^^-
2424
| |
25-
| help: try this: `if let Ok(x_field) = x.field { diverge(...) }`
25+
| help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }`
2626

2727
error: called `map(f)` on an Result value where `f` is a unit closure
2828
--> $DIR/result_map_unit_fn_fixable.rs:44:5

0 commit comments

Comments
 (0)