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 lint takes the enum origin into account #10250

Merged
merged 3 commits into from
Feb 1, 2023

Conversation

tylerjw
Copy link
Contributor

@tylerjw tylerjw commented Jan 29, 2023

fixes #7419


changelog: Enhancement: [wildcard_enum_match_arm]: Now lints missing private variants, for local enums
#10250

@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2023

r? @dswij

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 29, 2023
@tylerjw
Copy link
Contributor Author

tylerjw commented Jan 29, 2023

r? @xFrednet

Tagging you for review as it is your issue, and you've helped me before.

I believe with this PR, the behavior is correct, however, I can't figure out how to declare an enum outside of this crate to test with. For that reason, with this change, all the previous tests that would trigger this lint do not (as the enum is from within this crate).

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey 👋, thank you for the PR.

You can create a file under tests/ui/auxiliary and then access it with extern crate <file_name> to have external items. #10260 recently did this and might be a good example.

The logic looks good to me, only a small suggestion to move the check to the DefId of the ADT. I contemplated for a second, if a config value might be good, but I think this is sufficient :)

cx.tcx.is_doc_hidden(variant_def.def_id) || cx.tcx.has_attr(variant_def.def_id, sym::unstable)
fn is_hidden_and_external(cx: &LateContext<'_>, variant_def: &VariantDef) -> bool {
(cx.tcx.is_doc_hidden(variant_def.def_id) || cx.tcx.has_attr(variant_def.def_id, sym::unstable))
&& variant_def.def_id.as_local().is_none()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do this check once on the ADT DefId and return early if its not local. That should be slightly faster and clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean about the ordering of the check. I re-ordered the checks between external and hidden.

As to the tests, wildcard_enum_atch_arm.rs is already doing this and the test result is as I would expect which is sweet.

The local enums with hidden types are now expanded, and the external one is not in the test output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I figured out what you are asking for here. I pulled the test for this being external out of the first loop. I can't figure out how to get the logic right to pull it out for the second one. I did at least make it just testing a captured bool instead of making a function call each time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment wasn't clear, as I misunderstood the code in question a bit. But you got what I recommended. I'll have a second look at it :)

@xFrednet
Copy link
Member

xFrednet commented Feb 1, 2023

Looks good to me, thank you for the update, I like this change!

@bors r+

@bors
Copy link
Contributor

bors commented Feb 1, 2023

📌 Commit df7cdf7 has been approved by xFrednet

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 1, 2023

⌛ Testing commit df7cdf7 with merge a2f85de...

@bors
Copy link
Contributor

bors commented Feb 1, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing a2f85de to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Feb 1, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing a2f85de to master...

@bors bors merged commit a2f85de into rust-lang:master Feb 1, 2023
@tylerjw tylerjw deleted the issue_7419 branch February 1, 2023 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve wildcard_enum_match_arm lints to take the enums origin into account
5 participants