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 upTracking issue for `private_in_public` compatibility lint. #34537
Comments
petrochenkov
referenced this issue
Jun 28, 2016
Merged
Make `private_in_public` compatibility lint deny-by-default #34206
brson
added
the
A-typesystem
label
Jul 1, 2016
This comment has been minimized.
This comment has been minimized.
Making |
nwin
referenced this issue
Jul 24, 2016
Closed
rustc should warn about private types in re-exported interfaces #35005
Sep 2, 2016
This was referenced
lfairy
referenced this issue
Sep 27, 2016
Closed
Frivolous private_in_public lint when shadowing an imported crate using #[bench] #36768
This comment has been minimized.
This comment has been minimized.
Current status of crates from the regression report:
|
This comment has been minimized.
This comment has been minimized.
@petrochenkov @nikomatsakis Any chance of flipping the switch to hard error this year? |
This comment has been minimized.
This comment has been minimized.
Not without implementing rust-lang/rfcs#1671 (or rather https://internals.rust-lang.org/t/rfc-reduce-false-positives-for-private-type-in-public-interface/3678) first, I suppose. |
This comment has been minimized.
This comment has been minimized.
Gah, I've been meaning to start a thread to discuss this topic in more depth! I had completely forgotten. |
This comment has been minimized.
This comment has been minimized.
@nikomatsakis You remembered just in time! |
This comment has been minimized.
This comment has been minimized.
Crater report shows 32 root regressions (out of which Some of them are old versions of |
This comment has been minimized.
This comment has been minimized.
I'll look at the fallout today or tomorrow. |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Using forbid for crater runs looks like a good idea. I've looked through about half of regressions, all looks legitimate and many are indeed due to nix and xml-rs. |
This comment has been minimized.
This comment has been minimized.
There may be another solution to all this private-in-public problem. Implement #30476 and make reporting of this kind of privacy errors late, as opposed to early/preventive as it is today. I expect less fallout from this, because things like this
won't report errors. All private-in-public errors in rustc_privacy (but not in resolve!) could be lowered to lints then, because early reporting is still useful for catching silly human errors. |
This comment has been minimized.
This comment has been minimized.
Yeah, that's a bit of a pickle. Not sure what the optimal solution is there, nothing obvious works. But that doesn't scale to resolutions of associated types through where clauses, which go through the trait machinery, and at that point you'd have to negate all the benefits of uniform semantical types to get accurate location information for everything. |
This comment has been minimized.
This comment has been minimized.
Oh, #30476 looks interesting. We can do it uniformly in inference writeback, is intra-function enough? |
This comment has been minimized.
This comment has been minimized.
A privacy pass simply needs to go through all HIR nodes and check their types* (somehow avoiding duplicated errors, but that's details). * At least adjusted types, not sure about non-adjusted. |
added a commit
that referenced
this issue
Jun 1, 2017
added a commit
to frewsxcv/rust
that referenced
this issue
Jun 1, 2017
added a commit
that referenced
this issue
Jun 5, 2017
Jun 6, 2017
This was referenced
added a commit
that referenced
this issue
Jun 19, 2017
Mark-Simulacrum
added
the
C-future-compatibility
label
Jun 24, 2017
added a commit
that referenced
this issue
Jul 7, 2017
Jul 7, 2017
This was referenced
Mark-Simulacrum
referenced this issue
Jul 9, 2017
Closed
Regression on nightly-2017-07-08 and nightly-2017-07-09 #43131
Mark-Simulacrum
added
C-tracking-issue
and removed
C-tracking-issue
labels
Jul 22, 2017
weiznich
referenced this issue
Jul 24, 2017
Closed
Query dsl generated by select leak private types to public interface #1037
This comment has been minimized.
This comment has been minimized.
I don't know how much this is expected/already known, but the lint triggers in cases like this one: pub mod foo {
struct Private;
mod internal {
pub type Bar = Vec<super::Private>;
}
} with
Though here, relative to module |
This comment has been minimized.
This comment has been minimized.
petrochenkov
referenced this issue
Sep 20, 2017
Merged
RFC: Type privacy and private-in-public lints #2145
This comment has been minimized.
This comment has been minimized.
How the hell is |
This comment has been minimized.
This comment has been minimized.
I am aware one can now use |
This comment has been minimized.
This comment has been minimized.
Private items cannot be publicly reexported, that's a general rule that wasn't properly enforced for
Using
Plenty of bugfixes breaking small numbers of crates were gradually landed in the previous years without epochs, using deprecation periods. The official policy is https://github.com/rust-lang/rfcs/blob/master/text/1122-language-semver.md Regarding |
This comment has been minimized.
This comment has been minimized.
Not all Rust code in the world is in crates.io, and we don’t know how representative crates.io is. Even with several months of warning, making breaking changes that are not soundness fixes without an epoch discredits our stability promise. This one feels particularly frivolous. |
This comment has been minimized.
This comment has been minimized.
The lint is currently warning on the following code : https://play.rust-lang.org/?gist=398cc0302ea20d2781d62db6deb53d97&version=nightly&mode=debug Is this a bug ? If not, is the reasoning explained anywhere ? I feel like implementing a public trait on private traits shouldn't cause the warning ? |
This comment has been minimized.
This comment has been minimized.
@roblabla In revised (but not yet implemented) rules this is a lint that's probably going to be allow-by-default, because this is still kind of a documentation issue (how do you explain to the library users what |
petrochenkov commentedJun 28, 2016
•
edited
What is this lint about
RFC 136 describes rules for using private types and traits in interfaces of public items. The main idea is that an entity restricted to some module cannot be used outside of that module. Private items are considered restricted to the module they are defined in,
pub
items are considered unrestricted and being accessible for all the universe of crates, RFC 1422 describes some more fine-grained restrictions. Note that the restrictions are determined entirely by item's declarations and don't require any reexport traversal and reachability analysis. "Used" means different things for different entities, for example private modules simply can't be named outside of their module, private types can't be named and additionally values of their type cannot be obtained outside of their module, etc. To enforce these rules more visible entities cannot contain less visible entities in their interfaces. Consider, for example, this function:If this were allowed, then values of private type
S
could leave its module.Despite the RFC being accepted these rules were not completely enforced until #29973 fixed most of the missing cases. Some more missing cases were covered later by PRs #32674 and #31362. For backward compatibility the new errors were reported as warnings (lints). Now it's time to retire these warnings and turn them into hard errors, which they are supposed to be.
This issue also tracks another very similar lint,
pub_use_of_private_extern_crate
, checking for a specific "private-in-public" situation.How to fix this warning/error
If you really want to use some private unnameable type or trait in a public interface, for example to emulate sealed traits, then there's a universal workaround - make the item public, but put it into a private inner module.
The trait
Float
is public from the private-in-public checker's point of view, because it uses only local reasoning, howeverFloat
is unnameable from outside ofm
and effectively private, because it isn't actually reexported fromm
despite being potentially reexportable.You'll also have to manually document what kind of mystery set of arguments your public function
multiply_by_2
accepts, because unnameable traits are effectively private for rustdoc.Current status
private_in_public
lint as warn-by-defaultprivate_in_public
lint deny-by-defaultprivate_in_public
lint warn-by-default again due to relatively large amount of breakageprivate_in_public
lint deny-by-defaultprivate_in_public
lint a hard error