rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.28k stars 1.52k forks source link

Encourage removing `{ .. }` from a pattern if enum variant is field-less #13400

Open urben1680 opened 5 days ago

urben1680 commented 5 days ago

What it does

Match patterns using Enum::Variant { .. } should be linted on if the enum variant is field-less.

Example:

match Some(42) {
    Some(v) => v,
    None { .. } /* <- lint this */ => 1
}

Advantage

Drawbacks

Example

None { .. } => 1
     ^^^^^^

Could be written as:

None => 1
lolbinarycat commented 1 day ago

This pattern may still useful in macros so this should still be possible to be ignored with an [allow(...)]

  1. all lints can be ignored in that way, if they couldn't be, they wouldn't be lints, they would be errors
  2. macro generated code is usually not linted