-
Notifications
You must be signed in to change notification settings - Fork 13.9k
groundwork for RFC 1422, improve PrivateItemsInPublicInterfacesVisitor
#32674
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
Conversation
src/librustc_privacy/lib.rs
Outdated
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.
required_visibility and min_visibility generalize is_quiet and is_public (respectively)
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.
is_quiet is kind of a hack, I intended to split this visitor into two visitors (for checking T and Tr in impl Tr for T {....} and for everything else) and also harmonize it with some stuff in EmbargoVisitor...
Well, I guess I'll still do it, someday.
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 think there's enough similarity to justify having just one visitor. Regardless, hack or not it generalizes well :)
3d547ee to
da8d0bc
Compare
src/librustc/ty/mod.rs
Outdated
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.
//< doesn't work with rustdoc
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.
That's unfortunate, I'll make these preceding /// comments then
|
Reviewed, LGTM. |
|
This is also a plugin-[breaking-change] due to the changes to AST |
|
@petrochenkov thanks!
Ok, I'll change this to not break the AST and then do a separate PR that future proofs the AST wrt 1422 (i.e. makes |
|
☔ The latest upstream changes (presumably #32562) made this pull request unmergeable. Please resolve the merge conflicts. |
622d906 to
bb47000
Compare
|
I addressed @petrochenkov's comments, changed this PR to not break the AST, and rebased. |
|
@bors r+ |
|
📌 Commit bb47000 has been approved by |
…lity in `typeck` and in `privacy::PrivacyVisitor`.
bb47000 to
dcd4621
Compare
|
rebased |
|
📌 Commit dcd4621 has been approved by |
|
⌛ Testing commit dcd4621 with merge a9fd0c5... |
…tsakis Lay groundwork for RFC 1422 and improve `PrivateItemsInPublicInterfacesVisitor` This PR lays groundwork for RFC 1422 (cc rust-lang#32409) and improves `PrivateItemsInPublicInterfacesVisitor`. More specifically, it - Refactors away `hir::Visibility::inherit_from`, the semantics of which are obsolete. - Makes `hir::Visibility` non-`Copy` so that we will be able to add new variants to represent `pub(restricted)` (for example, `Visibility::Restricted(Path)`). - Adds a new `Copy` type `ty::Visibility` that represents a visibility value, i.e. a characterization of where an item is accessible. This is able to represent `pub(restricted)` visibilities. - Improves `PrivateItemsInPublicInterfacesVisitor` so that it checks for items in an interface that are less visible than the interface. This fixes rust-lang#30079 but doesn't change any other behavior. r? @nikomatsakis
|
⛄ The build was interrupted to prioritize another pull request. |
PrivateItemsInPublicInterfacesVisitorPrivateItemsInPublicInterfacesVisitor
privacy: Use common `DefId` visiting infrastructure for all privacy visitors One repeating pattern in privacy checking is going through a type, visiting all `DefId`s inside it and doing something with them. This is the case because visibilities and reachabilities are attached to `DefId`s. Previously various privacy visitors visited types slightly differently using their own methods, with most recently written `TypePrivacyVisitor` being the "gold standard". This mostly worked okay, but differences could manifest in overly conservative reachability analysis, some errors being reported twice, some private-in-public lints (not errors) being wrongly reported or not reported. This PR does something that I wanted to do since #32674 (comment) - factoring out the common visiting logic! Now all the common logic is contained in `struct DefIdVisitorSkeleton`, with specific privacy visitors deciding only what to do with visited `DefId`s (via `trait DefIdVisitor`). A bunch of cleanups is also applied in the process. This area is somewhat tricky due to lots of easily miss-able details, but thankfully it's was well covered by tests in #46083 and previous PRs, so I'm relatively sure in the refactoring correctness. Fixes #56837 (comment) in particular. Also this will help with implementing #48054.
This PR lays groundwork for RFC 1422 (cc #32409) and improves
PrivateItemsInPublicInterfacesVisitor. More specifically, ithir::Visibility::inherit_from, the semantics of which are obsolete.hir::Visibilitynon-Copyso that we will be able to add new variants to representpub(restricted)(for example,Visibility::Restricted(Path)).Copytypety::Visibilitythat represents a visibility value, i.e. a characterization of where an item is accessible. This is able to representpub(restricted)visibilities.PrivateItemsInPublicInterfacesVisitorso that it checks for items in an interface that are less visible than the interface. This fixes Private structure can escape from its module through impl for another private structure #30079 but doesn't change any other behavior.r? @nikomatsakis