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

rustdoc: Use own logic to print #[repr(..)] attributes in JSON output. #138018

Merged
merged 1 commit into from
Mar 23, 2025

Conversation

obi1kenobi
Copy link
Member

Switch away from Debug-like representation of #[repr(..)] attributes, and start using rustdoc's own logic for pretty-printing #[repr(..)] in rustdoc JSON.

Part of addressing #137645 but not a complete solution for it.

r? @aDotInTheVoid

@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 Mar 4, 2025
@aDotInTheVoid aDotInTheVoid added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend labels Mar 4, 2025
@obi1kenobi obi1kenobi force-pushed the pg/librustdoc_repr_attr branch from 98cba84 to 67e9486 Compare March 5, 2025 06:45
@rustbot rustbot added A-rustdoc-search Area: Rustdoc's search feature T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Mar 5, 2025
@obi1kenobi obi1kenobi marked this pull request as ready for review March 5, 2025 06:45
@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing src/librustdoc/json/conversions.rs; otherwise, make sure you bump the FORMAT_VERSION constant.

cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi

Some changes occurred in tests/rustdoc-json

cc @aDotInTheVoid

@aDotInTheVoid aDotInTheVoid removed A-rustdoc-search Area: Rustdoc's search feature T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Mar 11, 2025
Copy link
Member

@aDotInTheVoid aDotInTheVoid left a comment

Choose a reason for hiding this comment

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

This looks really good! Thanks for the very thorough tests, it's appreciated.

Could you update the docs on Item::attribute? After that and rebasing to bump the format version again, this should be good to merge.

@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
/// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 40;
pub const FORMAT_VERSION: u32 = 41;
Copy link
Member

Choose a reason for hiding this comment

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

Another PR currently in the queue is making this change: #138109 (comment)

Once that lands, you should rebase ontop of that, and then bump again.

@obi1kenobi
Copy link
Member Author

obi1kenobi commented Mar 12, 2025 via email

@bors
Copy link
Contributor

bors commented Mar 16, 2025

