Skip to content

Commit 66e5fd1

Browse files
committed
update tests
Update redundant_guard.rs Update redundant_guard.rs
1 parent 83ce827 commit 66e5fd1

8 files changed

+55
-41
lines changed

clippy_lints/src/redundant_guard.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,31 @@ use std::borrow::Cow;
1313

1414
declare_clippy_lint! {
1515
/// ### What it does
16+
/// Checks for unnecessary guards in match expressions.
1617
///
1718
/// ### Why is this bad?
19+
/// It's more complex and much less readable.
1820
///
1921
/// ### Example
20-
/// ```rust
21-
/// // example code where clippy issues a warning
22+
/// ```rust,ignore
23+
/// match x {
24+
/// Some(x) if matches!(x, Some(1)) => ..,
25+
/// Some(x) if x == Some(2) => ..,
26+
/// _ => todo!(),
27+
/// }
2228
/// ```
2329
/// Use instead:
24-
/// ```rust
25-
/// // example code which does not raise clippy warning
30+
/// ```rust,ignore
31+
/// match x {
32+
/// Some(Some(1)) => ..,
33+
/// Some(Some(2)) => ..,
34+
/// _ => todo!(),
35+
/// }
2636
/// ```
2737
#[clippy::version = "1.72.0"]
2838
pub REDUNDANT_GUARD,
29-
nursery,
30-
"default lint descriptiona"
39+
complexity,
40+
"checks for unnecessary guards in match expressions"
3141
}
3242
declare_lint_pass!(RedundantGuard => [REDUNDANT_GUARD]);
3343

tests/ui/match_expr_like_matches_macro.fixed

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
unreachable_patterns,
66
dead_code,
77
clippy::equatable_if_let,
8-
clippy::needless_borrowed_reference
8+
clippy::needless_borrowed_reference,
9+
clippy::redundant_guard
910
)]
1011

1112
fn main() {

tests/ui/match_expr_like_matches_macro.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
unreachable_patterns,
66
dead_code,
77
clippy::equatable_if_let,
8-
clippy::needless_borrowed_reference
8+
clippy::needless_borrowed_reference,
9+
clippy::redundant_guard
910
)]
1011

