File tree 5 files changed +40
-41
lines changed
5 files changed +40
-41
lines changed Original file line number Diff line number Diff line change @@ -160,10 +160,6 @@ fn check_final_expr<'tcx>(
160
160
span : Option < Span > ,
161
161
replacement : RetReplacement ,
162
162
) {
163
- if last_statement_borrows ( cx, expr) {
164
- return ;
165
- }
166
-
167
163
match expr. kind {
168
164
// simple return is always "bad"
169
165
ExprKind :: Ret ( ref inner) => {
Original file line number Diff line number Diff line change @@ -16,8 +16,7 @@ declare_clippy_lint! {
16
16
/// less readable. Depending on formatting they can make a `break` or `return`
17
17
/// statement look like a function call.
18
18
///
19
- /// **Known problems:** The lint currently misses unit return types in types,
20
- /// e.g., the `F` in `fn generic_unit<F: Fn() -> ()>(f: F) { .. }`.
19
+ /// **Known problems:** None.
21
20
///
22
21
/// **Example:**
23
22
/// ```rust
Original file line number Diff line number Diff line change @@ -69,24 +69,20 @@ fn test_void_match(x: u32) {
69
69
}
70
70
}
71
71
72
- mod no_lint_if_stmt_borrows {
73
- mod issue_5858 {
74
- fn read_line() -> String {
75
- use std::io::BufRead;
76
- let stdin = ::std::io::stdin();
77
- return stdin.lock().lines().next().unwrap().unwrap();
78
- }
72
+ fn read_line() -> String {
73
+ use std::io::BufRead;
74
+ let stdin = ::std::io::stdin();
75
+ return stdin.lock().lines().next().unwrap().unwrap();
76
+ }
79
77
80
- fn read_line2(value: bool) -> String {
81
- if value {
82
- use std::io::BufRead;
83
- let stdin = ::std::io::stdin();
84
- let _a = stdin.lock().lines().next().unwrap().unwrap();
85
- return String::from("test");
86
- } else {
87
- return String::new();
88
- }
89
- }
78
+ fn borrows_but_not_last(value: bool) -> String {
79
+ if value {
80
+ use std::io::BufRead;
81
+ let stdin = ::std::io::stdin();
82
+ let _a = stdin.lock().lines().next().unwrap().unwrap();
83
+ String::from("test")
84
+ } else {
85
+ String::new()
90
86
}
91
87
}
92
88
Original file line number Diff line number Diff line change @@ -69,24 +69,20 @@ fn test_void_match(x: u32) {
69
69
}
70
70
}
71
71
72
- mod no_lint_if_stmt_borrows {
73
- mod issue_5858 {
74
- fn read_line ( ) -> String {
75
- use std:: io:: BufRead ;
76
- let stdin = :: std:: io:: stdin ( ) ;
77
- return stdin. lock ( ) . lines ( ) . next ( ) . unwrap ( ) . unwrap ( ) ;
78
- }
72
+ fn read_line ( ) -> String {
73
+ use std:: io:: BufRead ;
74
+ let stdin = :: std:: io:: stdin ( ) ;
75
+ return stdin. lock ( ) . lines ( ) . next ( ) . unwrap ( ) . unwrap ( ) ;
76
+ }
79
77
80
- fn read_line2 ( value : bool ) -> String {
81
- if value {
82
- use std:: io:: BufRead ;
83
- let stdin = :: std:: io:: stdin ( ) ;
84
- let _a = stdin. lock ( ) . lines ( ) . next ( ) . unwrap ( ) . unwrap ( ) ;
85
- return String :: from ( "test" ) ;
86
- } else {
87
- return String :: new ( ) ;
88
- }
89
- }
78
+ fn borrows_but_not_last ( value : bool ) -> String {
79
+ if value {
80
+ use std:: io:: BufRead ;
81
+ let stdin = :: std:: io:: stdin ( ) ;
82
+ let _a = stdin. lock ( ) . lines ( ) . next ( ) . unwrap ( ) . unwrap ( ) ;
83
+ return String :: from ( "test" ) ;
84
+ } else {
85
+ return String :: new ( ) ;
90
86
}
91
87
}
92
88
Original file line number Diff line number Diff line change @@ -72,5 +72,17 @@ error: unneeded `return` statement
72
72
LL | _ => return,
73
73
| ^^^^^^ help: replace `return` with an empty block: `{}`
74
74
75
- error: aborting due to 12 previous errors
75
+ error: unneeded `return` statement
76
+ --> $DIR/needless_return.rs:83:9
77
+ |
78
+ LL | return String::from("test");
79
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
80
+
81
+ error: unneeded `return` statement
82
+ --> $DIR/needless_return.rs:85:9
83
+ |
84
+ LL | return String::new();
85
+ | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
86
+
87
+ error: aborting due to 14 previous errors
76
88
You can’t perform that action at this time.
0 commit comments