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

groundwork for RFC 1422, improve PrivateItemsInPublicInterfacesVisitor #32674

Merged
merged 5 commits into from
Apr 7, 2016

Conversation

jseyfried
Copy link
Contributor

This PR lays groundwork for RFC 1422 (cc #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 Private structure can escape from its module through impl for another private structure #30079 but doesn't change any other behavior.

r? @nikomatsakis

@jseyfried
Copy link
Contributor Author

cc @petrochenkov

/// The visitor checks that each component type is at least this visible
required_visibility: ty::Visibility,
/// The visibility of the least visible component that has been visited
min_visibility: ty::Visibility,
Copy link
Contributor Author

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)

Copy link
Contributor

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.

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 there's enough similarity to justify having just one visitor. Regardless, hack or not it generalizes well :)

@@ -275,6 +275,22 @@ impl ImplOrTraitItemId {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Copy)]
pub enum Visibility {
Public, //< Visible everywhere
Copy link
Contributor

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

Copy link
Contributor Author

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

@petrochenkov
Copy link
Contributor

Reviewed, LGTM.

@petrochenkov
Copy link
Contributor

This is also a plugin-[breaking-change] due to the changes to AST
cc #31645

@jseyfried
Copy link
Contributor Author

@petrochenkov thanks!

This is also a plugin-[breaking-change] due to the changes to AST

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 ast::Visibility non-Copy and adds variants for pub(restricted)).

@bors
Copy link
Contributor

bors commented Apr 2, 2016

☔ The latest upstream changes (presumably #32562) made this pull request unmergeable. Please resolve the merge conflicts.

@jseyfried jseyfried force-pushed the 1422_groundwork branch 2 times, most recently from 622d906 to bb47000 Compare April 2, 2016 20:43
@jseyfried
Copy link
Contributor Author

I addressed @petrochenkov's comments, changed this PR to not break the AST, and rebased.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 5, 2016

📌 Commit bb47000 has been approved by nikomatsakis

@jseyfried
Copy link
Contributor Author

rebased
@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 7, 2016

📌 Commit dcd4621 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 7, 2016

⌛ Testing commit dcd4621 with merge a9fd0c5...

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 7, 2016
…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
@bors
Copy link
Contributor

bors commented Apr 7, 2016

⛄ The build was interrupted to prioritize another pull request.

bors added a commit that referenced this pull request Apr 7, 2016
Rollup of 7 pull requests

- Successful merges: #32674, #32699, #32711, #32745, #32748, #32757, #32789
- Failed merges:
@bors bors merged commit dcd4621 into rust-lang:master Apr 7, 2016
@jseyfried jseyfried deleted the 1422_groundwork branch December 20, 2016 09:25
@jseyfried jseyfried changed the title Lay groundwork for RFC 1422 and improve PrivateItemsInPublicInterfacesVisitor groundwork for RFC 1422, improve PrivateItemsInPublicInterfacesVisitor Feb 17, 2017
bors added a commit that referenced this pull request Dec 31, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Private structure can escape from its module through impl for another private structure
4 participants