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)]
|
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||||
enum RetReplacement {
|
enum RetReplacement {
|
||||||
Empty,
|
Empty,
|
||||||
Unit,
|
Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint_pass!(Return => [NEEDLESS_RETURN, LET_AND_RETURN, UNUSED_UNIT]);
|
declare_lint_pass!(Return => [NEEDLESS_RETURN, LET_AND_RETURN, UNUSED_UNIT]);
|
||||||
|
@ -139,7 +139,7 @@ impl Return {
|
||||||
// a match expr, check all arms
|
// a match expr, check all arms
|
||||||
ast::ExprKind::Match(_, ref arms) => {
|
ast::ExprKind::Match(_, ref arms) => {
|
||||||
for arm in 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| {
|
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
||||||
db.span_suggestion(
|
db.span_suggestion(
|
||||||
ret_span,
|
ret_span,
|
||||||
"replace `return` with the unit type",
|
"replace `return` with an empty block",
|
||||||
"()".to_string(),
|
"{}".to_string(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -70,7 +70,7 @@ error: unneeded return statement
|
||||||
--> $DIR/needless_return.rs:64:14
|
--> $DIR/needless_return.rs:64:14
|
||||||
|
|
|
|
||||||
LL | _ => return,
|
LL | _ => return,
|
||||||
| ^^^^^^ help: replace `return` with the unit type: `()`
|
| ^^^^^^ help: replace `return` with an empty block: `{}`
|
||||||
|
|
||||||
error: aborting due to 12 previous errors
|
error: aborting due to 12 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue