-
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
match_wildcard
improvements
#6863
Conversation
r? @llogiq (rust-highfive has picked a reviewer for you, use r? to override) |
45c41db
to
0523137
Compare
I'm not completely sure about the wording of the warning. Otherwise this looks good. |
Also a test with a |
☔ The latest upstream changes (presumably #6725) made this pull request unmergeable. Please resolve the merge conflicts. |
I left the wording as is, but it could be improved. The suggestion to change the message instead of ignore the lint for |
Does the standard library really have that many single-variant enums? |
It's for when the wildcard matches only a single variant, not when the enum has only one. |
Fyi my suggestion for #6604 was intended for all enums. Personally I think that if a |
I can think of two reasons to use the lint.
I would use the lint for the former, I don't really care about the latter. That's just how I would personally use it. |
I see what you mean. The first reason is generally more important and could be the only important reason for others as well. Perhaps we need a new pedantic lint |
clippy_lints/src/matches.rs
Outdated
let mut suggestions: Vec<_> = variants.iter().cloned().map(format_suggestion).collect(); | ||
let message = if adt_def.is_variant_list_non_exhaustive() { | ||
suggestions.push("_".into()); | ||
"match on non-exhaustive enum doesn't explicitly match all known variants" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like that this message references a "non-exhaustive enum" where the lint doesn't even trigger on enums that have been marked #[non-exhaustive]
. How about "match on the single remaining variant by wildcard" instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I used the wrong message there.
3b25ecf
to
76fbe92
Compare
I'm still not completely sure about the message: "will miss any" reads like variants added in the future would not be matched when the opposite is the case. How about "will also match any" instead? |
☔ The latest upstream changes (presumably #6918) made this pull request unmergeable. Please resolve the merge conflicts. |
…um_match_arm` lints Don't lint on `Result` and `Option` types. Considers `or` patterns. Considers variants prefixed with `Self` Suggestions will try to find a common prefix rather than just using the full path
Changed. Should the match on non-exhaustive enums be separated into it's own lint? The whole purpose of them is to not necessarily match every variant. |
Good question. But not a blocker, so in the interest of avoiding more rebasing work for you, we can address this in a followup. @bors r+ |
📌 Commit d5a7941 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes: #6604
fixes: #5733
fixes: #6862
#5733 is only fixed in the normal case, if different paths are used for the variants then the same problem will occur. It's cause by
def_path_str
returning an utterly useless result. I haven't dug into why yet.For #6604 there should be some discussion before accepting this. It's easy enough to change the message rather than disable the lint for
Option
andResult
.changelog: Attempt to find a common path prefix for
match_wildcard_for_single_variants
andwildcard_enum_match_arm
changelog: Don't lint op
Option
andResult
formatch_wildcard_for_single_variants
andwildcard_enum_match_arm
changelog: Consider
or
patterns andSelf
prefix formatch_wildcard_for_single_variants
andwildcard_enum_match_arm