about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPierre-Andre Gagnon <pagagnon@gmail.com>2021-02-18 17:32:55 -0500
committerPierre-Andre Gagnon <pagagnon@gmail.com>2021-02-18 17:32:55 -0500
commita78271b8611d7ab7709976dfb94ae36b668ac42b (patch)
treeb808f52c585bf8f5c5e87f3aa8c9ff040b1b1762
parent6165cccf7e43cf4ca2234e84dcf7060c7d89ef45 (diff)
downloadrust-a78271b8611d7ab7709976dfb94ae36b668ac42b.tar.gz
rust-a78271b8611d7ab7709976dfb94ae36b668ac42b.zip
Changed fn body suggestion msg
-rw-r--r--clippy_lints/src/unnecessary_wraps.rs14
-rw-r--r--tests/ui/unnecessary_wraps.rs18
-rw-r--r--tests/ui/unnecessary_wraps.stderr14
3 files changed, 31 insertions, 15 deletions
diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs
index b097d531bc4..607585125a4 100644
--- a/clippy_lints/src/unnecessary_wraps.rs
+++ b/clippy_lints/src/unnecessary_wraps.rs
@@ -131,11 +131,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
         });
 
         if can_sugg && !suggs.is_empty() {
-            let (lint_msg, return_type_suggestion_msg, return_type_suggestion) = if inner_type.is_unit() {
+            let (lint_msg, return_type_sugg_msg, return_type_sugg, body_sugg_msg) = if inner_type.is_unit() {
                 (
                     "this function's return value is unnecessary".to_string(),
                     "remove the return type...".to_string(),
                     snippet(cx, fn_decl.output.span(), "..").to_string(),
+                    "...and then remove returned values",
                 )
             } else {
                 (
@@ -145,21 +146,18 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
                     ),
                     format!("remove `{}` from the return type...", return_type_label),
                     inner_type.to_string(),
+                    "...and then change returning expressions",
                 )
             };
 
             span_lint_and_then(cx, UNNECESSARY_WRAPS, span, lint_msg.as_str(), |diag| {
                 diag.span_suggestion(
                     fn_decl.output.span(),
-                    return_type_suggestion_msg.as_str(),
-                    return_type_suggestion,
-                    Applicability::MaybeIncorrect,
-                );
-                diag.multipart_suggestion(
-                    "...and then change the returning expressions",
-                    suggs,
+                    return_type_sugg_msg.as_str(),
+                    return_type_sugg,
                     Applicability::MaybeIncorrect,
                 );
+                diag.multipart_suggestion(body_sugg_msg, suggs, Applicability::MaybeIncorrect);
             });
         }
     }
diff --git a/tests/ui/unnecessary_wraps.rs b/tests/ui/unnecessary_wraps.rs
index 5aaa99bbe5a..a510263e67d 100644
--- a/tests/ui/unnecessary_wraps.rs
+++ b/tests/ui/unnecessary_wraps.rs
@@ -141,6 +141,24 @@ fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
     }
 }
 
+// should not be linted
+fn issue_6640_3() -> Option<()> {
+    if true {
+        Some(())
+    } else {
+        None
+    }
+}
+
+// should not be linted
+fn issue_6640_4() -> Result<(), ()> {
+    if true {
+        Ok(())
+    } else {
+        Err(())
+    }
+}
+
 fn main() {
     // method calls are not linted
     func1(true, true);
diff --git a/tests/ui/unnecessary_wraps.stderr b/tests/ui/unnecessary_wraps.stderr
index 40effb89499..9a861c61a46 100644
--- a/tests/ui/unnecessary_wraps.stderr
+++ b/tests/ui/unnecessary_wraps.stderr
@@ -15,7 +15,7 @@ help: remove `Option` from the return type...
    |
 LL | fn func1(a: bool, b: bool) -> i32 {
    |                               ^^^
-help: ...and then change the returning expressions
+help: ...and then change returning expressions
    |
 LL |         return 42;
 LL |     }
@@ -41,7 +41,7 @@ help: remove `Option` from the return type...
    |
 LL | fn func2(a: bool, b: bool) -> i32 {
    |                               ^^^
-help: ...and then change the returning expressions
+help: ...and then change returning expressions
    |
 LL |         return 10;
 LL |     }
@@ -63,7 +63,7 @@ help: remove `Option` from the return type...
    |
 LL | fn func5() -> i32 {
    |               ^^^
-help: ...and then change the returning expressions
+help: ...and then change returning expressions
    |
 LL |     1
    |
@@ -80,7 +80,7 @@ help: remove `Result` from the return type...
    |
 LL | fn func7() -> i32 {
    |               ^^^
-help: ...and then change the returning expressions
+help: ...and then change returning expressions
    |
 LL |     1
    |
@@ -97,7 +97,7 @@ help: remove `Option` from the return type...
    |
 LL |     fn func12() -> i32 {
    |                    ^^^
-help: ...and then change the returning expressions
+help: ...and then change returning expressions
    |
 LL |         1
    |
@@ -118,7 +118,7 @@ help: remove the return type...
    |
 LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> {
    |                                      ^^^^^^^^^^
-help: ...and then change the returning expressions
+help: ...and then remove returned values
    |
 LL |         return ;
 LL |     }
@@ -144,7 +144,7 @@ help: remove the return type...
    |
 LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
    |                                      ^^^^^^^^^^^^^^^
-help: ...and then change the returning expressions
+help: ...and then remove returned values
    |
 LL |         return ;
 LL |     }