Skip to content

Commit

Permalink
fix(needles_return): correct span selection for text replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
feniljain committed Apr 5, 2023
1 parent b499b7d commit 9cf57d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn check_final_expr<'tcx>(
ExprKind::Match(_, arms, MatchSource::Normal) => {
let match_ty = cx.typeck_results().expr_ty(peeled_drop_expr);
for arm in arms.iter() {
check_final_expr(cx, arm.body, semi_spans.clone(), RetReplacement::Empty, Some(match_ty));
check_final_expr(cx, arm.body, semi_spans.clone(), RetReplacement::Unit, Some(match_ty));
}
},
// if it's a whole block, check it
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/needless_return.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn test_void_if_fun(b: bool) {
fn test_void_match(x: u32) {
match x {
0 => (),
_ =>(),
_ => (),
}
}

Expand All @@ -91,7 +91,7 @@ fn test_nested_match(x: u32) {
1 => {
let _ = 42;
},
_ =>(),
_ => (),
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ async fn async_test_void_if_fun(b: bool) {
async fn async_test_void_match(x: u32) {
match x {
0 => (),
_ =>(),
_ => (),
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/needless_return.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ LL | | return;
= help: remove `return`

error: unneeded `return` statement
--> $DIR/needless_return.rs:87:13
--> $DIR/needless_return.rs:87:14
|
LL | _ => return,
| ^^^^^^^
| ^^^^^^
|
= help: replace `return` with a unit value

Expand All @@ -136,10 +136,10 @@ LL | | return;
= help: remove `return`

error: unneeded `return` statement
--> $DIR/needless_return.rs:98:13
--> $DIR/needless_return.rs:98:14
|
LL | _ => return,
| ^^^^^^^
| ^^^^^^
|
= help: replace `return` with a unit value

Expand Down Expand Up @@ -296,10 +296,10 @@ LL | | return;
= help: remove `return`

error: unneeded `return` statement
--> $DIR/needless_return.rs:207:13
--> $DIR/needless_return.rs:207:14
|
LL | _ => return,
| ^^^^^^^
| ^^^^^^
|
= help: replace `return` with a unit value

Expand Down

0 comments on commit 9cf57d0

Please sign in to comment.