about summary refs log tree commit diff
diff options
context:
space:
mode:
authorfeniljain <fkjainco@gmail.com>2023-04-05 20:03:45 +0530
committerfeniljain <fkjainco@gmail.com>2023-04-05 20:03:45 +0530
commit9cf57d0a8f95c51b0faeda4ce5c5b4cd629f1cae (patch)
treee3ba6ec127f0c311dfeef390c8eb122c002f38b9
parentb499b7dc73f3571e2627a34a93e3079cab848bbc (diff)
downloadrust-9cf57d0a8f95c51b0faeda4ce5c5b4cd629f1cae.tar.gz
rust-9cf57d0a8f95c51b0faeda4ce5c5b4cd629f1cae.zip
fix(needles_return): correct span selection for text replacement
-rw-r--r--clippy_lints/src/returns.rs2
-rw-r--r--tests/ui/needless_return.fixed6
-rw-r--r--tests/ui/needless_return.stderr12
3 files changed, 10 insertions, 10 deletions
diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs
index b8172b74dc0..df126d7617e 100644
--- a/clippy_lints/src/returns.rs
+++ b/clippy_lints/src/returns.rs
@@ -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
diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed
index 47a9f031a42..57c08996ce2 100644
--- a/tests/ui/needless_return.fixed
+++ b/tests/ui/needless_return.fixed
@@ -81,7 +81,7 @@ fn test_void_if_fun(b: bool) {
 fn test_void_match(x: u32) {
     match x {
         0 => (),
-        _ =>(),
+        _ => (),
     }
 }
 
@@ -91,7 +91,7 @@ fn test_nested_match(x: u32) {
         1 => {
             let _ = 42;
         },
-        _ =>(),
+        _ => (),
     }
 }
 
@@ -196,7 +196,7 @@ async fn async_test_void_if_fun(b: bool) {
 async fn async_test_void_match(x: u32) {
     match x {
         0 => (),
-        _ =>(),
+        _ => (),
     }
 }
 
diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr
index 5d471a3c521..87d0cd3e14c 100644
--- a/tests/ui/needless_return.stderr
+++ b/tests/ui/needless_return.stderr
@@ -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
 
@@ -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
 
@@ -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