Skip to content

Commit 5ae1e97

Browse files
committed
Add test case
1 parent 6c698bb commit 5ae1e97

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

tests/ui/unnecessary_wrap.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,20 @@ fn func1(a: bool, b: bool) -> Option<i32> {
1717
}
1818
}
1919

20+
// should be linted
21+
fn func2(a: bool, b: bool) -> Option<i32> {
22+
if a && b {
23+
return Some(10);
24+
}
25+
if a {
26+
Some(20)
27+
} else {
28+
Some(30)
29+
}
30+
}
31+
2032
// public fns should not be linted
21-
pub fn func2(a: bool) -> Option<i32> {
33+
pub fn func3(a: bool) -> Option<i32> {
2234
if a {
2335
Some(1)
2436
} else {
@@ -27,7 +39,7 @@ pub fn func2(a: bool) -> Option<i32> {
2739
}
2840

2941
// should not be linted
30-
fn func3(a: bool) -> Option<i32> {
42+
fn func4(a: bool) -> Option<i32> {
3143
if a {
3244
Some(1)
3345
} else {
@@ -36,22 +48,22 @@ fn func3(a: bool) -> Option<i32> {
3648
}
3749

3850
// should be linted
39-
fn func4() -> Option<i32> {
51+
fn func5() -> Option<i32> {
4052
Some(1)
4153
}
4254

4355
// should not be linted
44-
fn func5() -> Option<i32> {
56+
fn func6() -> Option<i32> {
4557
None
4658
}
4759

4860
// should be linted
49-
fn func6() -> Result<i32, ()> {
61+
fn func7() -> Result<i32, ()> {
5062
Ok(1)
5163
}
5264

5365
// should not be linted
54-
fn func7(a: bool) -> Result<i32, ()> {
66+
fn func8(a: bool) -> Result<i32, ()> {
5567
if a {
5668
Ok(1)
5769
} else {
@@ -60,12 +72,12 @@ fn func7(a: bool) -> Result<i32, ()> {
6072
}
6173

6274
// should not be linted
63-
fn func8(a: bool) -> Result<i32, ()> {
75+
fn func9(a: bool) -> Result<i32, ()> {
6476
Err(())
6577
}
6678

6779
fn main() {
6880
// method calls are not linted
6981
func1(true, true);
70-
func2(true);
82+
func2(true, true);
7183
}

tests/ui/unnecessary_wrap.stderr

+33-7
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,64 @@ LL | } else {
2626
...
2727

2828
error: this function returns unnecessarily wrapping data
29-
--> $DIR/unnecessary_wrap.rs:39:1
29+
--> $DIR/unnecessary_wrap.rs:21:1
3030
|
31-
LL | / fn func4() -> Option<i32> {
31+
LL | / fn func2(a: bool, b: bool) -> Option<i32> {
32+
LL | | if a && b {
33+
LL | | return Some(10);
34+
LL | | }
35+
... |
36+
LL | | }
37+
LL | | }
38+
| |_^
39+
|
40+
help: remove `Option` from the return type...
41+
|
42+
LL | fn func2(a: bool, b: bool) -> i32 {
43+
| ^^^
44+
help: ...and change the returning expressions
45+
|
46+
LL | return 10;
47+
LL | }
48+
LL | if a {
49+
LL | 20
50+
LL | } else {
51+
LL | 30
52+
|
53+
54+
error: this function returns unnecessarily wrapping data
55+
--> $DIR/unnecessary_wrap.rs:51:1
56+
|
57+
LL | / fn func5() -> Option<i32> {
3258
LL | | Some(1)
3359
LL | | }
3460
| |_^
3561
|
3662
help: remove `Option` from the return type...
3763
|
38-
LL | fn func4() -> i32 {
64+
LL | fn func5() -> i32 {
3965
| ^^^
4066
help: ...and change the returning expressions
4167
|
4268
LL | 1
4369
|
4470

4571
error: this function returns unnecessarily wrapping data
46-
--> $DIR/unnecessary_wrap.rs:49:1
72+
--> $DIR/unnecessary_wrap.rs:61:1
4773
|
48-
LL | / fn func6() -> Result<i32, ()> {
74+
LL | / fn func7() -> Result<i32, ()> {
4975
LL | | Ok(1)
5076
LL | | }
5177
| |_^
5278
|
5379
help: remove `Result` from the return type...
5480
|
55-
LL | fn func6() -> i32 {
81+
LL | fn func7() -> i32 {
5682
| ^^^
5783
help: ...and change the returning expressions
5884
|
5985
LL | 1
6086
|
6187

62-
error: aborting due to 3 previous errors
88+
error: aborting due to 4 previous errors
6389

0 commit comments

Comments
 (0)