Skip to content
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

privacy: Stabilize lint unnameable_types #120144

Merged
merged 1 commit into from Apr 8, 2024
Merged

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jan 19, 2024

This is the last piece of "RFC #2145: Type privacy and private-in-public lints".

Having unstable lints is not very useful because you cannot even dogfood them in the compiler/stdlib in this case (#113284).
The worst thing that may happen when a lint is removed are some removed_lints warnings, but I haven't heard anyone suggesting removing this specific lint.

This lint is allow-by-default and is supposed to be enabled explicitly.
Some false positives are expected, because sometimes unnameable types are a legitimate pattern.
This lint also have some unnecessary false positives, that can be fixed - see #120146 and #120149.

Closes #48054.

@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2024

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 19, 2024
@petrochenkov petrochenkov added T-lang Relevant to the language team, which will review and decide on the PR/issue. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 19, 2024
@petrochenkov
Copy link
Contributor Author

cc @Bryanskiy

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks good to me, r=me after relevant sign-offs.

@scottmcm scottmcm removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 14, 2024
@joshtriplett
Copy link
Member

joshtriplett commented Feb 14, 2024

We talked about this in today's @rust-lang/lang meeting. We're in favor of shipping this. Some of us were favorable towards making it warn-by-default in the future.

We had one suggestion for naming and application of this lint: if we fired the lint specifically at the point where you are applying a non-pub visibility to a module with pub items, and called the lint something like suppressed_pub, then that would allow for an explicit opt-in for "I'm intentionally suppressing public items" by writing #[allow(suppressed_pub)] on the point where you're applying the non-pub visibility to the module with pub items.

@scottmcm
Copy link
Member

We discussed this in the lang triage meeting today. There was lots of discussion about the exact details of the lint, but general agreement that as allow-by-default we should let people start trying this so that they can give feedback about what it reports and how.

@rfcbot fcp merge

Some of the topics that came up were about potentially linting on the module that "hides" the things inside it instead of on the items hidden, what the right way to suppress this when needed would be, and why macros might be generating things as pub expecting that they'd be hidden later like this.

But as far as I could tell, none of those seemed like blockers for this PR making the lint available to people, just that people might potentially have concerns should a future PR propose moving it to warn-by-default, depending on details.

@rfcbot
Copy link

rfcbot commented Feb 14, 2024

Team member @scottmcm has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Feb 14, 2024
@joshtriplett
Copy link
Member

I do think we should consider renaming this to suppressed_pub (or something that similarly focused on the fact that a type was pub in a module but an outer module prevents it from being exposed) before stabilizing it, personally.

@traviscross
Copy link
Contributor

traviscross commented Feb 15, 2024

@rustbot labels -I-lang-nominated

As evidenced by the discussion above, we discussed this on the lang call today, and while there was discussion about where to go from here, no one seemed opposed to stabilizing an allow-by-default lint. The outcome is the proposed FCP merge, so we can unnominate this.

Thanks to @petrochenkov for pushing this forward.

@rustbot rustbot removed the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Feb 15, 2024
@petrochenkov
Copy link
Contributor Author

@joshtriplett

I do think we should consider renaming this to suppressed_pub (or something that similarly focused on the fact that a type was pub in a module but an outer module prevents it from being exposed) before stabilizing it, personally.

What you are describing here looks like another already existing allow-by-default lint - unreachable_pub.
unnameable_types focuses on a different things - types that are indeed public, but cannot be explicitly named by users of the crate.

unreachable_pub - something is locally marked as pub, but not actually reachable from other crates.
unnameable_types - something that is reachable from other crates (which implies pub), but cannot be named.

@tmandry
Copy link
Member

tmandry commented Feb 16, 2024

@petrochenkov It sounds like you are using a definition of "reachable" that is different from what I understood the term to mean (which is the same as how you are using "nameable"). Explaining the terms in error messages and docs would help.

My feeling is that we should just redefine unreachable_pub to include this lint. The distinction "can create a value of unnameable type" does not seem important enough to create a separate lint, when we can already do that with closures and async blocks. But this has already been RFC'd, so I will not block stabilization.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks good to me, r=me once lang discussions resolved.

@bors

This comment was marked as resolved.

kaffarell added a commit to kaffarell/tracing that referenced this pull request Feb 19, 2024
The `private_in_public` rustc lint is now deprecated and throws a
warning on each `cargo check`. According to the rfc [0] this lint is
being substituted by three other ones: `private_interfaces`,
`private_bounds` and `unnameable_types`.
`unnameable_types` is not yet stabilized [1], so it will throw a warning,
but we will be ready when it is :)