1112
fn main() {

tests/ui/match_expr_like_matches_macro.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: match expression looks like `matches!` macro
2-
--> $DIR/match_expr_like_matches_macro.rs:15:14
2+
--> $DIR/match_expr_like_matches_macro.rs:16:14
33
|
44
LL | let _y = match x {
55
| ______________^
@@ -11,7 +11,7 @@ LL | | };
1111
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
1212

1313
error: redundant pattern matching, consider using `is_some()`
14-
--> $DIR/match_expr_like_matches_macro.rs:21:14
14+
--> $DIR/match_expr_like_matches_macro.rs:22:14
1515
|
1616
LL | let _w = match x {
1717
| ______________^
@@ -23,7 +23,7 @@ LL | | };
2323
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
2424

2525
error: redundant pattern matching, consider using `is_none()`
26-
--> $DIR/match_expr_like_matches_macro.rs:27:14
26+
--> $DIR/match_expr_like_matches_macro.rs:28:14
2727
|
2828
LL | let _z = match x {
2929
| ______________^
@@ -33,7 +33,7 @@ LL | | };
3333
| |_____^ help: try this: `x.is_none()`
3434

3535
error: match expression looks like `matches!` macro
36-
--> $DIR/match_expr_like_matches_macro.rs:33:15
36+
--> $DIR/match_expr_like_matches_macro.rs:34:15
3737
|
3838
LL | let _zz = match x {
3939
| _______________^
@@ -43,13 +43,13 @@ LL | | };
4343
| |_____^ help: try this: `!matches!(x, Some(r) if r == 0)`
4444

4545
error: if let .. else expression looks like `matches!` macro
46-
--> $DIR/match_expr_like_matches_macro.rs:39:16
46+
--> $DIR/match_expr_like_matches_macro.rs:40:16
4747
|
4848
LL | let _zzz = if let Some(5) = x { true } else { false };
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `matches!(x, Some(5))`
5050

5151
error: match expression looks like `matches!` macro
52-
--> $DIR/match_expr_like_matches_macro.rs:63:20
52+
--> $DIR/match_expr_like_matches_macro.rs:64:20
5353
|
5454
LL | let _ans = match x {
5555
| ____________________^
@@ -60,7 +60,7 @@ LL | | };
6060
| |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
6161

6262
error: match expression looks like `matches!` macro
63-
--> $DIR/match_expr_like_matches_macro.rs:73:20
63+
--> $DIR/match_expr_like_matches_macro.rs:74:20
6464
|
6565
LL | let _ans = match x {
6666
| ____________________^
@@ -73,7 +73,7 @@ LL | | };
7373
| |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
7474

7575
error: match expression looks like `matches!` macro
76-
--> $DIR/match_expr_like_matches_macro.rs:83:20
76+
--> $DIR/match_expr_like_matches_macro.rs:84:20
7777
|
7878
LL | let _ans = match x {
7979
| ____________________^
@@ -84,7 +84,7 @@ LL | | };
8484
| |_________^ help: try this: `!matches!(x, E::B(_) | E::C)`
8585

8686
error: match expression looks like `matches!` macro
87-
--> $DIR/match_expr_like_matches_macro.rs:143:18
87+
--> $DIR/match_expr_like_matches_macro.rs:144:18
8888
|
8989
LL | let _z = match &z {
9090
| __________________^
@@ -94,7 +94,7 @@ LL | | };
9494
| |_________^ help: try this: `matches!(z, Some(3))`
9595

9696
error: match expression looks like `matches!` macro
97-
--> $DIR/match_expr_like_matches_macro.rs:152:18
97+
--> $DIR/match_expr_like_matches_macro.rs:153:18
9898
|
9999
LL | let _z = match &z {
100100
| __________________^
@@ -104,7 +104,7 @@ LL | | };
104104
| |_________^ help: try this: `matches!(&z, Some(3))`
105105

106106
error: match expression looks like `matches!` macro
107-
--> $DIR/match_expr_like_matches_macro.rs:169:21
107+
--> $DIR/match_expr_like_matches_macro.rs:170:21
108108
|
109109
LL | let _ = match &z {
110110
| _____________________^
@@ -114,7 +114,7 @@ LL | | };
114114
| |_____________^ help: try this: `matches!(&z, AnEnum::X)`
115115

116116
error: match expression looks like `matches!` macro
117-
--> $DIR/match_expr_like_matches_macro.rs:183:20
117+
--> $DIR/match_expr_like_matches_macro.rs:184:20
118118
|
119119
LL | let _res = match &val {
120120
| ____________________^
@@ -124,7 +124,7 @@ LL | | };
124124
| |_________^ help: try this: `matches!(&val, &Some(ref _a))`
125125

126126
error: match expression looks like `matches!` macro
127-
--> $DIR/match_expr_like_matches_macro.rs:195:20
127+
--> $DIR/match_expr_like_matches_macro.rs:196:20
128128
|
129129
LL | let _res = match &val {
130130
| ____________________^
@@ -134,7 +134,7 @@ LL | | };
134134
| |_________^ help: try this: `matches!(&val, &Some(ref _a))`
135135

136136
error: match expression looks like `matches!` macro
137-
--> $DIR/match_expr_like_matches_macro.rs:253:14
137+
--> $DIR/match_expr_like_matches_macro.rs:254:14
138138
|
139139
LL | let _y = match Some(5) {
140140
| ______________^

tests/ui/shadow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@aux-build:proc_macro_derive.rs
22

33
#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
4-
#![allow(clippy::let_unit_value, clippy::needless_if)]
4+
#![allow(clippy::let_unit_value, clippy::needless_if, clippy::redundant_guard)]
55

66
extern crate proc_macro_derive;
77

tests/ui/single_match.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
unused,
55
clippy::uninlined_format_args,
66
clippy::needless_if,
7+
clippy::redundant_guard,
78
clippy::redundant_pattern_matching
89
)]
910
fn dummy() {}

tests/ui/single_match.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
unused,
55
clippy::uninlined_format_args,
66
clippy::needless_if,
7+
clippy::redundant_guard,
78
clippy::redundant_pattern_matching
89
)]
910
fn dummy() {}

