Skip to content

Commit f17cca6

Browse files
committed
Fix clippy warnings
1 parent c8012ef commit f17cca6

10 files changed

+135
-112
lines changed

clippy_lints/src/matches.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,13 +1782,14 @@ mod redundant_pattern_match {
17821782
}
17831783

17841784
// Gets all the the temporaries in an expression which need to be dropped afterwards.
1785+
#[allow(clippy::too_many_lines)]
17851786
fn get_temporary_tys(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<Ty<'tcx>> {
17861787
fn f(
17871788
addr_of: bool,
17881789
tcx: TyCtxt<'tcx>,
17891790
typeck: &TypeckResults<'tcx>,
17901791
expr: &'tcx Expr<'tcx>,
1791-
res: &mut Vec<Ty<'tcx>>,
1792+
result: &mut Vec<Ty<'tcx>>,
17921793
) {
17931794
match expr.kind {
17941795
ExprKind::ConstBlock(_)
@@ -1808,78 +1809,78 @@ mod redundant_pattern_match {
18081809
| ExprKind::MethodCall(_, _, [], _) => (),
18091810
ExprKind::MethodCall(_, _, [self_arg, args @ ..], _) => {
18101811
if addr_of {
1811-
res.push(typeck.expr_ty(expr));
1812+
result.push(typeck.expr_ty(expr));
18121813
}
18131814
let ref_self = typeck
18141815
.type_dependent_def_id(expr.hir_id)
18151816
.map_or(false, |id| tcx.fn_sig(id).skip_binder().inputs()[0].is_ref());
1816-
f(ref_self, tcx, typeck, self_arg, res);
1817+
f(ref_self, tcx, typeck, self_arg, result);
18171818
for arg in args {
1818-
f(false, tcx, typeck, arg, res);
1819+
f(false, tcx, typeck, arg, result);
18191820
}
18201821
},
1821-
ExprKind::AddrOf(_, _, expr) | ExprKind::Field(expr, _) => f(true, tcx, typeck, expr, res),
1822-
ExprKind::Box(expr) | ExprKind::Cast(expr, _) => f(false, tcx, typeck, expr, res),
1822+
ExprKind::AddrOf(_, _, expr) | ExprKind::Field(expr, _) => f(true, tcx, typeck, expr, result),
1823+
ExprKind::Box(expr) | ExprKind::Cast(expr, _) => f(false, tcx, typeck, expr, result),
18231824
ExprKind::Array(exprs @ [_, ..]) | ExprKind::Tup(exprs @ [_, ..]) | ExprKind::Call(_, exprs) => {
18241825
if addr_of {
1825-
res.push(typeck.expr_ty(expr));
1826+
result.push(typeck.expr_ty(expr));
18261827
}
18271828
for expr in exprs {
1828-
f(false, tcx, typeck, expr, res);
1829+
f(false, tcx, typeck, expr, result);
18291830
}
18301831
},
18311832
ExprKind::Binary(_, lhs, rhs) => {
18321833
if addr_of {
1833-
res.push(typeck.expr_ty(expr));
1834+
result.push(typeck.expr_ty(expr));
18341835
}
1835-
f(false, tcx, typeck, lhs, res);
1836-
f(false, tcx, typeck, rhs, res);
1836+
f(false, tcx, typeck, lhs, result);
1837+
f(false, tcx, typeck, rhs, result);
18371838
},
18381839
ExprKind::Unary(UnOp::UnDeref, e) => {
1839-
f(typeck.expr_ty(e).is_ref(), tcx, typeck, e, res);
1840+
f(typeck.expr_ty(e).is_ref(), tcx, typeck, e, result);
18401841
},
18411842
ExprKind::Type(e, _) | ExprKind::Unary(_, e) => {
18421843
if addr_of {
1843-
res.push(typeck.expr_ty(expr));
1844+
result.push(typeck.expr_ty(expr));
18441845
}
1845-
f(false, tcx, typeck, e, res);
1846+
f(false, tcx, typeck, e, result);
18461847
},
18471848
ExprKind::Index(base, index) => {
1848-
f(true, tcx, typeck, base, res);
1849-
f(false, tcx, typeck, index, res);
1849+
f(true, tcx, typeck, base, result);
1850+
f(false, tcx, typeck, index, result);
18501851
},
18511852
ExprKind::DropTemps(_) | ExprKind::Closure(..) => {
18521853
if addr_of {
1853-
res.push(typeck.expr_ty(expr));
1854+
result.push(typeck.expr_ty(expr));
18541855
}
18551856
},
18561857
ExprKind::Match(e, _, _) => {
18571858
if addr_of {
1858-
res.push(typeck.expr_ty(expr));
1859+
result.push(typeck.expr_ty(expr));
18591860
}
1860-
f(true, tcx, typeck, e, res);
1861+
f(true, tcx, typeck, e, result);
18611862
},
18621863
ExprKind::Block(b, _) | ExprKind::Loop(b, _, _) => {
18631864
if addr_of {
1864-
res.push(typeck.expr_ty(expr));
1865+
result.push(typeck.expr_ty(expr));
18651866
}
18661867
if let Some(expr) = b.expr {
1867-
f(false, tcx, typeck, expr, res);
1868+
f(false, tcx, typeck, expr, result);
18681869
}
18691870
},
18701871
ExprKind::Struct(_, fields, _) => {
18711872
if addr_of {
1872-
res.push(typeck.expr_ty(expr));
1873+
result.push(typeck.expr_ty(expr));
18731874
}
18741875
for field in fields {
1875-
f(false, tcx, typeck, field.expr, res);
1876+
f(false, tcx, typeck, field.expr, result);
18761877
}
18771878
},
18781879
ExprKind::Repeat(expr, _) => {
18791880
if addr_of {
1880-
res.push(typeck.expr_ty(expr));
1881+
result.push(typeck.expr_ty(expr));
18811882
}
1882-
f(false, tcx, typeck, expr, res);
1883+
f(false, tcx, typeck, expr, result);
18831884
},
18841885
}
18851886
}

tests/ui/redundant_pattern_matching_option.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
#![warn(clippy::all)]
44
#![warn(clippy::redundant_pattern_matching)]
5-
#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
5+
#![allow(
6+
unused_must_use,
7+
clippy::needless_bool,
8+
clippy::match_like_matches_macro,
9+
clippy::if_same_then_else
10+
)]
611

