-
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
private type in public API of non-pub mod is allowed #22261
Comments
cc #16463 |
nominating, suggest 1.0 polish (though 1.0 beta might be warranted). |
(also, its possible I missed some discussion where we decided to remove the check here; but I would have imagined such a change would have gotten more attention.) |
Reading over the original PR #17401 i noticed that it seems like there was no Still, RFC 136 seems to clearly state that this case should be disallowed. |
This sometimes causes odd linking errors such as #20201 (comment) |
P-backcompat-lang, 1.0 beta |
Amusing. |
Amusing, truly. I thought it is intended, and I'm using this "feature". God I was trying to use my lovely utils.rs as extern crate any I found a crash of cargo. Just made my day. |
You guys, there's a tag for that. come on, there's a system |
Assigning to @nrc in the interest of having as little unassigned work for 1.0 beta as possible. |
The error doesn't seem to be anything to do with the return type. The check for private types in public interfaces only occurs if the module is itself public. I.e., changing I think this is still a bug, because I would expect there to be an error even if the module is private, since (as the example shows) it can cause incorrect exposure of internals. |
@nrc indeed, that seems wrong to me. |
A problem that has come up with this is that my fix breaks the following pattern:
This used to be Ok, because |
I should add that there is no easy work around - we can't make |
I think the property here is, if a type is used in a public item, then either that type must be public or the 'last private module' from that item must not enclose the type. Where "last private module" is the first non-pub module we encounter if we walk up the module tree from the public item to the crate root ("last" comes from walking from the crate root down). Note that it is always safe to use a public type in a public item, if the type is inaccessible due to a private module, then so will the item be. Note two: I think traits and impls count as modules for the above purpose. Note three: I believe this rule may be equivalent to the 'earlier, more complex' rule discussed in the alternatives to RFC 136. Maybe I should give up and start sprinkling |
It took me a while to digest the def'n there but I agree it is good. One thing I think we have to do is re-check pub mod x {
struct Priv;
mod helper {
pub fn f(_: Priv) { }
}
pub use self::helper::f; // Error here!
} The idea would be that you re-check the pub use'd item, but with the notion of the "current module" changed to be relative to the pub use, not the point of declaration. |
Key insight from IRC: the last private module in @nrc's definition is the "smallest opaque container" -- hence you require it be pub (and hence authorized to escape out of this container) or else that it already come from outside the container. |
Also, per IRC discussion, @nrc and I more-or-less agreed that his proposed semantics seems like an improvement on the RFC, but that for now we could probably implement the RFC as specified, and come back to this extension. |
Closes #22261 r? @nikomatsakis (+ a new test coming soon...)
http://is.gd/7IFKSB |
While reviewing the list of active feature gates and double-checking the behavior of
visible_private_types
, I found that the check is not working for e.g. the program below:In the playpen, the above compiles and runs. I expected to see an error due to the type of
a::foo
returning the private typea::S
.The text was updated successfully, but these errors were encountered: