forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
no_effect
]: suggest adding return
if applicable
- Loading branch information
Showing
3 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#![allow(dead_code, unused)] | ||
#![no_main] | ||
|
||
use std::ops::ControlFlow; | ||
|
||
fn a() -> u32 { | ||
{ | ||
0u32; | ||
} | ||
0 | ||
} | ||
|
||
async fn b() -> u32 { | ||
{ | ||
0u32; | ||
} | ||
0 | ||
} | ||
|
||
type C = i32; | ||
async fn c() -> C { | ||
{ | ||
0i32 as C; | ||
} | ||
0 | ||
} | ||
|
||
fn d() -> u128 { | ||
{ | ||
// not last stmt | ||
0u128; | ||
println!("lol"); | ||
} | ||
0 | ||
} | ||
|
||
fn e() -> u32 { | ||
{ | ||
// mismatched types | ||
0u16; | ||
} | ||
0 | ||
} | ||
|
||
fn f() -> [u16; 1] { | ||
{ | ||
[1u16]; | ||
} | ||
[1] | ||
} | ||
|
||
fn g() -> ControlFlow<()> { | ||
{ | ||
ControlFlow::Break::<()>(()); | ||
} | ||
ControlFlow::Continue(()) | ||
} | ||
|
||
fn h() -> Vec<u16> { | ||
{ | ||
// function call, so this won't trigger `no_effect`. not an issue with this change, but the | ||
// lint itself (but also not really.) | ||
vec![0u16]; | ||
} | ||
vec![] | ||
} | ||
|
||
fn i() -> () { | ||
{ | ||
(); | ||
} | ||
() | ||
} | ||
|
||
fn j() { | ||
{ | ||
// does not suggest on function without explicit return type | ||
(); | ||
} | ||
() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
error: unneeded unit return type | ||
--> $DIR/no_effect_return.rs:68:7 | ||
| | ||
LL | fn i() -> () { | ||
| ^^^^^^ help: remove the `-> ()` | ||
| | ||
= note: `-D clippy::unused-unit` implied by `-D warnings` | ||
|
||
error: unneeded unit expression | ||
--> $DIR/no_effect_return.rs:72:5 | ||
| | ||
LL | () | ||
| ^^ help: remove the final `()` | ||
|
||
error: unneeded unit expression | ||
--> $DIR/no_effect_return.rs:80:5 | ||
| | ||
LL | () | ||
| ^^ help: remove the final `()` | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:8:9 | ||
| | ||
LL | 0u32; | ||
| -^^^^ | ||
| | | ||
| help: did you mean to return it?: `return` | ||
| | ||
= note: `-D clippy::no-effect` implied by `-D warnings` | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:15:9 | ||
| | ||
LL | 0u32; | ||
| -^^^^ | ||
| | | ||
| help: did you mean to return it?: `return` | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:23:9 | ||
| | ||
LL | 0i32 as C; | ||
| -^^^^^^^^^ | ||
| | | ||
| help: did you mean to return it?: `return` | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:31:9 | ||
| | ||
LL | 0u128; | ||
| ^^^^^^ | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:40:9 | ||
| | ||
LL | 0u16; | ||
| ^^^^^ | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:47:9 | ||
| | ||
LL | [1u16]; | ||
| -^^^^^^ | ||
| | | ||
| help: did you mean to return it?: `return` | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:54:9 | ||
| | ||
LL | ControlFlow::Break::<()>(()); | ||
| -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| help: did you mean to return it?: `return` | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:70:9 | ||
| | ||
LL | (); | ||
| -^^ | ||
| | | ||
| help: did you mean to return it?: `return` | ||
|
||
error: statement with no effect | ||
--> $DIR/no_effect_return.rs:78:9 | ||
| | ||
LL | (); | ||
| ^^^ | ||
|
||
error: aborting due to 12 previous errors | ||
|