5

privacy: Stabilize lint `unnameable_types` by petrochenkov · Pull Request #12014...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/120144
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

privacy: Stabilize lint unnameable_types #120144

Conversation

Contributor

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.

jonhoo, jieyouxu, and kornelski reacted with hooray emoji

Collaborator

r? @davidtwco

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

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

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

Contributor

Author

Member

@davidtwco davidtwco

left a comment

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

scottmcm

removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label

Feb 14, 2024

Member

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.

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

commented

Feb 14, 2024

edited by joshtriplett

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

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

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.

Contributor

@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

removed the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label

Feb 15, 2024

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.

joshtriplett reacted with thumbs up emoji

Member

@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.

madsmtm reacted with thumbs up emoji

Member

@davidtwco davidtwco

left a comment

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

This comment was marked as resolved.

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)
  • pub - something that has a local pub annotation, without considering any global properties like reexports or reachability

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.

Contributor

Author

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

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

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

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

traviscross

removed the I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. label

Mar 31, 2024

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

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.

Member

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

@bors r+

kaffarell and jonhoo reacted with hooray emoji

Contributor

📌 Commit 95ec17a has been approved by davidtwco

It is now in the queue for this repository.

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

merged commit 337be99 into

rust-lang:master

Apr 8, 2024

11 checks passed

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

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

Reviewers

davidtwco

davidtwco approved these changes
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

Milestone

1.79.0

Development

Successfully merging this pull request may close these issues.

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

10 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK