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

Filter serde exported variants in wildcard_enum_match_arm #5733

Closed
mental32 opened this issue Jun 19, 2020 · 5 comments · Fixed by #6863
Closed

Filter serde exported variants in wildcard_enum_match_arm #5733

mental32 opened this issue Jun 19, 2020 · 5 comments · Fixed by #6863
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion

Comments

@mental32
Copy link

mental32 commented Jun 19, 2020

Hi there! I frequently encounter clippy::restriction hits for wildcard_enum_match_arm but for items that are generated by serde and are private/hidden (notice leading underscore convention).

Could arms like this be selectively filtered out for this lint? I don't think it'll improve readability if I add this arm (I don't even think I can add this arm since the item is private) and I think these are closer to informal artifacts generated by serde rather than an api that should be relied on.

At the moment my go to solution is to #[allow(...)] it for the function its found in but it ends up reading like tedious noise.

error: wildcard match will miss any future added variants
   --> src/lib.rs:166:13
    |
166 |             _ => continue,
    |             ^ help: try this: `foo::_IMPL_DESERIALIZE_FOR_Foo::_serde::export::Ok(..)`
    |
note: the lint level is defined here
   --> src/lib.rs:5:22
    |
5   | #![deny(clippy::all, clippy::restriction)]
    |                      ^^^^^^^^^^^^^^^^^^^
    = note: `#[deny(clippy::wildcard_enum_match_arm)]` implied by `#[deny(clippy::restriction)]`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm

Curious to hear thoughts on this!

@ThibsG
Copy link
Contributor

ThibsG commented Jun 21, 2020

Thanks for reporting this!
Can you provide minimal code example (not only backtrace) or at a least show portion of code that is triggering this ?

@mental32
Copy link
Author

No problem: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=b4adc23a8806145a48f45bf35f184082

@flip1995
Copy link
Member

This just needs a check for in_external_macro

@mental32 FYI: enabling the complete restriction group is not recommended, since it includes really restrictive lints, that sometimes are in contrast with other lints or even go against idiomatic rust. These lints should only be enabled on a lint-by-lint basis and with careful consideration.

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy T-macros Type: Issues with macros and macro expansion labels Jun 22, 2020
@mental32
Copy link
Author

@flip1995 oh, nice to know! 😅

I tended to just switch all the groups on and filter away the stuff that annoyed me, It never occurred to me to work the other way.

@flip1995
Copy link
Member

You can enable the whole pedantic group, if you don't mind sprinkling allows throughout the code (Clippy itself does this). But IMO picking out lints from pedantic and restriction one by one is the better approach. This is not an official recommendation, just my personal preference, though.

If you want even more lints, you can also look at the nursery group, but these lints are buggy in one way or another, so be extra careful there.

@camsteffen camsteffen 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 Jan 26, 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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants