Skip to content

Commit

Permalink
Auto merge of #4262 - bara86:master, r=flip1995
Browse files Browse the repository at this point in the history
Use empty block instead of unit type for needless return

fixes #4238

changelog: Use empty block instead of unit type for needless return
  • Loading branch information
bors committed Jul 9, 2019
2 parents 316da7e + 2fb73fe commit 1987bf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ declare_clippy_lint! {
#[derive(PartialEq, Eq, Copy, Clone)]
enum RetReplacement {
Empty,
Unit,
Block,
}

declare_lint_pass!(Return => [NEEDLESS_RETURN, LET_AND_RETURN, UNUSED_UNIT]);
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Return {
// a match expr, check all arms
ast::ExprKind::Match(_, ref arms) => {
for arm in arms {
self.check_final_expr(cx, &arm.body, Some(arm.body.span), RetReplacement::Unit);
self.check_final_expr(cx, &arm.body, Some(arm.body.span), RetReplacement::Block);
}
},
_ => (),
Expand Down Expand Up @@ -176,12 +176,12 @@ impl Return {
);
});
},
RetReplacement::Unit => {
RetReplacement::Block => {
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
db.span_suggestion(
ret_span,
"replace `return` with the unit type",
"()".to_string(),
"replace `return` with an empty block",
"{}".to_string(),
Applicability::MachineApplicable,
);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/needless_return.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ error: unneeded return statement
--> $DIR/needless_return.rs:64:14
|
LL | _ => return,
| ^^^^^^ help: replace `return` with the unit type: `()`
| ^^^^^^ help: replace `return` with an empty block: `{}`

error: aborting due to 12 previous errors

0 comments on commit 1987bf7

Please sign in to comment.