[0]: https://rust-lang.github.io/rfcs/2145-type-privacy.html
[1]: rust-lang/rust#120144
@petrochenkov petrochenkov added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 26, 2024
@petrochenkov
Copy link
Contributor Author

@tmandry

It sounds like you are using a definition of "reachable" that is different from what I understood the term to mean (which is the same as how you are using "nameable"). Explaining the terms in error messages and docs would help.

I used the naming used in the compiler (struct EffectiveVisibility)

  • directly visible - both the item and all its parent modules are public, so the item can be referred by a direct path from the outside - my_crate::my_mod::Item (this is only used by rustdoc)
  • reexported aka nameable - the item is either directly visible, or has a chain of public reexports leading to it, even if some of its direct parent modules are private - my_crate::my_mod_reexport::Item
  • reachable - the item is either reexported, or is leaked from the crate in some other way - is returned by a public function, or by a public field, or occurs inside of some public type alias (basically it appears in a signature of something already reachable)

Also

  • pub - something that has a local pub annotation, without considering any global properties like reexports or reachability

@petrochenkov
Copy link
Contributor Author

So, summarizing again:

unreachable_pub

An item is locally pub, but it is neither reexported nor leaks to other crates in any way.

Recommended action: remove pub, or replace it with pub(crate)/pub(super)/etc.

This lint is reported for all entities because pub can be removed from anything.
(Although we probably need to tweak how this lint to not fire on fields of non-pub types, that's its main point of annoyance right now.)

unnameable_types

An item is reachable (leaks to other crates, this implies pub), but cannot be named because it's not reexported.

Recommended action: either reexport the item properly to make it nameable, or document that users are not supposed to be able to name it for one reason or another. In this case pub cannot be removed or changed to some more restricted visibility.

This lint is only reported for types and traits, because reporting it for other entities is redundant / not useful in nearly all cases.

This behavior is what many people expected from the old private_in_public lint, and were surprised because that lint didn't work like this.

  • How private_in_public lint really worked: non-pub type/trait appears in a signature of a pub function.
  • How some people expected it to work: "private" (actually unreachable) type/trait appears in a signature of a "public" (actually reachable/reexported) function. This matches unnameable_types.

@petrochenkov
Copy link
Contributor Author

I've updated some lint docs.
Also, re-nominating to make progress.

@petrochenkov petrochenkov added I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 13, 2024
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Mar 27, 2024
@rfcbot
Copy link

rfcbot commented Mar 27, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@traviscross traviscross removed the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label Mar 31, 2024
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Apr 6, 2024
@rfcbot
Copy link

rfcbot commented Apr 6, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@davidtwco
Copy link
Member

Already reviewed the implementation and the FCP has finished, so will approve this now.

@bors r+

@bors
Copy link
Contributor

bors commented Apr 8, 2024

📌 Commit 95ec17a has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Apr 8, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 8, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#115984 (extending filesystem support for Hermit)
 - rust-lang#120144 (privacy: Stabilize lint `unnameable_types`)
 - rust-lang#122807 (Add consistency with phrases "meantime" and "mean time")
 - rust-lang#123089 (Add invariant to VecDeque::pop_* that len < cap if pop successful)
 - rust-lang#123595 (Documentation fix)
 - rust-lang#123625 (Stop exporting `TypeckRootCtxt` and `FnCtxt`.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 337be99 into rust-lang:master Apr 8, 2024
11 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 8, 2024
Rollup merge of rust-lang#120144 - petrochenkov:unty, r=davidtwco

privacy: Stabilize lint `unnameable_types`

This is the last piece of ["RFC rust-lang#2145: Type privacy and private-in-public lints"](rust-lang#48054).

Having unstable lints is not very useful because you cannot even dogfood them in the compiler/stdlib in this case (rust-lang#113284).
The worst thing that may happen when a lint is removed are some `removed_lints` warnings, but I haven't heard anyone suggesting removing this specific lint.

This lint is allow-by-default and is supposed to be enabled explicitly.
Some false positives are expected, because sometimes unnameable types are a legitimate pattern.
This lint also have some unnecessary false positives, that can be fixed - see rust-lang#120146 and rust-lang#120149.

Closes rust-lang#48054.
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for RFC #2145: Type privacy and private-in-public lints
10 participants