Skip to content

Commit baa4cb1

Browse files
committed
early return removed
1 parent 96efaee commit baa4cb1

File tree

5 files changed

+40
-41
lines changed

5 files changed

+40
-41
lines changed

clippy_lints/src/returns.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ fn check_final_expr<'tcx>(
160160
span: Option<Span>,
161161
replacement: RetReplacement,
162162
) {
163-
if last_statement_borrows(cx, expr) {
164-
return;
165-
}
166-
167163
match expr.kind {
168164
// simple return is always "bad"
169165
ExprKind::Ret(ref inner) => {

clippy_lints/src/unused_unit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ declare_clippy_lint! {
1616
/// less readable. Depending on formatting they can make a `break` or `return`
1717
/// statement look like a function call.
1818
///
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.
2120
///
2221
/// **Example:**
2322
/// ```rust

tests/ui/needless_return.fixed

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,20 @@ fn test_void_match(x: u32) {
6969
}
7070
}
7171

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+
}
7977

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()
9086
}
9187
}
9288

tests/ui/needless_return.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,20 @@ fn test_void_match(x: u32) {
6969
}
7070
}
7171

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+
}
7977

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();
9086
}
9187
}
9288

tests/ui/needless_return.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,17 @@ error: unneeded `return` statement
7272
LL | _ => return,
7373
| ^^^^^^ help: replace `return` with an empty block: `{}`
7474

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
7688

0 commit comments

Comments
 (0)