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 upCheck types for privacy #42125
Conversation
rust-highfive
assigned
eddyb
May 20, 2017
petrochenkov
reviewed
May 20, 2017
| None | ||
| } | ||
| ty::TyAnon(..) => { | ||
| // FIXME: How to visit `impl Trait` type? |
This comment has been minimized.
This comment has been minimized.
petrochenkov
May 20, 2017
Author
Contributor
This needs to be fixed.
IIRC, my attempts to visit it with TypeVisitor either infinitely recursed or ICEd.
This comment has been minimized.
This comment has been minimized.
eddyb
May 20, 2017
Member
Shouldn't impl Trait be able to "export" private types? cc @rust-lang/lang
This comment has been minimized.
This comment has been minimized.
petrochenkov
May 20, 2017
Author
Contributor
Yes, in anonymized form, but I'm talking about preventing use of
impl PrivateTrait
^^^^^^^^^^^^and
impl Trait<PrivateType>
^^^^^^^^^^^
here, not use of private underlying types.
This comment has been minimized.
This comment has been minimized.
eddyb
May 24, 2017
Member
Oh. So using API that involves private types? The private types would show up elsewhere if they were involved. Like, using any method on Trait would end up with that part in its Substs.
petrochenkov
reviewed
May 20, 2017
| return true; | ||
| } else if let ty::TyFnDef(..) = ty.sty { | ||
| // Inherent static methods don't have self type in substs, | ||
| // we have to check it additionally. |
This comment has been minimized.
This comment has been minimized.
petrochenkov
May 20, 2017
Author
Contributor
For some reason Self for static inherent methods is not listed in substs.
IIRC, it's not the first time I see it requiring special treatment for this reason.
This comment has been minimized.
This comment has been minimized.
eddyb
May 20, 2017
•
Member
It's not because Self is a mere alias in them. The substitutions for impls (inherent or trait impls, but you never get the latter from type-checking, only e.g. trans or MIR inlining can see them) are literally for the <...> in impl<...>.
However, it's (AFAIK) impossible to access an inherent method without one of:
- method call, which means there is an expression containing the
Selftype T::methodwhich is sugar for<T>::method, and the semantic version ofTcan be read (seerustdocandrustc_save_analysis)
petrochenkov
reviewed
May 20, 2017
| // ext::Z; // ERROR type `ext::Z` is private | ||
| // ERROR type `fn(u8) -> ext::Z {ext::Z::{{constructor}}}` is private | ||
| // ext::Z1; // ERROR type `fn(u8) -> ext::Z1 {ext::Z1::{{constructor}}}` is private | ||
| // ext::Z1::k; // ERROR type `fn() {ext::Z1::k}` is private |
This comment has been minimized.
This comment has been minimized.
petrochenkov
May 20, 2017
Author
Contributor
Some of these cases cannot be tested until macros 2.0 are merged.
eddyb
added
the
S-waiting-on-crater
label
May 20, 2017
Mark-Simulacrum
added
the
S-waiting-on-review
label
May 20, 2017
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov I'm very excited to see this PR! I have a few questions. I think there are some key questions that we were wrestling with:
I'm sure I'll know the answers once I skim the code, but I thought it'd be helpful to try and summarize these key points so that people don't have to do so. |
This comment has been minimized.
This comment has been minimized.
|
Also, I think we should FCP this before we land it. I don't anticipate a lot of back-and-forth but this is basically an insta-stable language change, so I think it makes sense. |
This comment has been minimized.
This comment has been minimized.
I didn't relax the private-in-public checker yet, so these two are still errors. I'm going to send a separate PR with private-in-public changes later. That PR will certainly require an FCP, this one - I'm not so sure. My preliminary plan is that
This is a separate case unrelated to this PR and its successors, and it will continue being an error. |
This comment has been minimized.
This comment has been minimized.
|
Started builds for crater |
This comment has been minimized.
This comment has been minimized.
|
I've started the crate builds for crater. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Actual root regressions:
|
This comment has been minimized.
This comment has been minimized.
|
Analysis: Crates that have other crates dependent on them are marked with I think it'll be okay to send PRs with fixes and/or version bumps, and then land this without additional warnings. |
This comment has been minimized.
This comment has been minimized.
what does "unfixed" mean? oh, unfixed in that crate, you mean? (i.e., not on rustc master) |
This comment has been minimized.
This comment has been minimized.
Yes |
This was referenced May 26, 2017
This comment has been minimized.
This comment has been minimized.
|
PRs/issues are submitted to all affected crates. |
This comment has been minimized.
This comment has been minimized.
It's hard to offer a strong boundary using private types in macros anyway, because of inference leakages. Unreachable-but-public types can be used if you want to hide a type name. |
petrochenkov
added some commits
Jun 3, 2017
petrochenkov
force-pushed the
petrochenkov:privty
branch
from
4fb032e
to
a27f8cf
Jul 6, 2017
This comment has been minimized.
This comment has been minimized.
|
Rebased. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jul 7, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit a27f8cf
into
rust-lang:master
Jul 7, 2017
tbg
added a commit
to tbg/rust
that referenced
this pull request
Jul 7, 2017
tbg
referenced this pull request
Jul 8, 2017
Merged
Downgrade ProjectionTy's TraitRef to its substs #42388
This was referenced Aug 5, 2017
This was referenced Aug 5, 2017
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/compiler just FYI but there's 5 open regressions against beta for this PR, all linked above this comment. |
petrochenkov commentedMay 20, 2017
•
edited
This PR implements late post factum checking of type privacy, as opposed to early preventive "private-in-public" checking.
This will allow to turn private-in-public checks into a lint and make them more heuristic-based, and more aligned with what people may expect (e.g. reachability-based behavior).
Types are privacy-checked if they are written explicitly, and also if they are inferred as expression or pattern types.
This PR checks "semantic" types and does it unhygienically, this significantly restricts what macros 2.0 (as implemented in #40847) can do (sorry @jseyfried) - they still can use private names, but can't use private types.
This is the most conservative solution, but hopefully it's temporary and can be relaxed in the future, probably using macro contexts of expression/pattern spans.
Traits are also checked in preparation for trait aliases, which will be able to leak private traits, and macros 2.0 which will be able to leak pretty much anything.
This is a [breaking-change], but the code that is not contrived and can be broken by this patch should be guarded by
private_in_publiclint. Previous crater run discovered a few abandoned crates that weren't updated sinceprivate_in_publichas been introduced in 2015.cc #34537 https://internals.rust-lang.org/t/lang-team-minutes-private-in-public-rules/4504
Fixes #30476
Fixes #33479
cc @nikomatsakis
r? @eddyb