-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Disallow non-exhaustive matches #3649
Comments
Clippy is the right place for this! This lint would go in one of the categories pedantic/restriction, so it would be an opt-in lint. If someone is interested in implementing this lint, the best point to start would be the |
I think I've implemented this locally. I'll test it out when I get back and send a PR once it's good! |
This is definitely a restriction lint. It would have too many problems to be applied generally.
|
Add wildcard_match_arm lint This lint prevents using a wildcard in a match arm. Implemented as a restriction currently, because this is pretty much an edge case. See #3649 for more information. Didn't add any tests because I wasn't sure how, but if someone wants to point me in the right direction, I'd be happy to!
Add wildcard_match_arm lint This lint prevents using a wildcard in a match arm. Implemented as a restriction currently, because this is pretty much an edge case. See #3649 for more information. Didn't add any tests because I wasn't sure how, but if someone wants to point me in the right direction, I'd be happy to!
Add wildcard_match_arm lint This lint prevents using a wildcard in a match arm. Implemented as a restriction currently, because this is pretty much an edge case. See #3649 for more information. Didn't add any tests because I wasn't sure how, but if someone wants to point me in the right direction, I'd be happy to!
Closed in #3652. |
This lint prevents using a wildcard in a match.
Changes: ```` wildcard_match_arm: Update lint count. wildcard_match_arm: add nesting issue to known. wildcard_match_arm: lint only enum matches. wildcard_match_arm: update ui test stderr wildcard_match_arm: format test. wilcard_match_arm: run rustfmt. wildcard_match_arm: add lint properly. wildcard_match_arm: rename function. wildcard_match_arm: add simple ui test. wildcard_match_arm: expand lint scope. Change match_wild lint name to WILDCARD_MATCH_ARM. Add match_wild lint (rust-lang#3649). fetch_prs_between: add .sh file ending cargo fmt Update various docs Use built-in entry_fn detection over self-built cargo fmt Reorganize conditionals: Run faster checks first Maybe fix ICE? Add initial version of const_fn lint Fix `unit_arg` false positive Rustfmt Check hypothetically failing conversion Remove tests for deprecated items Update more changed iterator paths Atomics constants are now handled by the deprecation lint Update changed iterator paths Update const slice processing update test stderr run cargo fmt rustup rust-lang/rust#57907 Fix documentation for `slow_vector_initialization` rustup rust-lang/rust#57726 Remove unsafe_vector_initialization from added lints Prevent incorrect cast_lossless suggestion in const_fn Incorporate review suggestions Fix dogfood tests on Appveyor test(versioncheck): Use .no_deps() test(versioncheck): Fix version equality check chore(cargo/dependencies/cargo-metadata): Upgrade to 0.7.1 dependencies: update itertools from 0.7 to 0.8 Add script to fetch GitHub PRs between two commits gitattributes: Treat .fixed files as rust files Update changelog with all changes since 0.0.212 Fix `expect_fun_call` lint suggestions ````
I'm not sure if this is better suited as a language feature or a clippy lint (though I assume clippy is an easier route to pursue), but it would be really nice to be able to either mark an enum (lang?) or a region of code (clippy?) as disallowing non-exhaustive matches. I know this might seem weird and/or bad, but I have a project wherein I want to make sure that all possible variants are covered, no wildcards, and I would like to have clippy be able to take care of checking for this on PRs instead of having to check it myself (clippy's way less likely to miss it than I am!).
Let's say my library has an internal enum giving movement types, and a function that performs an action based on this.
Then, if I (or someone else) later add(s) an enum variant, I can be sure, if the tests pass, that the new movement type is being appropriately handled (without the wildcard pattern as a crutch).
The text was updated successfully, but these errors were encountered: