-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Check paths for privacy as they are resolved and refactor away LastPrivate
#31824
Conversation
33ead2a
to
5c3c877
Compare
Reviewed. |
Thanks for the PR @jseyfried! I may unfortunately not be the best reviewer for this as so much of resolve and privacy have changed since this was originally implemented, but I can at least add my 2cents! Historically privacy and resolve were entangled, but this ended up leading to tons of really weird resolution problems. The major motivation for moving all of privacy to its own separate pass was to improve all these errors. At that point, the only privacy-related parts of resolve were that glob imports didn't bring private names into a module. Since then, though, maybe resolve has changed to be much more robust? I've definitely seen some awesome work of yours fly by in the interim :). I suspect that the buggy program you've linked here can possibly be fixed by not jettisoning |
Looking over the tests, it looks like the error messages related to privacy get even better than where they are today. Specifically the messages seem much more precise in terms of what's actually private along the chain of a path. With that in mind, if you're confident that this fits nicely into resolve as-is today and it won't regress resolution error messages, then it seems like a fine shift to me! I forget now what the |
@alexcrichton Thanks for the history and feedback! Resolve is indeed more robust now :) I'm confident that this PR won't regress resolution error messages since it doesn't change the observable behavior of the import resolver or crate resolver; instead, it silently collects privacy errors during resolution and reports them after resolution is complete.
|
|
b46675f
to
afb4c30
Compare
I added a commit addressing @petrochenkov's comments (and a comment of mine). |
afde9e3
to
068eb82
Compare
@@ -3614,6 +3606,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |||
} | |||
} | |||
} | |||
|
|||
fn report_privacy_errors(&self) { | |||
for (span, string) in self.privacy_errors.iter() { |
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.
Since privacy_errors
is a HashMap
, this will result in nondeterministic error ordering. Maybe the map should be changed to an FnvHashMap
or a BTreeMap
?
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.
Good point, I'll change it.
☔ The latest upstream changes (presumably #31882) made this pull request unmergeable. Please resolve the merge conflicts. |
I've added a couple more comments since you are going to rebase this anyway. |
This seems like a big improvement. r=me. |
To be clear: r=me after rebase + nits that others have already listed are addressed. |
068eb82
to
2dde490
Compare
2dde490
to
e67590b
Compare
@nikomatsakis I rebased, addressed the comments, and cleaned up the history. Given that there was breakage in |
@jseyfried unclear, but I kicked off one just in case |
The crater run somehow failed. I'm inclined to just land this, since the next beta has branched. |
@bors r+ |
📌 Commit e67590b has been approved by |
⌛ Testing commit e67590b with merge 7cee8b9... |
This PR privacy checks paths as they are resolved instead of in `librustc_privacy` (fixes #12334 and fixes #31779). This removes the need for the `LastPrivate` system introduced in PR #9735, the limitations of which cause #31779. This PR also reports privacy violations in paths to intra- and inter-crate items the same way -- it always reports the first inaccessible segment of the path. Since it fixes #31779, this is a [breaking-change]. For example, the following code would break: ```rust mod foo { pub use foo::bar::S; mod bar { // `bar` should be private to `foo` pub struct S; } } impl foo::S { fn f() {} } fn main() { foo::bar::S::f(); // This is now a privacy error } ``` r? @alexcrichton
Remove outdated comment The corresponding code was removed in rust-lang#31824. Also remove code duplication and rename the function.
Remove outdated comment The corresponding code was removed in rust-lang#31824. Also remove code duplication and rename the function.
Remove outdated comment The corresponding code was removed in rust-lang#31824. Also remove code duplication and rename the function.
This PR privacy checks paths as they are resolved instead of in
librustc_privacy
(fixes #12334 and fixes #31779). This removes the need for theLastPrivate
system introduced in PR #9735, the limitations of which cause #31779.This PR also reports privacy violations in paths to intra- and inter-crate items the same way -- it always reports the first inaccessible segment of the path.
Since it fixes #31779, this is a [breaking-change]. For example, the following code would break:
r? @alexcrichton