@@ -8,11 +8,11 @@ use utils::paths;
8
8
#[ derive( Clone ) ]
9
9
pub struct Pass ;
10
10
11
- /// **What it does:** Checks for usage of `Option .map(f)` where f is a function
11
+ /// **What it does:** Checks for usage of `option .map(f)` where f is a function
12
12
/// or closure that returns the unit type.
13
13
///
14
14
/// **Why is this bad?** Readability, this can be written more clearly with
15
- /// an if statement
15
+ /// an if let statement
16
16
///
17
17
/// **Known problems:** None.
18
18
///
@@ -38,14 +38,14 @@ pub struct Pass;
38
38
declare_clippy_lint ! {
39
39
pub OPTION_MAP_UNIT_FN ,
40
40
complexity,
41
- "using `Option .map(f)`, where f is a function or closure that returns ()"
41
+ "using `option .map(f)`, where f is a function or closure that returns ()"
42
42
}
43
43
44
- /// **What it does:** Checks for usage of `Result .map(f)` where f is a function
44
+ /// **What it does:** Checks for usage of `result .map(f)` where f is a function
45
45
/// or closure that returns the unit type.
46
46
///
47
47
/// **Why is this bad?** Readability, this can be written more clearly with
48
- /// an if statement
48
+ /// an if let statement
49
49
///
50
50
/// **Known problems:** None.
51
51
///
@@ -71,7 +71,7 @@ declare_clippy_lint! {
71
71
declare_clippy_lint ! {
72
72
pub RESULT_MAP_UNIT_FN ,
73
73
complexity,
74
- "using `Result .map(f)`, where f is a function or closure that returns ()"
74
+ "using `result .map(f)`, where f is a function or closure that returns ()"
75
75
}
76
76
77
77
@@ -215,33 +215,21 @@ fn lint_map_unit_fn(cx: &LateContext, stmt: &hir::Stmt, expr: &hir::Expr, map_ar
215
215
} else if let Some ( ( binding, closure_expr) ) = unit_closure ( cx, fn_arg) {
216
216
let msg = suggestion_msg ( "closure" , map_type) ;
217
217
218
- enum Suggestion {
219
- Full ( String ) ,
220
- Approx ( String )
221
- }
222
-
223
- let suggestion = if let Some ( expr_span) = reduce_unit_expression ( cx, closure_expr) {
224
- Suggestion :: Full (
225
- format ! ( "if let {0}({1}) = {2} {{ {3} }}" ,
226
- variant,
227
- snippet( cx, binding. pat. span, "_" ) ,
228
- snippet( cx, var_arg. span, "_" ) ,
229
- snippet( cx, expr_span, "_" ) )
230
- )
231
- } else {
232
- Suggestion :: Approx (
233
- format ! ( "if let {0}({1}) = {2} {{ ... }}" ,
234
- variant,
235
- snippet( cx, binding. pat. span, "_" ) ,
236
- snippet( cx, var_arg. span, "_" ) )
237
- )
238
- } ;
239
-
240
218
span_lint_and_then ( cx, lint, expr. span , & msg, |db| {
241
- match suggestion {
242
- Suggestion :: Full ( sugg) => db. span_suggestion ( stmt. span , "try this" , sugg) ,
243
- Suggestion :: Approx ( sugg) => db. span_approximate_suggestion ( stmt. span , "try this" , sugg) ,
244
- } ;
219
+ if let Some ( reduced_expr_span) = reduce_unit_expression ( cx, closure_expr) {
220
+ let suggestion = format ! ( "if let {0}({1}) = {2} {{ {3} }}" ,
221
+ variant,
222
+ snippet( cx, binding. pat. span, "_" ) ,
223
+ snippet( cx, var_arg. span, "_" ) ,
224
+ snippet( cx, reduced_expr_span, "_" ) ) ;
225
+ db. span_suggestion ( stmt. span , "try this" , suggestion) ;
226
+ } else {
227
+ let suggestion = format ! ( "if let {0}({1}) = {2} {{ ... }}" ,
228
+ variant,
229
+ snippet( cx, binding. pat. span, "_" ) ,
230
+ snippet( cx, var_arg. span, "_" ) ) ;
231
+ db. span_approximate_suggestion ( stmt. span , "try this" , suggestion) ;
232
+ }
245
233
} ) ;
246
234
}
247
235
}
0 commit comments