-
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
Implement pub(restricted)
privacy (RFC 1422)
#32875
Conversation
I didn't allow Also, |
84e1cdb
to
ef05df9
Compare
@@ -949,6 +928,9 @@ pub struct NameBinding<'a> { | |||
modifiers: DefModifiers, | |||
kind: NameBindingKind<'a>, | |||
span: Option<Span>, | |||
// Enum variants are always considered `PUBLIC`, this is needed for `use Enum::Variant` | |||
// or `use Enum::*` to work on private enums. |
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.
This comment is no longer true after d1ef356?
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.
Indeed, fixed.
ef05df9
to
c2ccd5b
Compare
@@ -619,6 +621,7 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, | |||
|
|||
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, | |||
struct_field: &'v StructField) { | |||
visitor.visit_vis(&struct_field.vis); | |||
walk_opt_ident(visitor, struct_field.span, struct_field.ident); | |||
visitor.visit_ty(&struct_field.ty); | |||
walk_list!(visitor, visit_attribute, &struct_field.attrs); |
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.
Foreign items seem to be missing.
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.
And HIR visibilities in librustc\hir\intravisit.rs are not visited.
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.
Foreign items seem to be missing.
Good catch, I'll add them.
And HIR visibilities in librustc\hir\intravisit.rs are not visited.
There's no need to visit visibilities in the HIR currently -- do you think I should add a visit_vis
method in intravisit
anyway?
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.
do you think I should a visit_vis method in intravisit
Yes, default visitor functions just traverse the tree exhaustively, providing, well, correct defaults.
As an example, overridden visit_path
s will not visit paths in visibilities if intravisit
doesn't traverse visibilities by default.
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.
Done.
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've just noticed, default folders (fold.rs
) have the same problems as visitors.
AST folders don't fold all visibilities and HIR folders don't fold visibilities at all.
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.
Done.
c2ccd5b
to
358aed4
Compare
I rebased and addressed @petrochenkov's comments. |
☔ The latest upstream changes (presumably #32814) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -0,0 +1,31 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | |||
// file at the top-level directory of this distribution and at |
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.
Meta note: Let's make a subdirectory for these tests.
Perhaps src/test/compile-fail/privacy
? If we want to further designate tests aimed at the pub(restricted)
RFC, then perhaps src/test/compile-fail/privacy/restricted
?
This looks great. I suggest we move the privacy tests to a subdirectory. I want to start giving more structure to our So, here is my matrix. I've put an
Eventually I'd like to have a system for tagging tests with what they test so we can easily construct matrices like this automatically to get some idea of test coverage. But we're not there yet. r=me with suitable tests added. |
@nikomatsakis |
reexports of private variants are handled correctly.
d699383
to
a05dd73
Compare
@jseyfried oh, I forgot to label those :) it was "intra-crate" and "cross-crate" |
@jseyfried if you want me to review add'l tests, let me know, but if you feel like you've satisfied all the interesting points in that matrix, then r=me |
Ok, makes sense. I'll add some more tests and r=you |
A note: visibilities do not expect type parameters in paths, but use |
the feature `pub_restricted` is enabled.
a05dd73
to
70eb972
Compare
70eb972
to
e14504a
Compare
@petrochenkov interesting, sounds good. |
@bors r=nikomatsakis |
📌 Commit e14504a has been approved by |
Implement `pub(restricted)` privacy (RFC 1422) This implements `pub(restricted)` privacy from RFC 1422 (cc #32409) behind a feature gate. `pub(restricted)` paths currently cannot use re-exported modules both for simplicity of implementation and for future compatibility with RFC 1560 (cf #31783). r? @nikomatsakis
resolve: Refactor away `DefModifiers` This refactors away `DefModifiers`, which is unneeded now that rust-lang#32875 has landed. r? @eddyb
This implements
pub(restricted)
privacy from rust-lang/rfcs#1422 (cc #32409) behind a feature gate.pub(restricted)
paths currently cannot use re-exported modules both for simplicity of implementation and for future compatibility with rust-lang/rfcs#1560 (cc #31783).r? @nikomatsakis