-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make privacy checking aware that a use
directive can point to two defintions (namespaces) with different privacy.
#12245
Conversation
@@ -64,14 +63,32 @@ pub type ExternalExports = HashSet<DefId>; | |||
pub type LastPrivateMap = HashMap<NodeId, LastPrivate>; | |||
|
|||
pub enum LastPrivate { | |||
PrivMod(PrivateDep), |
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.
It seems a little odd to see PrivMod(AllPublic)
, so perhaps LastMod(AllPublic)
and LastImport
?
Marvelous tests, amazing design, nice job! The only major comment I have is that if you I think that we definitely want to land this at least as-is because it fixes the backwards-compatibility issues. Error messages can always be refined later down the road. I think something like this could be fixed with a side table mapping paths to the imports they were resolved with, but at some point this is also diminishing returns because this is a fairly rare use case anyway. So, two things:
Again, awesome work! |
The reason the error messages are a bit wrong is that I didn't want the def map to point at two things for imports - I thought that would be too irregular. But that means we don't really know if we are pointing at a type or a value in privacy.rs and so we sometimes get a slightly wrong error message. In other words, although the privacy information is aware of namespaces, the definition information is not. So when we rely on the latter we get incomplete/incorrect info. This only happens for error messages, so I didn't think it was breaking a major assumption about definitions for.
|
I like your line of reasoning for putting the error message on the import. That doesn't have to be done as part of this PR, however, feel free to open an issue and work on it later. |
@@ -510,40 +515,50 @@ impl<'a> PrivacyVisitor<'a> { | |||
} | |||
} | |||
|
|||
/// Guarantee that a particular definition is public, possibly emitting an | |||
/// error message if it's not. | |||
fn report_error(&self, result: CheckResult) -> bool { |
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 like this report method and I think it could be used in other places where the same form of reporting is necessary. What do you think about making this a default method in ast::visit::Visitor
(or moving it somewhere else)? If you prefer to respect YAGNI, I can do it myself later, I've already a case where I'd benefit from this.
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.
Actually, maybe this could go in the session itself.
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.
Yeah, I was thinking about maybe pulling out CheckResult and report_error into somewhere more generic - I was thinking of some utils file somewhere. The session is probably a good place (I prefer Visitor since it is not really related to visiting). I decided not to for now since I didn't know if it was generally useful. If you think it would be, feel free to pull it out.
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 it could be useful and I could use it in the patch I'm currently working on. Also, the pattern Error + Note is used in other places too.
I can pull it out later. This is not a blocker for this patch 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.
Another case where this could be helpful #12347
@alexcrichton also ready for re-review |
Feel free to |
…efintions (namespaces) with different privacy. Closes rust-lang#4110
@bors retry |
@@ -1 +1 @@ | |||
Subproject commit fd5308383c575472edb2163d823dc6670bf59609 | |||
Subproject commit 800b56fe6af21ffd8e56aee8cf12dd758f5bbdf1 |
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.
Was this revert ever fixed?
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.
Hm oddly enough 800b56fe6af21ffd8e56aee8cf12dd758f5bbdf1 is the right revision, not sure what's going on here...
fix: Fix fill-arguments completions not working Fixes rust-lang/rust-analyzer#12243
closes #4110