Skip to content

Commit

Permalink
Remove further semicolon reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Apr 10, 2018
1 parent eec3dec commit 85ad541
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
12 changes: 1 addition & 11 deletions clippy_lints/src/option_map_unit_fn.rs
Expand Up @@ -97,17 +97,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext, expr: &'a hir::Expr) -> Option<S
match inner_stmt.node {
hir::StmtDecl(ref d, _) => Some(d.span),
hir::StmtExpr(ref e, _) => Some(e.span),
hir::StmtSemi(ref e, _) => {
if is_unit_expression(cx, e) {
// `X` returns unit so we can strip the
// semicolon and reduce further
reduce_unit_expression(cx, e)
} else {
// `X` doesn't return unit so it needs a
// trailing semicolon
Some(inner_stmt.span)
}
},
hir::StmtSemi(_, _) => Some(inner_stmt.span),
}
},
_ => None,
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/option_map_unit_fn.stderr
Expand Up @@ -62,15 +62,15 @@ error: called `map(f)` on an Option value where `f` is a unit closure
52 | x.field.map(|value| { do_nothing(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`

error: called `map(f)` on an Option value where `f` is a unit closure
--> $DIR/option_map_unit_fn.rs:54:5
|
54 | x.field.map(|value| { { do_nothing(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`

error: called `map(f)` on an Option value where `f` is a unit closure
--> $DIR/option_map_unit_fn.rs:57:5
Expand All @@ -94,15 +94,15 @@ error: called `map(f)` on an Option value where `f` is a unit closure
61 | x.field.map(|value| { diverge(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`

error: called `map(f)` on an Option value where `f` is a unit closure
--> $DIR/option_map_unit_fn.rs:63:5
|
63 | x.field.map(|value| { { diverge(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`

error: called `map(f)` on an Option value where `f` is a unit closure
--> $DIR/option_map_unit_fn.rs:68:5
Expand Down

0 comments on commit 85ad541

Please sign in to comment.