Skip to content

Add new doc(attribute = "...") attribute #142472

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
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jun 13, 2025

Fixes #141123.

The implementation and purpose of this new #[doc(attribute = "...")] attribute is very close to #[doc(keyword = "...")]. Which means that luckily for us, most of the code needed was already in place and @Noratrieb nicely wrote a first draft that helped me implement this new attribute very fast.

Now with all this said, there is one thing I didn't do yet: adding a rustdoc-js-std test. I added GUI tests with search results for attributes so should be fine but I still plan on adding one for it once documentation for builtin attributes will be written into the core/std libs.

You can test it here.

cc @Noratrieb @Veykril

@rustbot
Copy link
Collaborator

rustbot commented Jun 13, 2025

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 13, 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 compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha, @lolbinarycat

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the doc-attribute-attribute branch from 1ab0dc7 to e2fd7f7 Compare June 13, 2025 20:07
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor

cc: @ehuss you might want to make sure the reference documents this too? Unsure whether this is interesting to you but just to be safe

if is_keyword { "keyword" } else { "attribute " }
}

let value = match meta.value_str() {
Copy link
Contributor

Choose a reason for hiding this comment

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

sigh, I'll put the doc attribute high up on my todo list to get a proper parser... (this is fine for now)

#![feature(rustdoc_internals)]
#![allow(internal_features)]

/// Some documentation about the attribute.
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we make sure this stays in sync with the compiler's view of attributes? Is the plan to keep this manual, or could we somehow generate this from for example rustc_attr_data_structures

Copy link
Member Author

Choose a reason for hiding this comment

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

Just like keywords: we can only check that the attribute is used on an existing one. If new ones are added, there is no check for that.

We could add a tidy check for it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

that'd be nice

@GuillaumeGomez GuillaumeGomez force-pushed the doc-attribute-attribute branch from e2fd7f7 to a0fb9d0 Compare June 14, 2025 10:41
@rustbot
Copy link
Collaborator

rustbot commented Jun 14, 2025

These commits modify tests/rustdoc-json.
rustdoc-json is a public (but unstable) interface.

Please ensure that if you've changed the output:

  • It's intentional.
  • The FORMAT_VERSION in src/librustdoc-json-types is bumped if necessary.

cc @aDotInTheVoid, @obi1kenobi

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the doc-attribute-attribute branch from a0fb9d0 to 14b0aa7 Compare June 14, 2025 23:27
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 15, 2025

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

@GuillaumeGomez GuillaumeGomez force-pushed the doc-attribute-attribute branch 2 times, most recently from 4a47724 to 094ed61 Compare June 15, 2025 10:25
@rust-log-analyzer

This comment has been minimized.

…_primitive`, `is_keyword` and `is_attribute` methods
@GuillaumeGomez GuillaumeGomez force-pushed the doc-attribute-attribute branch from 094ed61 to 10c8903 Compare June 15, 2025 10:33
@GuillaumeGomez
Copy link
Member Author

Ok, hopefully this time I didn't forget yet another different check I didn't use in years. T_T

@GuillaumeGomez
Copy link
Member Author

Yeay! \o/

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 A-rustdoc-search Area: Rustdoc's search feature 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document builtin attributes (like no_mangle, repr, ...) in the standard library docs
8 participants