806a9dfddd
Don't warn on proc macro generated code in `needless_return` Fixes #13458 Fixes #13457 Fixes #13467 Fixes #13479 Fixes #13481 Fixes #13526 Fixes #13486 The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does* fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`. The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context. "Hide whitespace" helps a bit for reviewing the proc macro detection change changelog: none
682 lines
14 KiB
Plaintext
682 lines
14 KiB
Plaintext
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:29:5
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
= note: `-D clippy::needless-return` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::needless_return)]`
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:33:5
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:38:5
|
|
|
|
|
LL | return true;;;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;;;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:43:5
|
|
|
|
|
LL | return true;; ; ;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;; ; ;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:48:9
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:50:9
|
|
|
|
|
LL | return false;
|
|
| ^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return false;
|
|
LL + false
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:56:17
|
|
|
|
|
LL | true => return false,
|
|
| ^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL | true => false,
|
|
| ~~~~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:58:13
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:65:9
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:67:16
|
|
|
|
|
LL | let _ = || return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL | let _ = || true;
|
|
| ~~~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:71:5
|
|
|
|
|
LL | return the_answer!();
|
|
| ^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return the_answer!();
|
|
LL + the_answer!()
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:74:21
|
|
|
|
|
LL | fn test_void_fun() {
|
|
| _____________________^
|
|
LL | | return;
|
|
| |__________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - fn test_void_fun() {
|
|
LL - return;
|
|
LL + fn test_void_fun() {
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:79:11
|
|
|
|
|
LL | if b {
|
|
| ___________^
|
|
LL | | return;
|
|
| |______________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - if b {
|
|
LL - return;
|
|
LL + if b {
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:81:13
|
|
|
|
|
LL | } else {
|
|
| _____________^
|
|
LL | | return;
|
|
| |______________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - } else {
|
|
LL - return;
|
|
LL + } else {
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:89:14
|
|
|
|
|
LL | _ => return,
|
|
| ^^^^^^
|
|
|
|
|
help: replace `return` with a unit value
|
|
|
|
|
LL | _ => (),
|
|
| ~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:97:24
|
|
|
|
|
LL | let _ = 42;
|
|
| ________________________^
|
|
LL | | return;
|
|
| |__________________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - let _ = 42;
|
|
LL - return;
|
|
LL + let _ = 42;
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:100:14
|
|
|
|
|
LL | _ => return,
|
|
| ^^^^^^
|
|
|
|
|
help: replace `return` with a unit value
|
|
|
|
|
LL | _ => (),
|
|
| ~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:113:9
|
|
|
|
|
LL | return String::from("test");
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return String::from("test");
|
|
LL + String::from("test")
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:115:9
|
|
|
|
|
LL | return String::new();
|
|
| ^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return String::new();
|
|
LL + String::new()
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:137:32
|
|
|
|
|
LL | bar.unwrap_or_else(|_| return)
|
|
| ^^^^^^
|
|
|
|
|
help: replace `return` with an empty block
|
|
|
|
|
LL | bar.unwrap_or_else(|_| {})
|
|
| ~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:141:21
|
|
|
|
|
LL | let _ = || {
|
|
| _____________________^
|
|
LL | | return;
|
|
| |__________________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - let _ = || {
|
|
LL - return;
|
|
LL + let _ = || {
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:144:20
|
|
|
|
|
LL | let _ = || return;
|
|
| ^^^^^^
|
|
|
|
|
help: replace `return` with an empty block
|
|
|
|
|
LL | let _ = || {};
|
|
| ~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:150:32
|
|
|
|
|
LL | res.unwrap_or_else(|_| return Foo)
|
|
| ^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL | res.unwrap_or_else(|_| Foo)
|
|
| ~~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:159:5
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:163:5
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:168:9
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:170:9
|
|
|
|
|
LL | return false;
|
|
| ^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return false;
|
|
LL + false
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:176:17
|
|
|
|
|
LL | true => return false,
|
|
| ^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL | true => false,
|
|
| ~~~~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:178:13
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:185:9
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return true;
|
|
LL + true
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:187:16
|
|
|
|
|
LL | let _ = || return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL | let _ = || true;
|
|
| ~~~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:191:5
|
|
|
|
|
LL | return the_answer!();
|
|
| ^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return the_answer!();
|
|
LL + the_answer!()
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:194:33
|
|
|
|
|
LL | async fn async_test_void_fun() {
|
|
| _________________________________^
|
|
LL | | return;
|
|
| |__________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - async fn async_test_void_fun() {
|
|
LL - return;
|
|
LL + async fn async_test_void_fun() {
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:199:11
|
|
|
|
|
LL | if b {
|
|
| ___________^
|
|
LL | | return;
|
|
| |______________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - if b {
|
|
LL - return;
|
|
LL + if b {
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:201:13
|
|
|
|
|
LL | } else {
|
|
| _____________^
|
|
LL | | return;
|
|
| |______________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - } else {
|
|
LL - return;
|
|
LL + } else {
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:209:14
|
|
|
|
|
LL | _ => return,
|
|
| ^^^^^^
|
|
|
|
|
help: replace `return` with a unit value
|
|
|
|
|
LL | _ => (),
|
|
| ~~
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:222:9
|
|
|
|
|
LL | return String::from("test");
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return String::from("test");
|
|
LL + String::from("test")
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:224:9
|
|
|
|
|
LL | return String::new();
|
|
| ^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return String::new();
|
|
LL + String::new()
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:240:5
|
|
|
|
|
LL | return format!("Hello {}", "world!");
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return format!("Hello {}", "world!");
|
|
LL + format!("Hello {}", "world!")
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:281:9
|
|
|
|
|
LL | return true;
|
|
| ^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL ~ true
|
|
LL | } else {
|
|
LL | return false;
|
|
LL ~ }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:283:9
|
|
|
|
|
LL | return false;
|
|
| ^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL ~ false
|
|
LL ~ }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:290:13
|
|
|
|
|
LL | return 10;
|
|
| ^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL ~ 10
|
|
LL | },
|
|
...
|
|
LL | },
|
|
LL ~ }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:293:13
|
|
|
|
|
LL | return 100;
|
|
| ^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL ~ 100
|
|
LL | },
|
|
LL ~ }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:301:9
|
|
|
|
|
LL | return 0;
|
|
| ^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL ~ 0
|
|
LL ~ }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:308:13
|
|
|
|
|
LL | return *(x as *const isize);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL ~ *(x as *const isize)
|
|
LL | } else {
|
|
LL | return !*(x as *const isize);
|
|
LL ~ }
|
|
LL ~ }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:310:13
|
|
|
|
|
LL | return !*(x as *const isize);
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL ~ !*(x as *const isize)
|
|
LL ~ }
|
|
LL ~ }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:317:20
|
|
|
|
|
LL | let _ = 42;
|
|
| ____________________^
|
|
LL | |
|
|
LL | | return;
|
|
| |______________^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - let _ = 42;
|
|
LL -
|
|
LL - return;
|
|
LL + let _ = 42;
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:324:20
|
|
|
|
|
LL | let _ = 42; return;
|
|
| ^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - let _ = 42; return;
|
|
LL + let _ = 42;
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:336:9
|
|
|
|
|
LL | return Ok(format!("ok!"));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return Ok(format!("ok!"));
|
|
LL + Ok(format!("ok!"))
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:338:9
|
|
|
|
|
LL | return Err(format!("err!"));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return Err(format!("err!"));
|
|
LL + Err(format!("err!"))
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:344:9
|
|
|
|
|
LL | return if true { 1 } else { 2 };
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return if true { 1 } else { 2 };
|
|
LL + if true { 1 } else { 2 }
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:348:9
|
|
|
|
|
LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return` and wrap the sequence with parentheses
|
|
|
|
|
LL - return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
|
|
LL + (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 })
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:369:5
|
|
|
|
|
LL | return { "a".to_string() } + "b" + { "c" };
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return` and wrap the sequence with parentheses
|
|
|
|
|
LL - return { "a".to_string() } + "b" + { "c" };
|
|
LL + ({ "a".to_string() } + "b" + { "c" })
|
|
|
|
|
|
|
error: unneeded `return` statement
|
|
--> tests/ui/needless_return.rs:373:5
|
|
|
|
|
LL | return "".split("").next().unwrap().to_string();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove `return`
|
|
|
|
|
LL - return "".split("").next().unwrap().to_string();
|
|
LL + "".split("").next().unwrap().to_string()
|
|
|
|
|
|
|
error: aborting due to 54 previous errors
|
|
|