Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive match_wildcard_for_single_variants on enum with hidden variant #6984

Closed
dtolnay opened this issue Mar 27, 2021 · 0 comments · Fixed by #6988
Closed

False positive match_wildcard_for_single_variants on enum with hidden variant #6984

dtolnay opened this issue Mar 27, 2021 · 0 comments · Fixed by #6988
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 27, 2021

Beginning with the most recent nightly (clippy 0.1.53 5e65467 2021-03-26, rustc 1.53.0-nightly 5e65467ef 2021-03-26) the following code incorrectly triggers match_wildcard_for_single_variants. I believe clippy should not be recommending that the user write doc(hidden) variants into their code.

# .clippy.toml

msrv = "1.39.0"
// src/lib.rs

pub enum Enum {
    A,
    B,
    #[doc(hidden)]
    __Private,
}
// src/main.rs

#![warn(clippy::pedantic)]

use testing::Enum;

fn main() {
    let e = Enum::A;
    let _ = match e {
        Enum::A => 'a',
        Enum::B => 'b',
        _ => 'c',
    };
}
warning: wildcard matches only a single variant and will also match any future added variants
  --> src/main.rs:10:9
   |
10 |         _ => 'c',
   |         ^ help: try this: `Enum::__Private`
   |
note: the lint level is defined here
  --> src/main.rs:1:9
   |
1  | #![warn(clippy::pedantic)]
   |         ^^^^^^^^^^^^^^^^
   = note: `#[warn(clippy::match_wildcard_for_single_variants)]` implied by `#[warn(clippy::pedantic)]`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants

Mentioning @Jarcho @llogiq who touched this lint recently in #6863.

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 27, 2021
dtolnay added a commit to serde-rs/serde that referenced this issue Mar 27, 2021
rust-lang/rust-clippy#6984

    error: wildcard matches only a single variant and will also match any future added variants
        --> serde_derive/src/internals/attr.rs:1918:9
         |
    1918 |         _ => {}
         |         ^ help: try this: `syn::Type::__TestExhaustive(_)`
         |
    note: the lint level is defined here
        --> serde_derive/src/lib.rs:18:22
         |
    18   | #![deny(clippy::all, clippy::pedantic)]
         |                      ^^^^^^^^^^^^^^^^
         = note: `#[deny(clippy::match_wildcard_for_single_variants)]` implied by `#[deny(clippy::pedantic)]`
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants

    error: wildcard matches only a single variant and will also match any future added variants
       --> serde_derive/src/internals/receiver.rs:153:13
        |
    153 |             _ => {}
        |             ^ help: try this: `Type::__TestExhaustive(_)`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants

    error: wildcard matches only a single variant and will also match any future added variants
       --> serde_derive/src/bound.rs:190:17
        |
    190 |                 _ => {}
        |                 ^ help: try this: `syn::Type::__TestExhaustive(_)`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants
dtolnay added a commit to dtolnay/syn that referenced this issue Mar 27, 2021
rust-lang/rust-clippy#6984

    error: wildcard matches only a single variant and will also match any future added variants
        --> src/expr.rs:2337:17
         |
    2337 |                 _ => unreachable!(),
         |                 ^ help: try this: `Pat::__TestExhaustive(_)`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants
bors added a commit that referenced this issue Apr 2, 2021
Fix hidden variant suggestion on single variant

Fixes #6984

changelog: Fix hidden variant suggestion on `match_wildcard_for_single_variants`
bors added a commit that referenced this issue Apr 2, 2021
Fix hidden variant suggestion on single variant

Fixes #6984

changelog: Fix hidden variant suggestion on `match_wildcard_for_single_variants`
@bors bors closed this as completed in 8abab55 Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant