about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/returns.rs4
-rw-r--r--clippy_lints/src/unused_unit.rs3
-rw-r--r--tests/ui/needless_return.fixed30
-rw-r--r--tests/ui/needless_return.rs30
-rw-r--r--tests/ui/needless_return.stderr14
5 files changed, 40 insertions, 41 deletions
diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs
index 4d91f9be999..3c5541e64b4 100644
--- a/clippy_lints/src/returns.rs
+++ b/clippy_lints/src/returns.rs
@@ -160,10 +160,6 @@ fn check_final_expr<'tcx>(
     span: Option<Span>,
     replacement: RetReplacement,
 ) {
-    if last_statement_borrows(cx, expr) {
-        return;
-    }
-
     match expr.kind {
         // simple return is always "bad"
         ExprKind::Ret(ref inner) => {
diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs
index e322e402535..7548c6afa97 100644
--- a/clippy_lints/src/unused_unit.rs
+++ b/clippy_lints/src/unused_unit.rs
@@ -16,8 +16,7 @@ declare_clippy_lint! {
     /// less readable. Depending on formatting they can make a `break` or `return`
     /// statement look like a function call.
     ///
-    /// **Known problems:** The lint currently misses unit return types in types,
-    /// e.g., the `F` in `fn generic_unit<F: Fn() -> ()>(f: F) { .. }`.
+    /// **Known problems:** None.
     ///
     /// **Example:**
     /// ```rust
diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed
index b795516f999..d849e093da7 100644
--- a/tests/ui/needless_return.fixed
+++ b/tests/ui/needless_return.fixed
@@ -69,24 +69,20 @@ fn test_void_match(x: u32) {
     }
 }
 
-mod no_lint_if_stmt_borrows {
-    mod issue_5858 {
-        fn read_line() -> String {
-            use std::io::BufRead;
-            let stdin = ::std::io::stdin();
-            return stdin.lock().lines().next().unwrap().unwrap();
-        }
+fn read_line() -> String {
+    use std::io::BufRead;
+    let stdin = ::std::io::stdin();
+    return stdin.lock().lines().next().unwrap().unwrap();
+}
 
-        fn read_line2(value: bool) -> String {
-            if value {
-                use std::io::BufRead;
-                let stdin = ::std::io::stdin();
-                let _a = stdin.lock().lines().next().unwrap().unwrap();
-                return String::from("test");
-            } else {
-                return String::new();
-            }
-        }
+fn borrows_but_not_last(value: bool) -> String {
+    if value {
+        use std::io::BufRead;
+        let stdin = ::std::io::stdin();
+        let _a = stdin.lock().lines().next().unwrap().unwrap();
+        String::from("test")
+    } else {
+        String::new()
     }
 }
 
diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs
index 3547991935d..29f2bd1852a 100644
--- a/tests/ui/needless_return.rs
+++ b/tests/ui/needless_return.rs
@@ -69,24 +69,20 @@ fn test_void_match(x: u32) {
     }
 }
 
-mod no_lint_if_stmt_borrows {
-    mod issue_5858 {
-        fn read_line() -> String {
-            use std::io::BufRead;
-            let stdin = ::std::io::stdin();
-            return stdin.lock().lines().next().unwrap().unwrap();
-        }
+fn read_line() -> String {
+    use std::io::BufRead;
+    let stdin = ::std::io::stdin();
+    return stdin.lock().lines().next().unwrap().unwrap();
+}
 
-        fn read_line2(value: bool) -> String {
-            if value {
-                use std::io::BufRead;
-                let stdin = ::std::io::stdin();
-                let _a = stdin.lock().lines().next().unwrap().unwrap();
-                return String::from("test");
-            } else {
-                return String::new();
-            }
-        }
+fn borrows_but_not_last(value: bool) -> String {
+    if value {
+        use std::io::BufRead;
+        let stdin = ::std::io::stdin();
+        let _a = stdin.lock().lines().next().unwrap().unwrap();
+        return String::from("test");
+    } else {
+        return String::new();
     }
 }
 
diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr
index c34eecbcbb6..f73c833a801 100644
--- a/tests/ui/needless_return.stderr
+++ b/tests/ui/needless_return.stderr
@@ -72,5 +72,17 @@ error: unneeded `return` statement
 LL |         _ => return,
    |              ^^^^^^ help: replace `return` with an empty block: `{}`
 
-error: aborting due to 12 previous errors
+error: unneeded `return` statement
+  --> $DIR/needless_return.rs:83:9
+   |
+LL |         return String::from("test");
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
+
+error: unneeded `return` statement
+  --> $DIR/needless_return.rs:85:9
+   |
+LL |         return String::new();
+   |         ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
+
+error: aborting due to 14 previous errors