Skip to content

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented May 9, 2024

This PR adds a new rustdoc pass that unconditionally always strips all private fields in aliased type, since showing them, even with --document-private-items, is confusing, unhelpful, and run backwards to the "Aliased type" feature, which is to show the type as it would be seen by the user.

r? @GuillaumeGomez
Fixes #124938
Fixes #123860

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 9, 2024
@workingjubilee
Copy link
Member

Based on discussion in #123860 the preferred implementation would seem to be to only hide these if the fields are from an "upstream" dependency and still reveal them if they're in the workspace.

@Urgau
Copy link
Member Author

Urgau commented May 9, 2024

That would indeed be better, but neither rustc nor rustdoc has workspace information, that is purely a Cargo concept. With RFC 3243: packages_as_namespaces we would have some sort a similar information, but I don't think it's possible to do it without it or without something else.

@workingjubilee
Copy link
Member

Ah, then it makes sense to defer the preferred implementation until later.

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks! Please add a FIXME with a link to the cargo issue and open an issue here to keep track of it so it's not forgotten.

@Urgau Urgau force-pushed the hide-private-fields-aliased-type branch from 9b25ab4 to e89a2cc Compare May 11, 2024 11:14
@Urgau
Copy link
Member Author

Urgau commented May 11, 2024

Created issue #125009 to track the FIXME and added the it in the code.

@GuillaumeGomez
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 11, 2024

📌 Commit e89a2cc has been approved by GuillaumeGomez

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-review Status: Awaiting review from the assignee but also interested parties. labels May 11, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 11, 2024
…type, r=GuillaumeGomez

Always hide private fields in aliased type

This PR adds a new rustdoc pass that unconditionally always strips all private fields in aliased type, since showing them, even with `--document-private-items`, is confusing, unhelpful, and run backwards to the "Aliased type" feature, which is to show the type as it would be seen by the user.

r? `@GuillaumeGomez`
Fixes rust-lang#124938
Fixes rust-lang#123860
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 11, 2024
…type, r=GuillaumeGomez

Always hide private fields in aliased type

This PR adds a new rustdoc pass that unconditionally always strips all private fields in aliased type, since showing them, even with `--document-private-items`, is confusing, unhelpful, and run backwards to the "Aliased type" feature, which is to show the type as it would be seen by the user.

r? ``@GuillaumeGomez``
Fixes rust-lang#124938
Fixes rust-lang#123860
bors added a commit to rust-lang-ci/rust that referenced this pull request May 11, 2024
…llaumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#124807 (Migrate `run-make/rustdoc-io-error` to `rmake.rs`)
 - rust-lang#124829 (Enable profiler for armv7-unknown-linux-gnueabihf.)
 - rust-lang#124939 (Always hide private fields in aliased type)
 - rust-lang#124963 (Migrate `run-make/rustdoc-shared-flags` to rmake)
 - rust-lang#124981 (Relax allocator requirements on some Rc/Arc APIs.)
 - rust-lang#125008 (Add test for rust-lang#122775)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 11, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#124096 (Clean up users of rust_dbg_call)
 - rust-lang#124829 (Enable profiler for armv7-unknown-linux-gnueabihf.)
 - rust-lang#124939 (Always hide private fields in aliased type)
 - rust-lang#124963 (Migrate `run-make/rustdoc-shared-flags` to rmake)
 - rust-lang#124981 (Relax allocator requirements on some Rc/Arc APIs.)
 - rust-lang#125008 (Add test for rust-lang#122775)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit beef360 into rust-lang:master May 12, 2024
@rustbot rustbot added this to the 1.80.0 milestone May 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2024
Rollup merge of rust-lang#124939 - Urgau:hide-private-fields-aliased-type, r=GuillaumeGomez

Always hide private fields in aliased type

This PR adds a new rustdoc pass that unconditionally always strips all private fields in aliased type, since showing them, even with `--document-private-items`, is confusing, unhelpful, and run backwards to the "Aliased type" feature, which is to show the type as it would be seen by the user.

r? ```@GuillaumeGomez```
Fixes rust-lang#124938
Fixes rust-lang#123860
// the field and not the one given by the user for the currrent crate.
//
// FIXME(#125009): Not-local should probably consider same Cargo workspace
if !i.def_id().map_or(true, |did| did.is_local()) {
Copy link
Member

Choose a reason for hiding this comment

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

This caused all cross-crate type-aliased enums to stop rendering:

image

Because visibility() here returns None.

I'll put up a PR to fix it.

Copy link
Member

Choose a reason for hiding this comment

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

Much appreciated, thanks!

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 20, 2024
…ed-viz, r=fmease

rustdoc: Don't strip items with inherited visibility in `AliasedNonLocalStripper`

Enum variants return `None` in `Item::visibility`, which fails the comparison to `Some(Visibility::Public)`. This means that all enums in type aliases are being stripped, leading to this in the `rustc_middle` docs:

<img width="474" alt="image" src="https://github.com/rust-lang/rust/assets/3674314/83704d94-a571-4c28-acbd-ca51c4efd46e">

This regressed in rust-lang#124939 (comment).

This switches the `AliasedNonLocalStripper` to not strip items with `None` as their visibility.
fmease added a commit to fmease/rust that referenced this pull request May 20, 2024
…ed-viz, r=fmease

rustdoc: Don't strip items with inherited visibility in `AliasedNonLocalStripper`

Enum variants return `None` in `Item::visibility`, which fails the comparison to `Some(Visibility::Public)`. This means that all enums in type aliases are being stripped, leading to this in the `rustc_middle` docs:

<img width="474" alt="image" src="https://github.com/rust-lang/rust/assets/3674314/83704d94-a571-4c28-acbd-ca51c4efd46e">

This regressed in rust-lang#124939 (comment).

This switches the `AliasedNonLocalStripper` to not strip items with `None` as their visibility.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 20, 2024
…ed-viz, r=fmease

rustdoc: Don't strip items with inherited visibility in `AliasedNonLocalStripper`

Enum variants return `None` in `Item::visibility`, which fails the comparison to `Some(Visibility::Public)`. This means that all enums in type aliases are being stripped, leading to this in the `rustc_middle` docs:

<img width="474" alt="image" src="https://github.com/rust-lang/rust/assets/3674314/83704d94-a571-4c28-acbd-ca51c4efd46e">

This regressed in rust-lang#124939 (comment).

This switches the `AliasedNonLocalStripper` to not strip items with `None` as their visibility.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 20, 2024
Rollup merge of rust-lang#125300 - compiler-errors:dont-strip-inherited-viz, r=fmease

rustdoc: Don't strip items with inherited visibility in `AliasedNonLocalStripper`

Enum variants return `None` in `Item::visibility`, which fails the comparison to `Some(Visibility::Public)`. This means that all enums in type aliases are being stripped, leading to this in the `rustc_middle` docs:

<img width="474" alt="image" src="https://github.com/rust-lang/rust/assets/3674314/83704d94-a571-4c28-acbd-ca51c4efd46e">

This regressed in rust-lang#124939 (comment).

This switches the `AliasedNonLocalStripper` to not strip items with `None` as their visibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Private fields in aliased type should not be shown rustdoc: document-private-items makes aliased types expansion see through private fields
6 participants