Skip to content

Commit a53ade0

Browse files
committed
Fix clippy warnings
1 parent 5a2b7f0 commit a53ade0

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
@@ -1635,13 +1635,14 @@ mod redundant_pattern_match {
16351635
}
16361636

16371637
// Gets all the the temporaries in an expression which need to be dropped afterwards.
1638+
#[allow(clippy::too_many_lines)]
16381639
fn get_temporary_tys(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<Ty<'tcx>> {
16391640
fn f(
16401641
addr_of: bool,
16411642
tcx: TyCtxt<'tcx>,
16421643
typeck: &TypeckResults<'tcx>,
16431644
expr: &'tcx Expr<'tcx>,
1644-
res: &mut Vec<Ty<'tcx>>,
1645+
result: &mut Vec<Ty<'tcx>>,
16451646
) {
16461647
match expr.kind {
16471648
ExprKind::ConstBlock(_)
@@ -1661,78 +1662,78 @@ mod redundant_pattern_match {
16611662
| ExprKind::MethodCall(_, _, [], _) => (),
16621663
ExprKind::MethodCall(_, _, [self_arg, args @ ..], _) => {
16631664
if addr_of {
1664-
res.push(typeck.expr_ty(expr));
1665+
result.push(typeck.expr_ty(expr));
16651666
}
16661667
let ref_self = typeck
16671668
.type_dependent_def_id(expr.hir_id)
16681669
.map_or(false, |id| tcx.fn_sig(id).skip_binder().inputs()[0].is_ref());
1669-
f(ref_self, tcx, typeck, self_arg, res);
1670+
f(ref_self, tcx, typeck, self_arg, result);
16701671
for arg in args {
1671-
f(false, tcx, typeck, arg, res);
1672+
f(false, tcx, typeck, arg, result);
16721673
}
16731674
},
1674-
ExprKind::AddrOf(_, _, expr) | ExprKind::Field(expr, _) => f(true, tcx, typeck, expr, res),
1675-
ExprKind::Box(expr) | ExprKind::Cast(expr, _) => f(false, tcx, typeck, expr, res),
1675+
ExprKind::AddrOf(_, _, expr) | ExprKind::Field(expr, _) => f(true, tcx, typeck, expr, result),
1676+
ExprKind::Box(expr) | ExprKind::Cast(expr, _) => f(false, tcx, typeck, expr, result),
16761677
ExprKind::Array(exprs @ [_, ..]) | ExprKind::Tup(exprs @ [_, ..]) | ExprKind::Call(_, exprs) => {
16771678
if addr_of {
1678-
res.push(typeck.expr_ty(expr));
1679+
result.push(typeck.expr_ty(expr));
16791680
}
16801681
for expr in exprs {
1681-
f(false, tcx, typeck, expr, res);
1682+
f(false, tcx, typeck, expr, result);
16821683
}
16831684
},
16841685
ExprKind::Binary(_, lhs, rhs) => {
16851686
if addr_of {
1686-
res.push(typeck.expr_ty(expr));
1687+
result.push(typeck.expr_ty(expr));
16871688
}
1688-
f(false, tcx, typeck, lhs, res);
1689-
f(false, tcx, typeck, rhs, res);
1689+
f(false, tcx, typeck, lhs, result);
1690+
f(false, tcx, typeck, rhs, result);
16901691
},
16911692
ExprKind::Unary(UnOp::UnDeref, e) => {
1692-
f(typeck.expr_ty(e).is_ref(), tcx, typeck, e, res);
1693+
f(typeck.expr_ty(e).is_ref(), tcx, typeck, e, result);
16931694
},
16941695
ExprKind::Type(e, _) | ExprKind::Unary(_, e) => {
16951696
if addr_of {
1696-
res.push(typeck.expr_ty(expr));
1697+
result.push(typeck.expr_ty(expr));
16971698
}
1698-
f(false, tcx, typeck, e, res);
1699+
f(false, tcx, typeck, e, result);
16991700
},
17001701
ExprKind::Index(base, index) => {
1701-
f(true, tcx, typeck, base, res);
1702-
f(false, tcx, typeck, index, res);
1702+
f(true, tcx, typeck, base, result);
1703+
f(false, tcx, typeck, index, result);
17031704
},
17041705
ExprKind::DropTemps(_) | ExprKind::Closure(..) => {
17051706
if addr_of {
1706-
res.push(typeck.expr_ty(expr));
1707+
result.push(typeck.expr_ty(expr));
17071708
}
17081709
},
17091710
ExprKind::Match(e, _, _) => {
17101711
if addr_of {
1711-
res.push(typeck.expr_ty(expr));
1712+
result.push(typeck.expr_ty(expr));
17121713
}
1713-
f(true, tcx, typeck, e, res);
1714+
f(true, tcx, typeck, e, result);
17141715
},
17151716
ExprKind::Block(b, _) | ExprKind::Loop(b, _, _) => {
17161717
if addr_of {
1717-
res.push(typeck.expr_ty(expr));
1718+
result.push(typeck.expr_ty(expr));
17181719
}
17191720
if let Some(expr) = b.expr {
1720-
f(false, tcx, typeck, expr, res);
1721+
f(false, tcx, typeck, expr, result);
17211722
}
17221723
},
17231724
ExprKind::Struct(_, fields, _) => {
17241725
if addr_of {
1725-
res.push(typeck.expr_ty(expr));
1726+
result.push(typeck.expr_ty(expr));
17261727
}
17271728
for field in fields {
1728-
f(false, tcx, typeck, field.expr, res);
1729+
f(false, tcx, typeck, field.expr, result);
17291730
}
17301731
},
17311732
ExprKind::Repeat(expr, _) => {
17321733
if addr_of {
1733-
res.push(typeck.expr_ty(expr));
1734+
result.push(typeck.expr_ty(expr));
17341735
}
1735-
f(false, tcx, typeck, expr, res);
1736+
f(false, tcx, typeck, expr, result);
17361737
},
17371738
}
17381739
}

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)