mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-30 08:30:45 +00:00
map_unit_fn: fix applicability
This commit is contained in:
parent
24c283ea12
commit
ad0e7c8e7f
3 changed files with 12 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue