forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#9368 - nahuakang:improve-equatable-if-let, r=…
…flip1995 Improvement for `equatable_if_let` fixes rust-lang#9221 This PR makes sure that enums or structs not implementing `PartialEq` trait but still using the `if let` patterns can be linted to be rewritten with `matches!`. If you added a new lint, here's a checklist for things that will be checked during review or continuous integration. - \[ ] Followed [lint naming conventions][lint_naming] - \[x] Added passing UI tests (including committed `.stderr` file) - \[x] `cargo test` passes locally - \[ ] Executed `cargo dev update_lints` - \[ ] Added lint documentation - \[x] Run `cargo dev fmt` --- changelog: Improve [`equatable_if_let`] with additional `matches!` suggestions.
- Loading branch information
Showing
4 changed files
with
65 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,88 @@ | ||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:53:8 | ||
--> $DIR/equatable_if_let.rs:59:8 | ||
| | ||
LL | if let 2 = a {} | ||
| ^^^^^^^^^ help: try: `a == 2` | ||
| | ||
= note: `-D clippy::equatable-if-let` implied by `-D warnings` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:54:8 | ||
--> $DIR/equatable_if_let.rs:60:8 | ||
| | ||
LL | if let Ordering::Greater = a.cmp(&b) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.cmp(&b) == Ordering::Greater` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:55:8 | ||
--> $DIR/equatable_if_let.rs:61:8 | ||
| | ||
LL | if let Some(2) = c {} | ||
| ^^^^^^^^^^^^^^^ help: try: `c == Some(2)` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:56:8 | ||
--> $DIR/equatable_if_let.rs:62:8 | ||
| | ||
LL | if let Struct { a: 2, b: false } = d {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d == (Struct { a: 2, b: false })` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:57:8 | ||
--> $DIR/equatable_if_let.rs:63:8 | ||
| | ||
LL | if let Enum::TupleVariant(32, 64) = e {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::TupleVariant(32, 64)` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:58:8 | ||
--> $DIR/equatable_if_let.rs:64:8 | ||
| | ||
LL | if let Enum::RecordVariant { a: 64, b: 32 } = e {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == (Enum::RecordVariant { a: 64, b: 32 })` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:59:8 | ||
--> $DIR/equatable_if_let.rs:65:8 | ||
| | ||
LL | if let Enum::UnitVariant = e {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::UnitVariant` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:60:8 | ||
--> $DIR/equatable_if_let.rs:66:8 | ||
| | ||
LL | if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false })` | ||
|
||
error: this pattern matching can be expressed using `matches!` | ||
--> $DIR/equatable_if_let.rs:75:8 | ||
| | ||
LL | if let NotPartialEq::A = f {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(f, NotPartialEq::A)` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:70:8 | ||
--> $DIR/equatable_if_let.rs:76:8 | ||
| | ||
LL | if let NotStructuralEq::A = g {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `g == NotStructuralEq::A` | ||
|
||
error: this pattern matching can be expressed using `matches!` | ||
--> $DIR/equatable_if_let.rs:77:8 | ||
| | ||
LL | if let Some(NotPartialEq::A) = Some(f) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(Some(f), Some(NotPartialEq::A))` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:72:8 | ||
--> $DIR/equatable_if_let.rs:78:8 | ||
| | ||
LL | if let Some(NotStructuralEq::A) = Some(g) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(g) == Some(NotStructuralEq::A)` | ||
|
||
error: this pattern matching can be expressed using equality | ||
error: this pattern matching can be expressed using `matches!` | ||
--> $DIR/equatable_if_let.rs:79:8 | ||
| | ||
LL | if let NoPartialEqStruct { a: 2, b: false } = h {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(h, NoPartialEqStruct { a: 2, b: false })` | ||
|
||
error: this pattern matching can be expressed using equality | ||
--> $DIR/equatable_if_let.rs:86:8 | ||
| | ||
LL | if let m1!(x) = "abc" { | ||
| ^^^^^^^^^^^^^^^^^^ help: try: `"abc" == m1!(x)` | ||
|
||
error: aborting due to 11 previous errors | ||
error: aborting due to 14 previous errors | ||
|