Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 342ce3d

Browse files
committed
fix reviewer comments
1 parent fb6bf1e commit 342ce3d

8 files changed

+47
-92
lines changed

clippy_lints/src/matches/match_like_matches.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,9 @@ fn find_bool_lit(ex: &ExprKind<'_>) -> Option<bool> {
183183

184184
fn is_some(path_kind: PatKind<'_>) -> bool {
185185
match path_kind {
186-
PatKind::TupleStruct(QPath::Resolved(_, path), patterns, _) if is_wild(&patterns[0]) => {
186+
PatKind::TupleStruct(QPath::Resolved(_, path), [first, ..], _) if is_wild(first) => {
187187
let name = path.segments[0].ident;
188-
if name.name == rustc_span::sym::Some {
189-
return true;
190-
}
191-
false
188+
name.name == rustc_span::sym::Some
192189
},
193190
_ => false,
194191
}

clippy_lints/src/matches/redundant_pattern_match.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ fn find_sugg_for_if_let<'tcx>(
188188
pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) {
189189
if arms.len() == 2 {
190190
let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind);
191-
let found_good_method = found_good_method(cx, arms, node_pair);
192191

193-
if let Some(good_method) = found_good_method {
192+
if let Some(good_method) = found_good_method(cx, arms, node_pair) {
194193
let span = expr.span.to(op.span);
195194
let result_expr = match &op.kind {
196195
ExprKind::AddrOf(_, _, borrowed) => borrowed,
@@ -310,6 +309,9 @@ fn get_good_method<'a>(cx: &LateContext<'_>, arms: &[Arm<'_>], path_left: &QPath
310309
"Ok" => {
311310
find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultOk), "is_ok()", "is_err()")
312311
},
312+
"Err" => {
313+
find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultErr), "is_err()", "is_ok()")
314+
},
313315
"Some" => find_good_method_for_matches_macro(
314316
cx,
315317
arms,

tests/ui/redundant_pattern_matching_option.fixed

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,12 @@ fn issue10726() {
9595

9696
Some(42).is_none();
9797

98-
Some(42).is_none();
99-
100-
Some(42).is_some();
101-
102-
None::<()>.is_none();
103-
104-
None::<()>.is_none();
98+
None::<()>.is_some();
10599

106100
None::<()>.is_none();
107101

108-
None::<()>.is_some();
102+
match Some(42) {
103+
Some(21) => true,
104+
_ => false,
105+
};
109106
}

tests/ui/redundant_pattern_matching_option.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,38 +111,23 @@ fn issue10726() {
111111
_ => false,
112112
};
113113

114-
match Some(42) {
115-
Some(_) => false,
116-
_ => true,
117-
};
118-
119114
match Some(42) {
120115
None => true,
121116
_ => false,
122117
};
123118

124-
match Some(42) {
125-
None => false,
126-
_ => true,
127-
};
128-
129119
match None::<()> {
130-
Some(_) => false,
131-
_ => true,
132-
};
133-
134-
match None::<()> {
135-
Some(_) => false,
136-
_ => true,
120+
Some(_) => true,
121+
_ => false,
137122
};
138123

139124
match None::<()> {
140125
None => true,
141126
_ => false,
142127
};
143128

144-
match None::<()> {
145-
None => false,
146-
_ => true,
129+
match Some(42) {
130+
Some(21) => true,
131+
_ => false,
147132
};
148133
}

tests/ui/redundant_pattern_matching_option.stderr

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -161,64 +161,28 @@ error: redundant pattern matching, consider using `is_none()`
161161
--> $DIR/redundant_pattern_matching_option.rs:114:5
162162
|
163163
LL | / match Some(42) {
164-
LL | | Some(_) => false,
165-
LL | | _ => true,
166-
LL | | };
167-
| |_____^ help: try this: `Some(42).is_none()`
168-
169-
error: redundant pattern matching, consider using `is_none()`
170-
--> $DIR/redundant_pattern_matching_option.rs:119:5
171-
|
172-
LL | / match Some(42) {
173164
LL | | None => true,
174165
LL | | _ => false,
175166
LL | | };
176167
| |_____^ help: try this: `Some(42).is_none()`
177168

178169
error: redundant pattern matching, consider using `is_some()`
179-
--> $DIR/redundant_pattern_matching_option.rs:124:5
180-
|
181-
LL | / match Some(42) {
182-
LL | | None => false,
183-
LL | | _ => true,
184-
LL | | };
185-
| |_____^ help: try this: `Some(42).is_some()`
186-
187-
error: redundant pattern matching, consider using `is_none()`
188-
--> $DIR/redundant_pattern_matching_option.rs:129:5
189-
|
190-
LL | / match None::<()> {
191-
LL | | Some(_) => false,
192-
LL | | _ => true,
193-
LL | | };
194-
| |_____^ help: try this: `None::<()>.is_none()`
195-
196-
error: redundant pattern matching, consider using `is_none()`
197-
--> $DIR/redundant_pattern_matching_option.rs:134:5
170+
--> $DIR/redundant_pattern_matching_option.rs:119:5
198171
|
199172
LL | / match None::<()> {
200-
LL | | Some(_) => false,
201-
LL | | _ => true,
173+
LL | | Some(_) => true,
174+
LL | | _ => false,
202175
LL | | };
203-
| |_____^ help: try this: `None::<()>.is_none()`
176+
| |_____^ help: try this: `None::<()>.is_some()`
204177

205178
error: redundant pattern matching, consider using `is_none()`
206-
--> $DIR/redundant_pattern_matching_option.rs:139:5
179+
--> $DIR/redundant_pattern_matching_option.rs:124:5
207180
|
208181
LL | / match None::<()> {
209182
LL | | None => true,
210183
LL | | _ => false,
211184
LL | | };
212185
| |_____^ help: try this: `None::<()>.is_none()`
213186

214-
error: redundant pattern matching, consider using `is_some()`
215-
--> $DIR/redundant_pattern_matching_option.rs:144:5
216-
|
217-
LL | / match None::<()> {
218-
LL | | None => false,
219-
LL | | _ => true,
220-
LL | | };
221-
| |_____^ help: try this: `None::<()>.is_some()`
222-
223-
error: aborting due to 30 previous errors
187+
error: aborting due to 26 previous errors
224188

tests/ui/redundant_pattern_matching_result.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ fn issue10726() {
114114

115115
Ok::<i32, i32>(42).is_err();
116116

117+
Err::<i32, i32>(42).is_ok();
118+
117119
Err::<i32, i32>(42).is_err();
118120

119-
Err::<i32, i32>(42).is_ok();
121+
match Ok::<i32, i32>(42) {
122+
Ok(21) => true,
123+
_ => false,
124+
};
120125
}

tests/ui/redundant_pattern_matching_result.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,22 @@ fn issue10726() {
134134
};
135135

136136
match Ok::<i32, i32>(42) {
137-
Ok(_) => false,
138-
_ => true,
137+
Err(_) => true,
138+
_ => false,
139139
};
140140

141141
match Err::<i32, i32>(42) {
142-
Ok(_) => false,
143-
_ => true,
142+
Ok(_) => true,
143+
_ => false,
144144
};
145145

146146
match Err::<i32, i32>(42) {
147-
Ok(_) => true,
147+
Err(_) => true,
148+
_ => false,
149+
};
150+
151+
match Ok::<i32, i32>(42) {
152+
Ok(21) => true,
148153
_ => false,
149154
};
150155
}

tests/ui/redundant_pattern_matching_result.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,28 +163,28 @@ error: redundant pattern matching, consider using `is_err()`
163163
--> $DIR/redundant_pattern_matching_result.rs:136:5
164164
|
165165
LL | / match Ok::<i32, i32>(42) {
166-
LL | | Ok(_) => false,
167-
LL | | _ => true,
166+
LL | | Err(_) => true,
167+
LL | | _ => false,
168168
LL | | };
169169
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
170170

171-
error: redundant pattern matching, consider using `is_err()`
171+
error: redundant pattern matching, consider using `is_ok()`
172172
--> $DIR/redundant_pattern_matching_result.rs:141:5
173173
|
174174
LL | / match Err::<i32, i32>(42) {
175-
LL | | Ok(_) => false,
176-
LL | | _ => true,
175+
LL | | Ok(_) => true,
176+
LL | | _ => false,
177177
LL | | };
178-
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
178+
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
179179

180-
error: redundant pattern matching, consider using `is_ok()`
180+
error: redundant pattern matching, consider using `is_err()`
181181
--> $DIR/redundant_pattern_matching_result.rs:146:5
182182
|
183183
LL | / match Err::<i32, i32>(42) {
184-
LL | | Ok(_) => true,
184+
LL | | Err(_) => true,
185185
LL | | _ => false,
186186
LL | | };
187-
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
187+
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
188188

189189
error: aborting due to 26 previous errors
190190

0 commit comments

Comments
 (0)