Skip to content

rustdoc-json: Structured representation of attributes #141358

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

Open
aDotInTheVoid opened this issue May 21, 2025 · 0 comments
Open

rustdoc-json: Structured representation of attributes #141358

aDotInTheVoid opened this issue May 21, 2025 · 0 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

Today, rustdoc-json presents attributes as a Vec<String>

/// Attributes on this item.
///
/// Does not include `#[deprecated]` attributes: see the [`Self::deprecation`] field instead.
///
/// Some attributes appear in pretty-printed Rust form, regardless of their formatting
/// in the original source code. For example:
/// - `#[non_exhaustive]` and `#[must_use]` are represented as themselves.
/// - `#[no_mangle]` and `#[export_name]` are also represented as themselves.
/// - `#[repr(C)]` and other reprs also appear as themselves,
/// though potentially with a different order: e.g. `repr(i8, C)` may become `repr(C, i8)`.
/// Multiple repr attributes on the same item may be combined into an equivalent single attr.
///
/// Other attributes may appear debug-printed. For example:
/// - `#[inline]` becomes something similar to `#[attr="Inline(Hint)"]`.
///
/// As an internal implementation detail subject to change, this debug-printing format
/// is currently equivalent to the HIR pretty-printing of parsed attributes.
pub attrs: Vec<String>,

This means that users wanting to use these attributes (and not just display them) must implement a parser for these strings. It'd be nice if rustdoc exposed the semantics of the attribute, and not just the syntax.

This'd mean going from Vec<String> to Vec<Attr>, and adding some enum Attr with all the possible kinds of attribute. The exact details would require design work. See #137645 (comment) for more detail.

Possibly this should wait untill the state of rustc's own attribute system is more settled (#131229).

CC @jdonszelmann @obi1kenobi

@aDotInTheVoid aDotInTheVoid added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend labels May 21, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 21, 2025
@aDotInTheVoid aDotInTheVoid removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 21, 2025
@fmease fmease added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label May 21, 2025
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants