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

wildcard_enum_match_arm fail with non-exhaustive enums and OR patterns #6862

Closed
repi opened this issue Mar 6, 2021 · 0 comments · Fixed by #6863
Closed

wildcard_enum_match_arm fail with non-exhaustive enums and OR patterns #6862

repi opened this issue Mar 6, 2021 · 0 comments · Fixed by #6863
Assignees
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

@repi
Copy link

repi commented Mar 6, 2021

Lint name: wildcard_enum_match_arm

I tried this code (playground link):

#![warn(clippy::wildcard_enum_match_arm)]

fn main() {
    use std::io::ErrorKind; // this enum uses `[non_exhaustive]`
    let e = ErrorKind::Interrupted;
    
    match e {
        ErrorKind::NotFound => println!("oh NotFound"),
        ErrorKind::PermissionDenied => println!("oh PermissionDenied"),
        ErrorKind::ConnectionRefused => println!("oh ConnectionRefused"),
        ErrorKind::ConnectionReset => println!("oh ConnectionReset"),
        ErrorKind::ConnectionAborted => println!("oh ConnectionAborted"),
        ErrorKind::NotConnected => println!("oh NotConnected"),
        ErrorKind::AddrInUse => println!("oh AddrInUse"),
        ErrorKind::AddrNotAvailable => println!("oh AddrNotAvailable"),
        ErrorKind::BrokenPipe => println!("oh BrokenPipe"),
        ErrorKind::AlreadyExists => println!("oh AlreadyExists"),
        ErrorKind::WouldBlock => println!("oh WouldBlock"),
        ErrorKind::InvalidInput => println!("oh InvalidInput"),
        ErrorKind::InvalidData => println!("oh InvalidData"),
        ErrorKind::TimedOut => println!("oh TimedOut"),
        ErrorKind::WriteZero => println!("oh WriteZero"),
        ErrorKind::UnexpectedEof => println!("oh UnexpectedEof"),
        
        // works
        //ErrorKind::Interrupted => println!("some stuffs"),
        //ErrorKind::Other => println!("some stuffs"),

        // doesn't work
        ErrorKind::Interrupted |
        ErrorKind::Other => println!("some stuffs"),

        _ => println!("something else"),
    }
}

I expected to see this happen: The lint not triggering, as all enum variants including a non-exhaustive case are covered

Instead, this happened: The lint triggers and wants the _ case changed to std::io::ErrorKind::Interrupted | std::io::ErrorKind::Other | _, but those concrete variant types are already handled.

Meta

  • cargo clippy -V: clippy 0.0.212 (cb75ad5d 2021-02-10)
  • rustc -Vv:
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-pc-windows-msvc
release: 1.50.0
@repi repi 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 6, 2021
@repi repi changed the title wildcard_enum_match_arm doesn't handle OR patterns with non-exhaustive enums wildcard_enum_match_arm fail with non-exhaustive enums and OR patterns Mar 6, 2021
@phansch phansch self-assigned this Mar 8, 2021
@bors bors closed this as completed in 4d68619 Mar 18, 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.

2 participants