Skip to content

Implement the ability to document tool attributes with #[doc(attribute = "...")] - #163642

Open
kantnero wants to merge 7 commits into
rust-lang:mainfrom
kantnero:add-support-for-namespace-attr-doc
Open

kantnero wants to merge 7 commits into
rust-lang:mainfrom
kantnero:add-support-for-namespace-attr-doc

Conversation

@kantnero

@kantnero kantnero commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

While documenting diagnostic::do_not_recommend and diagnostic::on_unimplemented, #[doc(attribute = "...")] errored cause the current implementation only support built-in attributes. #157604 (comment)

This implementation splits the value at :: and check tool against registered_tools and that the other half is a valid identifier.

This PR was tested by documenting namespace attribute and running ./x test library/core --doc to be sure no error was encountered.

Should close: #163543
Disclosure: I used LLM to help understand the attribute parsing code and for an initial sketch of the check, which I rewrote and tested myself

r? @mejrs

…e = ..)]

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
…e = ..)]

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
@rustbot

rustbot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. labels Oct 2, 2026
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
@mejrs

mejrs commented Oct 2, 2026

Copy link
Copy Markdown
Member

Can you add this to the existing doc attribute tests in rustdoc-ui, rustdoc-html etc?

And can you also add tests for custom tool attributes (with the register_tool attribute)? No need to make them work if they don't, I just want the current state to be covered in our tests.

@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Oct 2, 2026
@rust-log-analyzer

This comment has been minimized.

@kantnero

kantnero commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@mejrs

mejrs commented Oct 2, 2026

Copy link
Copy Markdown
Member

Can you fix the CI errors?

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 2, 2026
@rustbot

rustbot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
@kantnero

kantnero commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 3, 2026
@mejrs

mejrs commented Oct 3, 2026

Copy link
Copy Markdown
Member

Unfortunately this creates file names like \core\attribute.diagnostic::do_not_recommend.html, but this is not a valid filename on Windows as colons are not valid in file names. So this would break rendering std docs on windows.

@kantnero

kantnero commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Instead of :: maybe rustdoc could do a search and replace with _ or something else?

@mejrs

mejrs commented Oct 3, 2026

Copy link
Copy Markdown
Member

@fmease, @GuillaumeGomez do you have any ideas on the best way forward here?

@fmease

fmease commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

The most proper solution would be something like \core\tool.diagnostic\attribute.do_not_recommend.html IMO but I don't know how much would need to be touched to achieve that.

@kantnero

kantnero commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

This would mean stripping off the name before :: and prefixing with tool.diagnostic

This would also mean each tool attr will have a seperate dir

@mejrs

mejrs commented Oct 3, 2026

Copy link
Copy Markdown
Member

A tool attribute can also have more segments, like #[tool::one::two]. Currently there are none where this has meaning, but it works in principle.

@kantnero

kantnero commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

A tool attribute can also have more segments, like #[tool::one::two]. Currently there are none where this has meaning, but it works in principle.

How should we move forward since this PR doesn't take that into account.

My suggestion:
#[diagnostic::one::two]

core\tool.diagnostic\attribute.one_two.html

In this case if there ever exist a tool attribute with more than one segment nothing has to change.

@fmease

fmease commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

diagnostic::one::two would then clash with diagnostic::one_two.

A tool attribute can also have more segments, like #[tool::one::two]. Currently there are none where this has meaning, but it works in principle.

a::b::c::d is a path. If a, b & c are modules we choose to represent it using the filesystem hierarchy in rustdoc, so CRATE/a/b/c/KIND.d.html. Analogously, if a was a tool namespace & d was a doc(attribute) attribute (making b & c semanticless path segments I guess) in an ideal world / long-term I would expect us to represent the Rust path as filesystem path CRATE/tool.a/b/c/attribute.d.html (or as CRATE/a/b/c/attribute.d.html if we generally don't need to disambiguate between modules & tool namespaces; I just don't remember the name resolution rules atm).

In the short-term we can opt for a less principled approach, of course.

@mejrs

mejrs commented Oct 3, 2026

Copy link
Copy Markdown
Member

We can also substitute with any token that isn't valid in an ident, for example
\core\attribute.diagnostic-one-two.html

@mejrs

mejrs commented Oct 3, 2026

Copy link
Copy Markdown
Member

(not sure how this interacts with doc search, searching "diagnostic::one::two" should still get us there)

@kantnero

kantnero commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

(not sure how this interacts with doc search, searching "diagnostic::one::two" should still get us there)

Yes it should

@kantnero

kantnero commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @mejrs
How do you want to proceed with this?

@mejrs

mejrs commented Oct 5, 2026

Copy link
Copy Markdown
Member

I'm not sure what the best solution is. I think some sort of substitution is probably the way to go but I'm not sure what followup changes are required to make everything work properly. You could go to zulip and ask the rustdoc people for advice.

@mejrs mejrs added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 26, 2026
@rust-bors

rust-bors Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler 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.

implement the ability to document tool attributes with #[doc(attribute = "..")]

5 participants