Skip to content

Commit 436d429

Browse files
committed
Add two more tests, allow 2 other lints.
1 parent 84716e4 commit 436d429

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

tests/ui/redundant_pattern_matching.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(clippy::all)]
22
#![warn(clippy::redundant_pattern_matching)]
3+
#![allow(clippy::unit_arg, clippy::let_unit_value)]
34

45
fn main() {
56
if let Ok(_) = Ok::<i32, i32>(42) {}
@@ -61,8 +62,17 @@ fn main() {
6162

6263
let _ = does_something();
6364
let _ = returns_unit();
65+
66+
let opt = Some(false);
67+
let x = if let Some(_) = opt { true } else { false };
68+
takes_bool(x);
69+
let y = if let Some(_) = opt {};
70+
takes_unit(y);
6471
}
6572

73+
fn takes_bool(x: bool) {}
74+
fn takes_unit(x: ()) {}
75+
6676
fn does_something() -> bool {
6777
if let Ok(_) = Ok::<i32, i32>(4) {
6878
true

tests/ui/redundant_pattern_matching.stderr

+15-11
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ LL | | };
7979
| |_____^ help: try this: `None::<()>.is_none()`
8080

8181
error: redundant pattern matching, consider using `is_none()`
82-
--> $DIR/redundant_pattern_matching.rs:56:15
82+
--> $DIR/redundant_pattern_matching.rs:56:13
8383
|
84-
LL | let foo = match None::<()> {
85-
| _______________^
84+
LL | let _ = match None::<()> {
85+
| _____________^
8686
LL | | Some(_) => false,
8787
LL | | None => true,
8888
LL | | };
@@ -94,16 +94,20 @@ error: redundant pattern matching, consider using `is_ok()`
9494
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
9595
| -------^^^^^--------------------------------------------- help: try this: `Ok::<usize, ()>(4).is_ok()`
9696

97-
error: this let-binding has unit value
98-
--> $DIR/redundant_pattern_matching.rs:64:5
97+
error: redundant pattern matching, consider using `is_some()`
98+
--> $DIR/redundant_pattern_matching.rs:67:20
9999
|
100-
LL | let _ = returns_unit();
101-
| ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `returns_unit();`
100+
LL | let x = if let Some(_) = opt { true } else { false };
101+
| -------^^^^^^^------------------------------ help: try this: `opt.is_some()`
102+
103+
error: redundant pattern matching, consider using `is_some()`
104+
--> $DIR/redundant_pattern_matching.rs:69:20
102105
|
103-
= note: `-D clippy::let-unit-value` implied by `-D warnings`
106+
LL | let y = if let Some(_) = opt {};
107+
| -------^^^^^^^--------- help: try this: `opt.is_some()`
104108

105109
error: redundant pattern matching, consider using `is_ok()`
106-
--> $DIR/redundant_pattern_matching.rs:68:12
110+
--> $DIR/redundant_pattern_matching.rs:77:12
107111
|
108112
LL | if let Ok(_) = Ok::<i32, i32>(4) {
109113
| _____- ^^^^^
@@ -114,7 +118,7 @@ LL | | }
114118
| |_____- help: try this: `Ok::<i32, i32>(4).is_ok()`
115119

116120
error: redundant pattern matching, consider using `is_ok()`
117-
--> $DIR/redundant_pattern_matching.rs:76:12
121+
--> $DIR/redundant_pattern_matching.rs:85:12
118122
|
119123
LL | if let Ok(_) = Ok::<i32, i32>(4) {
120124
| _____- ^^^^^
@@ -124,5 +128,5 @@ LL | | false
124128
LL | | };
125129
| |_____- help: try this: `Ok::<i32, i32>(4).is_ok()`
126130

127-
error: aborting due to 15 previous errors
131+
error: aborting due to 16 previous errors
128132

0 commit comments

Comments
 (0)