Skip to content

Commit 84716e4

Browse files
committed
Add more testcases for redundant_pattern_matching
These should make sure that, when the suggestions are fixed, they are fixed for all these cases.
1 parent 0d85d7e commit 84716e4

File tree

2 files changed

+83
-11
lines changed

2 files changed

+83
-11
lines changed

tests/ui/redundant_pattern_matching.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,30 @@ fn main() {
5151
Some(_) => false,
5252
None => true,
5353
};
54+
55+
let _ = match None::<()> {
56+
Some(_) => false,
57+
None => true,
58+
};
59+
60+
let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
61+
62+
let _ = does_something();
63+
let _ = returns_unit();
64+
}
65+
66+
fn does_something() -> bool {
67+
if let Ok(_) = Ok::<i32, i32>(4) {
68+
true
69+
} else {
70+
false
71+
}
72+
}
73+
74+
fn returns_unit() {
75+
if let Ok(_) = Ok::<i32, i32>(4) {
76+
true
77+
} else {
78+
false
79+
};
5480
}
Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: redundant pattern matching, consider using `is_ok()`
2-
--> $DIR/redundant_pattern_matching.rs:5:12
2+
--> $DIR/redundant_pattern_matching.rs:6:12
33
|
44
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
55
| -------^^^^^------------------------ help: try this: `Ok::<i32, i32>(42).is_ok()`
66
|
77
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
88

99
error: redundant pattern matching, consider using `is_err()`
10-
--> $DIR/redundant_pattern_matching.rs:7:12
10+
--> $DIR/redundant_pattern_matching.rs:8:12
1111
|
1212
LL | if let Err(_) = Err::<i32, i32>(42) {}
1313
| -------^^^^^^------------------------- help: try this: `Err::<i32, i32>(42).is_err()`
1414

1515
error: redundant pattern matching, consider using `is_none()`
16-
--> $DIR/redundant_pattern_matching.rs:9:12
16+
--> $DIR/redundant_pattern_matching.rs:10:12
1717
|
1818
LL | if let None = None::<()> {}
1919
| -------^^^^---------------- help: try this: `None::<()>.is_none()`
2020

2121
error: redundant pattern matching, consider using `is_some()`
22-
--> $DIR/redundant_pattern_matching.rs:11:12
22+
--> $DIR/redundant_pattern_matching.rs:12:12
2323
|
2424
LL | if let Some(_) = Some(42) {}
2525
| -------^^^^^^^-------------- help: try this: `Some(42).is_some()`
2626

2727
error: redundant pattern matching, consider using `is_ok()`
28-
--> $DIR/redundant_pattern_matching.rs:25:5
28+
--> $DIR/redundant_pattern_matching.rs:26:5
2929
|
3030
LL | / match Ok::<i32, i32>(42) {
3131
LL | | Ok(_) => true,
@@ -34,7 +34,7 @@ LL | | };
3434
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
3535

3636
error: redundant pattern matching, consider using `is_err()`
37-
--> $DIR/redundant_pattern_matching.rs:30:5
37+
--> $DIR/redundant_pattern_matching.rs:31:5
3838
|
3939
LL | / match Ok::<i32, i32>(42) {
4040
LL | | Ok(_) => false,
@@ -43,7 +43,7 @@ LL | | };
4343
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
4444

4545
error: redundant pattern matching, consider using `is_err()`
46-
--> $DIR/redundant_pattern_matching.rs:35:5
46+
--> $DIR/redundant_pattern_matching.rs:36:5
4747
|
4848
LL | / match Err::<i32, i32>(42) {
4949
LL | | Ok(_) => false,
@@ -52,7 +52,7 @@ LL | | };
5252
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
5353

5454
error: redundant pattern matching, consider using `is_ok()`
55-
--> $DIR/redundant_pattern_matching.rs:40:5
55+
--> $DIR/redundant_pattern_matching.rs:41:5
5656
|
5757
LL | / match Err::<i32, i32>(42) {
5858
LL | | Ok(_) => true,
@@ -61,7 +61,7 @@ LL | | };
6161
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
6262

6363
error: redundant pattern matching, consider using `is_some()`
64-
--> $DIR/redundant_pattern_matching.rs:45:5
64+
--> $DIR/redundant_pattern_matching.rs:46:5
6565
|
6666
LL | / match Some(42) {
6767
LL | | Some(_) => true,
@@ -70,13 +70,59 @@ LL | | };
7070
| |_____^ help: try this: `Some(42).is_some()`
7171

7272
error: redundant pattern matching, consider using `is_none()`
73-
--> $DIR/redundant_pattern_matching.rs:50:5
73+
--> $DIR/redundant_pattern_matching.rs:51:5
7474
|
7575
LL | / match None::<()> {
7676
LL | | Some(_) => false,
7777
LL | | None => true,
7878
LL | | };
7979
| |_____^ help: try this: `None::<()>.is_none()`
8080

81-
error: aborting due to 10 previous errors
81+
error: redundant pattern matching, consider using `is_none()`
82+
--> $DIR/redundant_pattern_matching.rs:56:15
83+
|
84+
LL | let foo = match None::<()> {
85+
| _______________^
86+
LL | | Some(_) => false,
87+
LL | | None => true,
88+
LL | | };
89+
| |_____^ help: try this: `None::<()>.is_none()`
90+
91+
error: redundant pattern matching, consider using `is_ok()`
92+
--> $DIR/redundant_pattern_matching.rs:61:20
93+
|
94+
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
95+
| -------^^^^^--------------------------------------------- help: try this: `Ok::<usize, ()>(4).is_ok()`
96+
97+
error: this let-binding has unit value
98+
--> $DIR/redundant_pattern_matching.rs:64:5
99+
|
100+
LL | let _ = returns_unit();
101+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `returns_unit();`
102+
|
103+
= note: `-D clippy::let-unit-value` implied by `-D warnings`
104+
105+
error: redundant pattern matching, consider using `is_ok()`
106+
--> $DIR/redundant_pattern_matching.rs:68:12
107+
|
108+
LL | if let Ok(_) = Ok::<i32, i32>(4) {
109+
| _____- ^^^^^
110+
LL | | true
111+
LL | | } else {
112+
LL | | false
113+
LL | | }
114+
| |_____- help: try this: `Ok::<i32, i32>(4).is_ok()`
115+
116+
error: redundant pattern matching, consider using `is_ok()`
117+
--> $DIR/redundant_pattern_matching.rs:76:12
118+
|
119+
LL | if let Ok(_) = Ok::<i32, i32>(4) {
120+
| _____- ^^^^^
121+
LL | | true
122+
LL | | } else {
123+
LL | | false
124+
LL | | };
125+
| |_____- help: try this: `Ok::<i32, i32>(4).is_ok()`
126+
127+
error: aborting due to 15 previous errors
82128

0 commit comments

Comments
 (0)