tests/ui/single_match.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
2-
--> $DIR/single_match.rs:14:5
2+
--> $DIR/single_match.rs:15:5
33
|
44
LL | / match x {
55
LL | | Some(y) => {
@@ -18,7 +18,7 @@ LL ~ };
1818
|
1919

2020
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
21-
--> $DIR/single_match.rs:22:5
21+
--> $DIR/single_match.rs:23:5
2222
|
2323
LL | / match x {
2424
LL | | // Note the missing block braces.
@@ -30,7 +30,7 @@ LL | | }
3030
| |_____^ help: try this: `if let Some(y) = x { println!("{:?}", y) }`
3131

3232
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
33-
--> $DIR/single_match.rs:31:5
33+
--> $DIR/single_match.rs:32:5
3434
|
3535
LL | / match z {
3636
LL | | (2..=3, 7..=9) => dummy(),
@@ -39,7 +39,7 @@ LL | | };
3939
| |_____^ help: try this: `if let (2..=3, 7..=9) = z { dummy() }`
4040

4141
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
42-
--> $DIR/single_match.rs:60:5
42+
--> $DIR/single_match.rs:61:5
4343
|
4444
LL | / match x {
4545
LL | | Some(y) => dummy(),
@@ -48,7 +48,7 @@ LL | | };
4848
| |_____^ help: try this: `if let Some(y) = x { dummy() }`
4949

5050
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
51-
--> $DIR/single_match.rs:65:5
51+
--> $DIR/single_match.rs:66:5
5252
|
5353
LL | / match y {
5454
LL | | Ok(y) => dummy(),
@@ -57,7 +57,7 @@ LL | | };
5757
| |_____^ help: try this: `if let Ok(y) = y { dummy() }`
5858

5959
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
60-
--> $DIR/single_match.rs:72:5
60+
--> $DIR/single_match.rs:73:5
6161
|
6262
LL | / match c {
6363
LL | | Cow::Borrowed(..) => dummy(),
@@ -66,7 +66,7 @@ LL | | };
6666
| |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }`
6767

6868
error: you seem to be trying to use `match` for an equality check. Consider using `if`
69-
--> $DIR/single_match.rs:93:5
69+
--> $DIR/single_match.rs:94:5
7070
|
7171
LL | / match x {
7272
LL | | "test" => println!(),
@@ -75,7 +75,7 @@ LL | | }
7575
| |_____^ help: try this: `if x == "test" { println!() }`
7676

7777
error: you seem to be trying to use `match` for an equality check. Consider using `if`
78-
--> $DIR/single_match.rs:106:5
78+
--> $DIR/single_match.rs:107:5
7979
|
8080
LL | / match x {
8181
LL | | Foo::A => println!(),
@@ -84,7 +84,7 @@ LL | | }
8484
| |_____^ help: try this: `if x == Foo::A { println!() }`
8585

8686
error: you seem to be trying to use `match` for an equality check. Consider using `if`
87-
--> $DIR/single_match.rs:112:5
87+
--> $DIR/single_match.rs:113:5
8888
|
8989
LL | / match x {
9090
LL | | FOO_C => println!(),
@@ -93,7 +93,7 @@ LL | | }
9393
| |_____^ help: try this: `if x == FOO_C { println!() }`
9494

9595
error: you seem to be trying to use `match` for an equality check. Consider using `if`
96-
--> $DIR/single_match.rs:117:5
96+
--> $DIR/single_match.rs:118:5
9797
|
9898
LL | / match &&x {
9999
LL | | Foo::A => println!(),
@@ -102,7 +102,7 @@ LL | | }
102102
| |_____^ help: try this: `if x == Foo::A { println!() }`
103103

104104
error: you seem to be trying to use `match` for an equality check. Consider using `if`
105-
--> $DIR/single_match.rs:123:5
105+
--> $DIR/single_match.rs:124:5
106106
|
107107
LL | / match &x {
108108
LL | | Foo::A => println!(),
@@ -111,7 +111,7 @@ LL | | }
111111
| |_____^ help: try this: `if x == &Foo::A { println!() }`
112112

113113
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
114-
--> $DIR/single_match.rs:140:5
114+
--> $DIR/single_match.rs:141:5
115115
|
116116
LL | / match x {
117117
LL | | Bar::A => println!(),
@@ -120,7 +120,7 @@ LL | | }
120120
| |_____^ help: try this: `if let Bar::A = x { println!() }`
121121

122122
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
123-
--> $DIR/single_match.rs:148:5
123+
--> $DIR/single_match.rs:149:5
124124
|
125125
LL | / match x {
126126
LL | | None => println!(),
@@ -129,7 +129,7 @@ LL | | };
129129
| |_____^ help: try this: `if let None = x { println!() }`
130130

131131
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
132-
--> $DIR/single_match.rs:170:5
132+
--> $DIR/single_match.rs:171:5
133133
|
134134
LL | / match x {
135135
LL | | (Some(_), _) => {},
@@ -138,7 +138,7 @@ LL | | }
138138
| |_____^ help: try this: `if let (Some(_), _) = x {}`
139139

140140
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
141-
--> $DIR/single_match.rs:176:5
141+
--> $DIR/single_match.rs:177:5
142142
|
143143
LL | / match x {
144144
LL | | (Some(E::V), _) => todo!(),
@@ -147,7 +147,7 @@ LL | | }
147147
| |_____^ help: try this: `if let (Some(E::V), _) = x { todo!() }`
148148

149149
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
150-
--> $DIR/single_match.rs:182:5
150+
--> $DIR/single_match.rs:183:5
151151
|
152152
LL | / match (Some(42), Some(E::V), Some(42)) {
153153
LL | | (.., Some(E::V), _) => {},
@@ -156,7 +156,7 @@ LL | | }
156156
| |_____^ help: try this: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}`
157157

158158
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
159-
--> $DIR/single_match.rs:254:5
159+
--> $DIR/single_match.rs:255:5
160160
|
161161
LL | / match bar {
162162
LL | | Some(v) => unsafe {
@@ -176,7 +176,7 @@ LL + } }
176176
|
177177

178178
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
179-
--> $DIR/single_match.rs:262:5
179+
--> $DIR/single_match.rs:263:5
180180
|
181181
LL | / match bar {
182182
LL | | #[rustfmt::skip]

0 commit comments

Comments
 (0)