Skip to content

Commit 4eaadd6

Browse files
committed
Run cargo dev bless to update fixes & stderr
1 parent 5ee1c24 commit 4eaadd6

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

clippy_lints/src/equatable_if_let.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,18 @@ impl<'tcx> LateLintPass<'tcx> for PatternEquality {
9696
);
9797
} else {
9898
span_lint_and_sugg(
99-
cx,
99+
cx,
100100
EQUATABLE_IF_LET,
101101
expr.span,
102-
"this pattern matching can be expressed using `matches!`",
103-
"try",
102+
"this pattern matching can be expressed using `matches!`",
103+
"try",
104104
format!(
105105
"matches!({}, {})",
106106
snippet_with_context(cx, let_expr.init.span, expr.span.ctxt(), "..", &mut applicability).0,
107107
snippet_with_context(cx, let_expr.pat.span, expr.span.ctxt(), "..", &mut applicability).0,
108-
),
108+
),
109109
applicability,
110-
)
110+
);
111111
}
112112
}
113113
}

tests/ui/equatable_if_let.fixed

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ struct Struct {
2323
b: bool,
2424
}
2525

26+
struct NoPartialEqStruct {
27+
a: i32,
28+
b: bool,
29+
}
30+
2631
enum NotPartialEq {
2732
A,
2833
B,
@@ -47,6 +52,7 @@ fn main() {
4752
let e = Enum::UnitVariant;
4853
let f = NotPartialEq::A;
4954
let g = NotStructuralEq::A;
55+
let h = NoPartialEqStruct { a: 2, b: false };
5056

5157
// true
5258

@@ -66,10 +72,11 @@ fn main() {
6672
if let Some(3 | 4) = c {}
6773
if let Struct { a, b: false } = d {}
6874
if let Struct { a: 2, b: x } = d {}
69-
if let NotPartialEq::A = f {}
75+
if matches!(f, NotPartialEq::A) {}
7076
if g == NotStructuralEq::A {}
71-
if let Some(NotPartialEq::A) = Some(f) {}
77+
if matches!(Some(f), Some(NotPartialEq::A)) {}
7278
if Some(g) == Some(NotStructuralEq::A) {}
79+
if matches!(h, NoPartialEqStruct { a: 2, b: false }) {}
7380

7481
macro_rules! m1 {
7582
(x) => {

tests/ui/equatable_if_let.stderr

+30-12
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,88 @@
11
error: this pattern matching can be expressed using equality
2-
--> $DIR/equatable_if_let.rs:53:8
2+
--> $DIR/equatable_if_let.rs:59:8
33
|
44
LL | if let 2 = a {}
55
| ^^^^^^^^^ help: try: `a == 2`
66
|
77
= note: `-D clippy::equatable-if-let` implied by `-D warnings`
88

99
error: this pattern matching can be expressed using equality
10-
--> $DIR/equatable_if_let.rs:54:8
10+
--> $DIR/equatable_if_let.rs:60:8
1111
|
1212
LL | if let Ordering::Greater = a.cmp(&b) {}
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.cmp(&b) == Ordering::Greater`
1414

1515
error: this pattern matching can be expressed using equality
16-
--> $DIR/equatable_if_let.rs:55:8
16+
--> $DIR/equatable_if_let.rs:61:8
1717
|
1818
LL | if let Some(2) = c {}
1919
| ^^^^^^^^^^^^^^^ help: try: `c == Some(2)`
2020

2121
error: this pattern matching can be expressed using equality
22-
--> $DIR/equatable_if_let.rs:56:8
22+
--> $DIR/equatable_if_let.rs:62:8
2323
|
2424
LL | if let Struct { a: 2, b: false } = d {}
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d == (Struct { a: 2, b: false })`
2626

2727
error: this pattern matching can be expressed using equality
28-
--> $DIR/equatable_if_let.rs:57:8
28+
--> $DIR/equatable_if_let.rs:63:8
2929
|
3030
LL | if let Enum::TupleVariant(32, 64) = e {}
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::TupleVariant(32, 64)`
3232

3333
error: this pattern matching can be expressed using equality
34-
--> $DIR/equatable_if_let.rs:58:8
34+
--> $DIR/equatable_if_let.rs:64:8
3535
|
3636
LL | if let Enum::RecordVariant { a: 64, b: 32 } = e {}
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == (Enum::RecordVariant { a: 64, b: 32 })`
3838

3939
error: this pattern matching can be expressed using equality
40-
--> $DIR/equatable_if_let.rs:59:8
40+
--> $DIR/equatable_if_let.rs:65:8
4141
|
4242
LL | if let Enum::UnitVariant = e {}
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::UnitVariant`
4444

4545
error: this pattern matching can be expressed using equality
46-
--> $DIR/equatable_if_let.rs:60:8
46+
--> $DIR/equatable_if_let.rs:66:8
4747
|
4848
LL | if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {}
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false })`
5050

51+
error: this pattern matching can be expressed using `matches!`
52+
--> $DIR/equatable_if_let.rs:75:8
53+
|
54+
LL | if let NotPartialEq::A = f {}
55+
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(f, NotPartialEq::A)`
56+
5157
error: this pattern matching can be expressed using equality
52-
--> $DIR/equatable_if_let.rs:70:8
58+
--> $DIR/equatable_if_let.rs:76:8
5359
|
5460
LL | if let NotStructuralEq::A = g {}
5561
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `g == NotStructuralEq::A`
5662

63+
error: this pattern matching can be expressed using `matches!`
64+
--> $DIR/equatable_if_let.rs:77:8
65+
|
66+
LL | if let Some(NotPartialEq::A) = Some(f) {}
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(Some(f), Some(NotPartialEq::A))`
68+
5769
error: this pattern matching can be expressed using equality
58-
--> $DIR/equatable_if_let.rs:72:8
70+
--> $DIR/equatable_if_let.rs:78:8
5971
|
6072
LL | if let Some(NotStructuralEq::A) = Some(g) {}
6173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(g) == Some(NotStructuralEq::A)`
6274

63-
error: this pattern matching can be expressed using equality
75+
error: this pattern matching can be expressed using `matches!`
6476
--> $DIR/equatable_if_let.rs:79:8
6577
|
78+
LL | if let NoPartialEqStruct { a: 2, b: false } = h {}
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(h, NoPartialEqStruct { a: 2, b: false })`
80+
81+
error: this pattern matching can be expressed using equality
82+
--> $DIR/equatable_if_let.rs:86:8
83+
|
6684
LL | if let m1!(x) = "abc" {
6785
| ^^^^^^^^^^^^^^^^^^ help: try: `"abc" == m1!(x)`
6886

69-
error: aborting due to 11 previous errors
87+
error: aborting due to 14 previous errors
7088

0 commit comments

Comments
 (0)