Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upprivate type in public API of non-pub mod is allowed #22261
Comments
This comment has been minimized.
This comment has been minimized.
|
cc #16463 |
This comment has been minimized.
This comment has been minimized.
|
nominating, suggest 1.0 polish (though 1.0 beta might be warranted). |
pnkfelix
added
the
I-nominated
label
Feb 13, 2015
This comment has been minimized.
This comment has been minimized.
|
(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.) |
pnkfelix
changed the title
private types in public APIs became re-enabled?
private types in return type of public APIs is allowed?
Feb 13, 2015
pnkfelix
changed the title
private types in return type of public APIs is allowed?
private type in return type of public API is allowed?
Feb 13, 2015
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
This sometimes causes odd linking errors such as #20201 (comment) |
This comment has been minimized.
This comment has been minimized.
|
P-backcompat-lang, 1.0 beta |
pnkfelix
added
the
P-backcompat-lang
label
Feb 19, 2015
pnkfelix
added this to the 1.0 beta milestone
Feb 19, 2015
pnkfelix
removed
the
I-nominated
label
Feb 19, 2015
This comment has been minimized.
This comment has been minimized.
|
Amusing. |
This comment has been minimized.
This comment has been minimized.
|
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. |
Gankro
added
the
A-amusing
label
Feb 19, 2015
This comment has been minimized.
This comment has been minimized.
|
You guys, there's a tag for that. come on, there's a system |
pnkfelix
referenced this issue
Mar 2, 2015
Closed
Associated types lets you expose private types in public signatures (?) #22912
nikomatsakis
assigned
nrc
Mar 4, 2015
This comment has been minimized.
This comment has been minimized.
|
Assigning to @nrc in the interest of having as little unassigned work for 1.0 beta as possible. |
This comment has been minimized.
This comment has been minimized.
|
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
changed the title
private type in return type of public API is allowed?
private type in public API of non-pub mod is allowed
Mar 9, 2015
This comment has been minimized.
This comment has been minimized.
|
@nrc indeed, that seems wrong to me. |
This comment has been minimized.
This comment has been minimized.
|
A problem that has come up with this is that my fix breaks the following pattern:
This used to be Ok, because |
This comment has been minimized.
This comment has been minimized.
|
I should add that there is no easy work around - we can't make |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This was referenced Mar 11, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
bors
added a commit
that referenced
this issue
Mar 17, 2015
bors
added a commit
that referenced
this issue
Mar 18, 2015
bors
closed this
in
#23290
Mar 18, 2015
tomaka
referenced this issue
Mar 21, 2015
Closed
Private type in exported type signature when it shouldn't #23585
nrc
referenced this issue
Mar 22, 2015
Closed
private type in public interface rules do not prevent exposure of some types #23621
This comment has been minimized.
This comment has been minimized.
|
http://is.gd/7IFKSB |
pnkfelix commentedFeb 13, 2015
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::fooreturning the private typea::S.