☔ The latest upstream changes (presumably #138548) made this pull request unmergeable. Please resolve the merge conflicts.

@aDotInTheVoid
Copy link
Member

I've done the test changes in only in #138569. I'll look at the content changes in a bit (if you don't get around to it first).

Good thing about doing tests before impl change: It tells you more about what's being changed. In this case, we go from always showing #[repr(transparent)], to only showing #[repr(transparent)] when it's a part of the public API. Still not sure that's a the right choice.

jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 18, 2025
…laumeGomez

rustdoc-json: Add tests for `#[repr(...)]`

Works towards rust-lang#137645 and rust-lang#81359

Based on rust-lang#138018, but with only the test changes. CC `@obi1kenobi`

r? `@GuillaumeGomez`
jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 18, 2025
…laumeGomez

rustdoc-json: Add tests for `#[repr(...)]`

Works towards rust-lang#137645 and rust-lang#81359

Based on rust-lang#138018, but with only the test changes. CC ``@obi1kenobi``

r? ``@GuillaumeGomez``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 18, 2025
…laumeGomez

rustdoc-json: Add tests for `#[repr(...)]`

Works towards rust-lang#137645 and rust-lang#81359

Based on rust-lang#138018, but with only the test changes. CC ```@obi1kenobi```

r? ```@GuillaumeGomez```
@obi1kenobi
Copy link
Member Author

obi1kenobi commented Mar 19, 2025

Good thing about doing tests before impl change: It tells you more about what's being changed. In this case, we go from always showing #[repr(transparent)], to only showing #[repr(transparent)] when it's a part of the public API. Still not sure that's a the right choice.

My arguments for the behavior change are:

  • Consistency between HTML and JSON output is desirable; not changing means rustdoc HTML and JSON disagree on the item attributes: JSON always shows it, HTML only shows it if public API.
  • Always including repr(transparent) makes that the only non-public-API element present in rustdoc JSON with default settings. This feels much more like a bug than a feature.
    • When not public API, repr(transparent) is an internal implementation detail analogous to a method body or a non-public-API type. Those aren't included in rustdoc JSON either at all (method bodies) or without a specific flag combination (--document-hidden-items --document-private-items). If included, the item can be determined to be non-public-API from the rustdoc JSON itself.
    • This suggests non-public-API repr(transparent) should either be omitted entirely (like a method body), or at minimum should only be included if a specific flag is added and if it's possible to determine its "public API" status from the JSON alone (which it currently is not).

I hope you find these arguments convincing :) If not, then in the interest of merging the rest of the PR quickly (important for cargo-semver-checks!), I can separate out the behavior change into its own PR so we can discuss it separately.

@aDotInTheVoid
Copy link
Member

Yeah fair enough that makes sense. Maybe oneday --document-private-items should include it on both HTML and JSON, but that can happen later/seperatly.

@obi1kenobi
Copy link
Member Author

FWIW I hope we get an explicit repr section (like the one for #[deprecated]) in items before that happens, so that we can get an explicit privacy indicator. The current change will improve the accuracy of the cargo-semver-checks lint for #[repr(transparent)] removals, but since we currently have to use --document-private-items to precisely resolve glob imports, adding #[repr(transparent)] back with that flag will undo that accuracy improvement.

Rebasing this commit and resolving merge conflicts now. Should be updated momentarily.

@obi1kenobi obi1kenobi force-pushed the pg/librustdoc_repr_attr branch 2 times, most recently from 743870f to 724900a Compare March 21, 2025 01:03
@rust-log-analyzer

This comment has been minimized.

@obi1kenobi obi1kenobi force-pushed the pg/librustdoc_repr_attr branch from 724900a to f7c8539 Compare March 21, 2025 04:28
Copy link
Member

@aDotInTheVoid aDotInTheVoid left a comment

Choose a reason for hiding this comment

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

Code/test changes look good to me. This can be merged after updating the docs, and rebasing on top of #138763 (which is currently in the queue and this will conflict with)

@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
/// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 42;
pub const FORMAT_VERSION: u32 = 43;
Copy link
Member

Choose a reason for hiding this comment

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

The docs for Item::attrs should be updated to explain what's happened here.

Copy link
Member Author

@obi1kenobi obi1kenobi Mar 22, 2025

Choose a reason for hiding this comment

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

Done; I also updated the Item::attrs comment to also explain that the #[deprecated] attribute is no longer present there (a change we made previously but wasn't mentioned explicitly in the doc).

@obi1kenobi obi1kenobi force-pushed the pg/librustdoc_repr_attr branch from f7c8539 to fe20ada Compare March 22, 2025 14:31
@obi1kenobi
Copy link
Member Author

Updated the docs; waiting for the other PR to merge so I can rebase. Can I r=you after the rebase or would you like to take another look?

@aDotInTheVoid
Copy link
Member

r=me after rebasing once the test change lands

@bors delegate+

@bors rollup

@bors
Copy link
Contributor

bors commented Mar 22, 2025

✌️ @obi1kenobi, you can now approve this pull request!

If @aDotInTheVoid told you to "r=me" after making some further change, please make that change, then do @bors r=@aDotInTheVoid

@bors
Copy link
Contributor

bors commented Mar 22, 2025

☔ The latest upstream changes (presumably #138830) made this pull request unmergeable. Please resolve the merge conflicts.

@obi1kenobi obi1kenobi force-pushed the pg/librustdoc_repr_attr branch from fe20ada to bafdbca Compare March 22, 2025 18:47
@obi1kenobi
Copy link
Member Author

@bors r=@aDotInTheVoid

@bors
Copy link
Contributor

bors commented Mar 22, 2025

📌 Commit bafdbca has been approved by aDotInTheVoid

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 Mar 22, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 22, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138018 (rustdoc: Use own logic to print `#[repr(..)]` attributes in JSON output.)
 - rust-lang#138294 (Mark some std tests as requiring `panic = "unwind"`)
 - rust-lang#138468 (rustdoc js: add nonnull helper and typecheck src-script.js)
 - rust-lang#138675 (Add release notes for 1.85.1)
 - rust-lang#138765 (Fix Thread::set_name on cygwin)
 - rust-lang#138786 (Move some driver code around)
 - rust-lang#138793 (target spec check: better error when llvm-floatabi is missing)
 - rust-lang#138822 (De-Stabilize `file_lock`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c5a5f8a into rust-lang:master Mar 23, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 23, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 23, 2025
Rollup merge of rust-lang#138018 - obi1kenobi:pg/librustdoc_repr_attr, r=aDotInTheVoid

rustdoc: Use own logic to print `#[repr(..)]` attributes in JSON output.

Switch away from `Debug`-like representation of `#[repr(..)]` attributes, and start using rustdoc's own logic for pretty-printing `#[repr(..)]` in rustdoc JSON.

Part of addressing rust-lang#137645 but not a complete solution for it.

r? `@aDotInTheVoid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend 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.

5 participants