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

single_match should be smarter for known enums #327

Closed
Manishearth opened this issue Sep 11, 2015 · 4 comments
Closed

single_match should be smarter for known enums #327

Manishearth opened this issue Sep 11, 2015 · 4 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types

Comments

@Manishearth
Copy link
Member

    match my_option {
      Some(an_int) => println!("{}", an_int),
      None => {}
    }

this can be replaced with an if let, but we don't suggest it, because there's no wildcard. This makes sense for arbitrary enums -- replacing an exhaustive match with an if let can be problematic if the original enum gets updated. But for known enums like Option/Result/Cow, this isn't an issue.

@llogiq
Copy link
Contributor

llogiq commented Sep 11, 2015

With Cow, the cases using only one match arm will be rare anyway. Regarding Option/Result, I agree. Perhaps I can add the OptionBool type from my own optional crate to the list? I'm positive that it won't get additional variants in the future 😄

@Manishearth
Copy link
Member Author

Yeah, basically anything where we're sure that it won't be extended.

@llogiq llogiq added good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Sep 14, 2015
@llogiq
Copy link
Contributor

llogiq commented Sep 14, 2015

The implementation will need to call expr_ty on the matched expression, then use utils::match_ty to get the type, then loop to match the type against a white-list of known two-variant enums.

@mcarton
Copy link
Member

mcarton commented May 15, 2016

Closing as fixed in #547.

@mcarton mcarton closed this as completed May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

3 participants