712
fn main() {
813
if None::<()>.is_none() {}

tests/ui/redundant_pattern_matching_option.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
#![warn(clippy::all)]
44
#![warn(clippy::redundant_pattern_matching)]
5-
#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
5+
#![allow(
6+
unused_must_use,
7+
clippy::needless_bool,
8+
clippy::match_like_matches_macro,
9+
clippy::if_same_then_else
10+
)]
611

712
fn main() {
813
if let None = None::<()> {}

tests/ui/redundant_pattern_matching_option.stderr

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
error: redundant pattern matching, consider using `is_none()`
2-
--> $DIR/redundant_pattern_matching_option.rs:8:12
2+
--> $DIR/redundant_pattern_matching_option.rs:13:12
33
|
44
LL | if let None = None::<()> {}
55
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
66
|
77
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
88

99
error: redundant pattern matching, consider using `is_some()`
10-
--> $DIR/redundant_pattern_matching_option.rs:10:12
10+
--> $DIR/redundant_pattern_matching_option.rs:15:12
1111
|
1212
LL | if let Some(_) = Some(42) {}
1313
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
1414

1515
error: redundant pattern matching, consider using `is_some()`
16-
--> $DIR/redundant_pattern_matching_option.rs:12:12
16+
--> $DIR/redundant_pattern_matching_option.rs:17:12
1717
|
1818
LL | if let Some(_) = Some(42) {
1919
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
2020

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

2727
error: redundant pattern matching, consider using `is_none()`
28-
--> $DIR/redundant_pattern_matching_option.rs:20:15
28+
--> $DIR/redundant_pattern_matching_option.rs:25:15
2929
|
3030
LL | while let None = Some(42) {}
3131
| ----------^^^^----------- help: try this: `while Some(42).is_none()`
3232

3333
error: redundant pattern matching, consider using `is_none()`
34-
--> $DIR/redundant_pattern_matching_option.rs:22:15
34+
--> $DIR/redundant_pattern_matching_option.rs:27:15
3535
|
3636
LL | while let None = None::<()> {}
3737
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
3838

3939
error: redundant pattern matching, consider using `is_some()`
40-
--> $DIR/redundant_pattern_matching_option.rs:25:15
40+
--> $DIR/redundant_pattern_matching_option.rs:30:15
4141
|
4242
LL | while let Some(_) = v.pop() {
4343
| ----------^^^^^^^---------- help: try this: `while v.pop().is_some()`
4444

4545
error: redundant pattern matching, consider using `is_some()`
46-
--> $DIR/redundant_pattern_matching_option.rs:33:5
46+
--> $DIR/redundant_pattern_matching_option.rs:38:5
4747
|
4848
LL | / match Some(42) {
4949
LL | | Some(_) => true,
@@ -52,7 +52,7 @@ LL | | };
5252
| |_____^ help: try this: `Some(42).is_some()`
5353

5454
error: redundant pattern matching, consider using `is_none()`
55-
--> $DIR/redundant_pattern_matching_option.rs:38:5
55+
--> $DIR/redundant_pattern_matching_option.rs:43:5
5656
|
5757
LL | / match None::<()> {
5858
LL | | Some(_) => false,
@@ -61,7 +61,7 @@ LL | | };
6161
| |_____^ help: try this: `None::<()>.is_none()`
6262

6363
error: redundant pattern matching, consider using `is_none()`
64-
--> $DIR/redundant_pattern_matching_option.rs:43:13
64+
--> $DIR/redundant_pattern_matching_option.rs:48:13
6565
|
6666
LL | let _ = match None::<()> {
6767
| _____________^
@@ -71,25 +71,25 @@ LL | | };
7171
| |_____^ help: try this: `None::<()>.is_none()`
7272

7373
error: redundant pattern matching, consider using `is_some()`
74-
--> $DIR/redundant_pattern_matching_option.rs:49:20
74+
--> $DIR/redundant_pattern_matching_option.rs:54:20
7575
|
7676
LL | let _ = if let Some(_) = opt { true } else { false };
7777
| -------^^^^^^^------ help: try this: `if opt.is_some()`
7878

7979
error: redundant pattern matching, consider using `is_some()`
80-
--> $DIR/redundant_pattern_matching_option.rs:53:20
80+
--> $DIR/redundant_pattern_matching_option.rs:58:20
8181
|
8282
LL | let _ = if let Some(_) = gen_opt() {
8383
| -------^^^^^^^------------ help: try this: `if gen_opt().is_some()`
8484

8585
error: redundant pattern matching, consider using `is_none()`
86-
--> $DIR/redundant_pattern_matching_option.rs:55:19
86+
--> $DIR/redundant_pattern_matching_option.rs:60:19
8787
|
8888
LL | } else if let None = gen_opt() {
8989
| -------^^^^------------ help: try this: `if gen_opt().is_none()`
9090

9191
error: redundant pattern matching, consider using `is_some()`
92-
--> $DIR/redundant_pattern_matching_option.rs:64:12
92+
--> $DIR/redundant_pattern_matching_option.rs:69:12
9393
|
9494
LL | if let Some(_) = Some(m.lock()) {}
9595
| -------^^^^^^^----------------- help: try this: `if Some(m.lock()).is_some()`
@@ -98,7 +98,7 @@ LL | if let Some(_) = Some(m.lock()) {}
9898
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
9999

100100
error: redundant pattern matching, consider using `is_some()`
101-
--> $DIR/redundant_pattern_matching_option.rs:65:12
101+
--> $DIR/redundant_pattern_matching_option.rs:70:12
102102
|
103103
LL | if let Some(_) = Some(m.lock().unwrap().0) {}
104104
| -------^^^^^^^---------------------------- help: try this: `if Some(m.lock().unwrap().0).is_some()`
@@ -107,7 +107,7 @@ LL | if let Some(_) = Some(m.lock().unwrap().0) {}
107107
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
108108

109109
error: redundant pattern matching, consider using `is_none()`
110-
--> $DIR/redundant_pattern_matching_option.rs:68:16
110+
--> $DIR/redundant_pattern_matching_option.rs:73:16
111111
|
112112
LL | if let None = None::<std::sync::MutexGuard<()>> {}
113113
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
@@ -116,7 +116,7 @@ LL | if let None = None::<std::sync::MutexGuard<()>> {}
116116
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
117117

118118
error: redundant pattern matching, consider using `is_none()`
119-
--> $DIR/redundant_pattern_matching_option.rs:70:12
119+
--> $DIR/redundant_pattern_matching_option.rs:75:12
120120
|
121121
LL | if let None = None::<std::sync::MutexGuard<()>> {
122122
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
@@ -125,49 +125,49 @@ LL | if let None = None::<std::sync::MutexGuard<()>> {
125125
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
126126

127127
error: redundant pattern matching, consider using `is_none()`
128-
--> $DIR/redundant_pattern_matching_option.rs:74:12
128+
--> $DIR/redundant_pattern_matching_option.rs:79:12
129129
|
130130
LL | if let None = None::<std::sync::MutexGuard<()>> {}
131131
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
132132

133133
error: redundant pattern matching, consider using `is_some()`
134-
--> $DIR/redundant_pattern_matching_option.rs:76:12
134+
--> $DIR/redundant_pattern_matching_option.rs:81:12
135135
|
136136
LL | if let Some(_) = Some(String::new()) {}
137137
| -------^^^^^^^---------------------- help: try this: `if Some(String::new()).is_some()`
138138

139139
error: redundant pattern matching, consider using `is_some()`
140-
--> $DIR/redundant_pattern_matching_option.rs:77:12
140+
--> $DIR/redundant_pattern_matching_option.rs:82:12
141141
|
142142
LL | if let Some(_) = Some((String::new(), ())) {}
143143
| -------^^^^^^^---------------------------- help: try this: `if Some((String::new(), ())).is_some()`
144144

145145
error: redundant pattern matching, consider using `is_some()`
146-
--> $DIR/redundant_pattern_matching_option.rs:92:12
146+
--> $DIR/redundant_pattern_matching_option.rs:97:12
147147
|
148148
LL | if let Some(_) = Some(42) {}
149149
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
150150

151151
error: redundant pattern matching, consider using `is_none()`
152-
--> $DIR/redundant_pattern_matching_option.rs:94:12
152+
--> $DIR/redundant_pattern_matching_option.rs:99:12
153153
|
154154
LL | if let None = None::<()> {}
155155
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
156156

157157
error: redundant pattern matching, consider using `is_some()`
158-
--> $DIR/redundant_pattern_matching_option.rs:96:15
158+
--> $DIR/redundant_pattern_matching_option.rs:101:15
159159
|
160160
LL | while let Some(_) = Some(42) {}
161161
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
162162

163163
error: redundant pattern matching, consider using `is_none()`
164-
--> $DIR/redundant_pattern_matching_option.rs:98:15
164+
--> $DIR/redundant_pattern_matching_option.rs:103:15
165165
|
166166
LL | while let None = None::<()> {}
167167
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
168168

169169
error: redundant pattern matching, consider using `is_some()`
170-
--> $DIR/redundant_pattern_matching_option.rs:100:5
170+
--> $DIR/redundant_pattern_matching_option.rs:105:5
171171
|
172172
LL | / match Some(42) {
173173
LL | | Some(_) => true,
@@ -176,7 +176,7 @@ LL | | };
176176
| |_____^ help: try this: `Some(42).is_some()`
177177

178178
error: redundant pattern matching, consider using `is_none()`
179-
--> $DIR/redundant_pattern_matching_option.rs:105:5
179+
--> $DIR/redundant_pattern_matching_option.rs:110:5
180180
|
181181
LL | / match None::<()> {
182182
LL | | Some(_) => false,

tests/ui/redundant_pattern_matching_poll.fixed

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
#![warn(clippy::all)]
44
#![warn(clippy::redundant_pattern_matching)]
5-
#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
5+
#![allow(
6+
unused_must_use,
7+
clippy::needless_bool,
8+
clippy::match_like_matches_macro,
9+
clippy::if_same_then_else
10+
)]
611

712
use std::task::Poll::{self, Pending, Ready};
813

tests/ui/redundant_pattern_matching_poll.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
#![warn(clippy::all)]
44
#![warn(clippy::redundant_pattern_matching)]
5-
#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
5+
#![allow(
6+
unused_must_use,
7+
clippy::needless_bool,
8+
clippy::match_like_matches_macro,
9+
clippy::if_same_then_else
10+
)]
611

712
use std::task::Poll::{self, Pending, Ready};
813

0 commit comments

Comments
 (0)