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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

// Rustdoc JSON *only* includes `#[repr(transparent)]`
// if the transparency is public API:
// - if a non-1-ZST field exists, it has to be public
// - otherwise, all fields are 1-ZST and at least one of them is public
Copy link
Member

Choose a reason for hiding this comment

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

NIT: It'd be nice to cite where these rules come from: https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent

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

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-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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants