mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 05:03:21 +00:00
Auto merge of #4262 - bara86:master, r=flip1995
Use empty block instead of unit type for needless return fixes #4238 changelog: Use empty block instead of unit type for needless return
This commit is contained in:
commit
1987bf73a8
2 changed files with 6 additions and 6 deletions
|
@ -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]);
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
|
@ -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,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue