early return removed

This commit is contained in:
jrqc 2020-08-14 09:25:26 +03:00
parent 96efaee552
commit baa4cb1cdd
5 changed files with 40 additions and 41 deletions

View file

@ -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) => {

View file

@ -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

View file

@ -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()
}
}

View file

@ -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();
}
}

View file

@ -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