diff options
| author | bors <bors@rust-lang.org> | 2021-04-12 18:00:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-12 18:00:38 +0000 |
| commit | 2a96bc434b08894584cf569b0d86f4774bf8c47d (patch) | |
| tree | 98722dbe75972e92d718abe9a709a92cb6129087 | |
| parent | 411c0df1d09813e58e009db4cd0e0161b0de1d03 (diff) | |
| parent | e6c67ad2bfd7bb9b4777bb95aea7c4ce70e2dd8a (diff) | |
| download | rust-2a96bc434b08894584cf569b0d86f4774bf8c47d.tar.gz rust-2a96bc434b08894584cf569b0d86f4774bf8c47d.zip | |
Auto merge of #7067 - TaKO8Ki:fix-false-negative-on-needless-return, r=llogiq
Fix a false negative on `needless return` closes #7042 changelog: fix a false negative on `needless return`
| -rw-r--r-- | clippy_lints/src/returns.rs | 1 | ||||
| -rw-r--r-- | tests/ui/needless_return.fixed | 88 | ||||
| -rw-r--r-- | tests/ui/needless_return.rs | 88 | ||||
| -rw-r--r-- | tests/ui/needless_return.stderr | 122 |
4 files changed, 268 insertions, 31 deletions
diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index af772cf4a14..3a6151dce71 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -223,6 +223,7 @@ fn check_final_expr<'tcx>( }, _ => (), }, + ExprKind::DropTemps(expr) => check_final_expr(cx, expr, None, RetReplacement::Empty), _ => (), } } diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index 82d95cc041f..5c4fd466c04 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,4 +1,5 @@ // run-rustfix +// edition:2018 #![allow(unused)] #![allow( @@ -125,10 +126,85 @@ mod issue6501 { } } -fn main() { - let _ = test_end_of_fn(); - let _ = test_no_semicolon(); - let _ = test_if_block(); - let _ = test_match(true); - test_closure(); +async fn async_test_end_of_fn() -> bool { + if true { + // no error! + return true; + } + true +} + +async fn async_test_no_semicolon() -> bool { + true +} + +async fn async_test_if_block() -> bool { + if true { + true + } else { + false + } +} + +async fn async_test_match(x: bool) -> bool { + match x { + true => false, + false => { + true + }, + } +} + +async fn async_test_closure() { + let _ = || { + true + }; + let _ = || true; +} + +async fn async_test_macro_call() -> i32 { + return the_answer!(); +} + +async fn async_test_void_fun() { + +} + +async fn async_test_void_if_fun(b: bool) { + if b { + + } else { + + } +} + +async fn async_test_void_match(x: u32) { + match x { + 0 => (), + _ => {}, + } +} + +async fn async_read_line() -> String { + use std::io::BufRead; + let stdin = ::std::io::stdin(); + return stdin.lock().lines().next().unwrap().unwrap(); } + +async fn async_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() + } +} + +async fn async_test_return_in_macro() { + needed_return!(10); + needed_return!(0); +} + +fn main() {} diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 8a471f802e1..34811db7413 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,4 +1,5 @@ // run-rustfix +// edition:2018 #![allow(unused)] #