Skip to content

Commit 1987bf7

Browse files
committed
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
2 parents 316da7e + 2fb73fe commit 1987bf7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

clippy_lints/src/returns.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ declare_clippy_lint! {
8686
#[derive(PartialEq, Eq, Copy, Clone)]
8787
enum RetReplacement {
8888
Empty,
89-
Unit,
89+
Block,
9090
}
9191

9292
declare_lint_pass!(Return => [NEEDLESS_RETURN, LET_AND_RETURN, UNUSED_UNIT]);
@@ -139,7 +139,7 @@ impl Return {
139139
// a match expr, check all arms
140140
ast::ExprKind::Match(_, ref arms) => {
141141
for arm in arms {
142-
self.check_final_expr(cx, &arm.body, Some(arm.body.span), RetReplacement::Unit);
142+
self.check_final_expr(cx, &arm.body, Some(arm.body.span), RetReplacement::Block);
143143
}
144144
},
145145
_ => (),
@@ -176,12 +176,12 @@ impl Return {
176176
);
177177
});
178178
},
179-
RetReplacement::Unit => {
179+
RetReplacement::Block => {
180180
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
181181
db.span_suggestion(
182182
ret_span,
183-
"replace `return` with the unit type",
184-
"()".to_string(),
183+
"replace `return` with an empty block",
184+
"{}".to_string(),
185185
Applicability::MachineApplicable,
186186
);
187187
});

tests/ui/needless_return.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ error: unneeded return statement
7070
--> $DIR/needless_return.rs:64:14
7171
|
7272
LL | _ => return,
73-
| ^^^^^^ help: replace `return` with the unit type: `()`
73+
| ^^^^^^ help: replace `return` with an empty block: `{}`
7474

7575
error: aborting due to 12 previous errors
7676

0 commit comments

Comments
 (0)