Skip to content

Commit 31b4b3e

Browse files
committed
implicit_return: make it use a rustfix test
1 parent d493fef commit 31b4b3e

File tree

3 files changed

+116
-11
lines changed

3 files changed

+116
-11
lines changed

tests/ui/implicit_return.fixed

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// run-rustfix
2+
3+
#![warn(clippy::implicit_return)]
4+
#![allow(clippy::needless_return, unused)]
5+
6+
fn test_end_of_fn() -> bool {
7+
if true {
8+
// no error!
9+
return true;
10+
}
11+
12+
return true
13+
}
14+
15+
#[allow(clippy::needless_bool)]
16+
fn test_if_block() -> bool {
17+
if true {
18+
return true
19+
} else {
20+
return false
21+
}
22+
}
23+
24+
#[allow(clippy::match_bool)]
25+
#[rustfmt::skip]
26+
fn test_match(x: bool) -> bool {
27+
match x {
28+
true => return false,
29+
false => { return true },
30+
}
31+
}
32+
33+
#[allow(clippy::match_bool, clippy::needless_return)]
34+
fn test_match_with_unreachable(x: bool) -> bool {
35+
match x {
36+
true => return false,
37+
false => unreachable!(),
38+
}
39+
}
40+
41+
#[allow(clippy::never_loop)]
42+
fn test_loop() -> bool {
43+
loop {
44+
return true;
45+
}
46+
}
47+
48+
#[allow(clippy::never_loop)]
49+
fn test_loop_with_block() -> bool {
50+
loop {
51+
{
52+
return true;
53+
}
54+
}
55+
}
56+
57+
#[allow(clippy::never_loop)]
58+
fn test_loop_with_nests() -> bool {
59+
loop {
60+
if true {
61+
return true;
62+
} else {
63+
let _ = true;
64+
}
65+
}
66+
}
67+
68+
#[allow(clippy::redundant_pattern_matching)]
69+
fn test_loop_with_if_let() -> bool {
70+
loop {
71+
if let Some(x) = Some(true) {
72+
return x;
73+
}
74+
}
75+
}
76+
77+
fn test_closure() {
78+
#[rustfmt::skip]
79+
let _ = || { return true };
80+
let _ = || return true;
81+
}
82+
83+
fn test_panic() -> bool {
84+
panic!()
85+
}
86+
87+
fn test_return_macro() -> String {
88+
return format!("test {}", "test")
89+
}
90+
91+
fn main() {
92+
let _ = test_end_of_fn();
93+
let _ = test_if_block();
94+
let _ = test_match(true);
95+
let _ = test_match_with_unreachable(true);
96+
let _ = test_loop();
97+
let _ = test_loop_with_block();
98+
let _ = test_loop_with_nests();
99+
let _ = test_loop_with_if_let();
100+
test_closure();
101+
let _ = test_return_macro();
102+
}

tests/ui/implicit_return.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
// run-rustfix
2+
13
#![warn(clippy::implicit_return)]
4+
#![allow(clippy::needless_return, unused)]
25

36
fn test_end_of_fn() -> bool {
47
if true {

tests/ui/implicit_return.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
11
error: missing return statement
2-
--> $DIR/implicit_return.rs:9:5
2+
--> $DIR/implicit_return.rs:12:5
33
|
44
LL | true
55
| ^^^^ help: add `return` as shown: `return true`
66
|
77
= note: `-D clippy::implicit-return` implied by `-D warnings`
88

99
error: missing return statement
10-
--> $DIR/implicit_return.rs:15:9
10+
--> $DIR/implicit_return.rs:18:9
1111
|
1212
LL | true
1313
| ^^^^ help: add `return` as shown: `return true`
1414

1515
error: missing return statement
16-
--> $DIR/implicit_return.rs:17:9
16+
--> $DIR/implicit_return.rs:20:9
1717
|
1818
LL | false
1919
| ^^^^^ help: add `return` as shown: `return false`
2020

2121
error: missing return statement
22-
--> $DIR/implicit_return.rs:25:17
22+
--> $DIR/implicit_return.rs:28:17
2323
|
2424
LL | true => false,
2525
| ^^^^^ help: add `return` as shown: `return false`
2626

2727
error: missing return statement
28-
--> $DIR/implicit_return.rs:26:20
28+
--> $DIR/implicit_return.rs:29:20
2929
|
3030
LL | false => { true },
3131
| ^^^^ help: add `return` as shown: `return true`
3232

3333
error: missing return statement
34-
--> $DIR/implicit_return.rs:41:9
34+
--> $DIR/implicit_return.rs:44:9
3535
|
3636
LL | break true;
3737
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
3838

3939
error: missing return statement
40-
--> $DIR/implicit_return.rs:49:13
40+
--> $DIR/implicit_return.rs:52:13
4141
|
4242
LL | break true;
4343
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
4444

4545
error: missing return statement
46-
--> $DIR/implicit_return.rs:58:13
46+
--> $DIR/implicit_return.rs:61:13
4747
|
4848
LL | break true;
4949
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
5050

5151
error: missing return statement
52-
--> $DIR/implicit_return.rs:76:18
52+
--> $DIR/implicit_return.rs:79:18
5353
|
5454
LL | let _ = || { true };
5555
| ^^^^ help: add `return` as shown: `return true`
5656

5757
error: missing return statement
58-
--> $DIR/implicit_return.rs:77:16
58+
--> $DIR/implicit_return.rs:80:16
5959
|
6060
LL | let _ = || true;
6161
| ^^^^ help: add `return` as shown: `return true`
6262

6363
error: missing return statement
64-
--> $DIR/implicit_return.rs:85:5
64+
--> $DIR/implicit_return.rs:88:5
6565
|
6666
LL | format!("test {}", "test")
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`

0 commit comments

Comments
 (0)