Skip to content

document some rustc_dump attributes - #161556

Open
mejrs wants to merge 2 commits into
rust-lang:mainfrom
mejrs:attr_docs
Open

document some rustc_dump attributes#161556
mejrs wants to merge 2 commits into
rust-lang:mainfrom
mejrs:attr_docs

Conversation

@mejrs

@mejrs mejrs commented Aug 22, 2026

Copy link
Copy Markdown
Member

View all comments

r? @fmease I think you're the most familiar with these at this time?

@rustbot

rustbot commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_ir

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-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 22, 2026

@fmease fmease left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would've never thought of using #[doc(attribute(…))] within rustc itself, nice! ^^

Regarding the actual pieces of documentation you've added, I have to admit that I'm questioning their value in their current form. Let me elaborate:

  1. The synopsis / first sentence is basically just restating the name in prose
  2. The link to the corresponding AttributeKind shouldn't really be of any interest to the rustc dev looking into utilizing the internal attribute at hand
    • in 99.9% of cases, they don't intend to modify/extend the attribute; in most cases they just want to use the attribute to dump info for tests or for debugging
    • most of these AttributeKind are trivial/boring by being unit variants (and they would need to grep/jump-to-references separately anyway to find the actual impl)
    • in the 0.01% of cases where they do plan to modify the attribute itself, they will know how to grep for the impl
  3. The example code snippet is nice for skimming I suppose but the info where to place the attribute can be derived from taking a look at ALLOWED_TARGETS / by trial & error
  4. The copy/pasted compiler output is valuable for understanding what sort of information the given attribute can provide
    • however, it's bound to get out of date since it would need to be kept in sync manually, an impossible task
    • today, this kind of information can be gathered by grepping tests/ui/ since there's guaranteed to be a corresponding test; and the nice part is: the "example output" is a *.stderr file which has to be up to date or else the test would fail!

I'm not saying that we shouldn't write documentation for these internal dumping attributes but I'd be a lot more interested in docs that would semi-thoroughly explain the important&interesting parts of the respective debug output if extant (also prone to becoming outdated like all documentation but not as prone as pasted compiler output if it "talks more general concepts" / provides good info beyond the basics).

Right now, we do have a table in the rustc dev guide that's frankly also rather terse: https://rustc-dev-guide.rust-lang.org/compiler-debugging.html#rustc_-test-attributes

I'm sorry if this sounds rather discouraging after you having done all that work!

View changes since this review

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

mejrs commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

I plan on documenting most (if not all) the interesting/useful/"spicy" attributes. This is just a start :) So keep "what would it look like if everything is documented" in mind.

  1. The synopsis / first sentence is basically just restating the name in prose

They are what shows up in the module docs though, see below, and I dislike having gaps there:
image

2. The link to the corresponding AttributeKind shouldn't really be of any interest to the rustc dev looking into utilizing the internal attribute at hand

It is slightly annoying to figure out what the variant name is, though. Just searching https://doc.rust-lang.org/nightly/nightly-rustc/ and following links is easier than grepping, especially if you don't know what the precise name is. It has annoyed me in the past trying to look that up. And I think that if every attribute was documented like this, it would save me (and hopefully others) some bits of time here and there :)

3. The example code snippet is nice for skimming I suppose but the info where to place the attribute can be derived from taking a look at ALLOWED_TARGETS / by trial & error

Like the std attribute docs, I'm not aiming to be thorough and precise (at least not in the dump attributes case). These attributes are very useful for teaching Rust and discussing various rustc implementation details. So it is very nice to be able to able to quickly link to and copy paste from a place like this. This is also why I've written several unstable book entries.

The copy/pasted compiler output is valuable for understanding what sort of information the given attribute can provide

  • however, it's bound to get out of date since it would need to be kept in sync manually, an impossible task
  • today, this kind of information can be gathered by grepping tests/ui/ since there's guaranteed to be a corresponding test; and the nice part is: the "example output" is a *.stderr file which has to be up to date or else the test would fail!

It should be possible to turn these into ui tests and #[doc = include_str!(..)] them into the docs, right? I'm happy to do that if there's no issues with it.

@@ -0,0 +1,759 @@
#[cfg_attr(not(bootstrap), doc(attribute = "rustc_dump_clauses"))]
/// Dumps the clauses of the annotated item.

@fmease fmease Aug 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Below this, could you add a brief paragraph mentioning query clauses_of (and ty::Clause maybe in some way)? I know we can't intra-doc-link to them but still.

Why is mentioning clauses_of of importance? Well, it's important to know that it doesn't dump the result of query explicit_clauses_of or item_bounds for example. It's worth clarifying since synopsis "the clauses of the annotated item" is (rightly) rather vague unless you already know clauses_of.

Concretely, this actually "dumps a list of clauses that must be proven true at usage sites and which can be assumed at the definition site which consists of the explicit user-written clauses, the inferred outlives-clauses and clause <Self as Trait> if the item is a trait Trait".


I'm imagining the paragraph could be of the form "For more details, see query clauses_of and type ty::Clause." or preferably something akin to "This dumps the list of ty::Clauses as computed by query clauses_of."

View changes since the review

Comment thread compiler/rustc_attr_ir/src/attribute_docs.rs Outdated
Comment thread compiler/rustc_attr_ir/src/attribute_docs.rs Outdated
Comment thread compiler/rustc_attr_ir/src/attribute_docs.rs Outdated
Comment thread compiler/rustc_attr_ir/src/attribute_docs.rs Outdated
Comment thread compiler/rustc_attr_ir/src/attribute_docs.rs
Comment thread compiler/rustc_attr_ir/src/attribute_docs.rs
Comment thread compiler/rustc_attr_ir/src/attribute_docs.rs
Comment thread src/bootstrap/src/bin/rustdoc.rs
Comment thread compiler/rustc_attr_ir/src/lib.rs Outdated
@fmease fmease 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 Aug 22, 2026
@fmease

fmease commented Aug 23, 2026

Copy link
Copy Markdown
Member

The copy/pasted compiler output is valuable for understanding what sort of information the given attribute can provide

  • however, it's bound to get out of date since it would need to be kept in sync manually, an impossible task
  • today, this kind of information can be gathered by grepping tests/ui/ since there's guaranteed to be a corresponding test; and the nice part is: the "example output" is a *.stderr file which has to be up to date or else the test would fail!

It should be possible to turn these into ui tests and #[doc = include_str!(..)] them into the docs, right? I'm happy to do that if there's no issues with it.

Yeah, let's go with that! :)

Something like the following should definitely work:

///
/// ```compile_fail
#[doc = include_str!("../../../tests/ui/<bikeshed>/<name>.rs")]
/// ```
///
/// ```text
#[doc = include_str!("../../../tests/ui/<bikeshed>/<name>.stderr")]
/// ```

@rustbot

This comment has been minimized.

@mejrs

mejrs commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

@fmease I think that's all the feedback taken care of. let me know what you think - I'm not sure what you've had in mind for some of them.

@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 Aug 24, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fmease

fmease commented Aug 25, 2026

Copy link
Copy Markdown
Member

I would use the following normalization rule which is the most aggressive:

//@ normalize-stderr: "DefId\(.+?\)" -> "DefId(..)"

that should hopefully address the CI failure (admittedly, I've only skimmed the error log).

@mejrs

mejrs commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

I would use the following normalization rule which is the most aggressive:

//@ normalize-stderr: "DefId\(.+?\)" -> "DefId(..)"

that should hopefully address the CI failure (admittedly, I've only skimmed the error log).

it would (it's what i tried initially), but it turns DefId(0:4 ~ rustc_dump_generics[47be]::Struct::'lifetime), into DefId(..). Ideally I'd like to keep the path part of it around,

@fmease fmease left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for applying all my feedback!

r=me with my two comments addressed in one way or another & maybe with commit "misc cleanups" and "normalize stuff" "squashed away".

View changes since this review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you remove the preexisting tests/ui/dump-clauses.rs? I originally added it when adding the attribute just so we have at least one place where we exercise the clause & item bounds attributes (since it was more meant for local debugging) ... but this file plus the other one for item bounds now serve this exact purpose.

#[doc(attribute = "rustc_dump_inferred_outlives")]
/// Dumps the inferred outlives-clauses of the annotated item.
///
/// See also the [`inferred_outlives_of`] query.

@fmease fmease Aug 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With "mention the corresponding/backing query (in a following paragraph)" in various review comments I was more thinking of a direct phrasing like

Suggested change
/// See also the [`inferred_outlives_of`] query.
/// They get computed by the [`inferred_outlives_of`] query.

but that's on me for being too vague.

"See also" is also fine, so feel free to ignore this.

@fmease fmease 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 Aug 30, 2026
@mejrs

mejrs commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

maybe with commit "misc cleanups" and "normalize stuff" "squashed away".

I will, I pushed feedback changes them as separate commits to make reviewing (and keeping track of) them easier.

@rustbot

rustbot commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@mejrs

mejrs commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

@bors r=fmease

@rust-bors

rust-bors Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 52d85d7 has been approved by fmease

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 31, 2026
@rust-bors

rust-bors Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 52d85d7 with merge 2562a0f...

Workflow: https://github.com/rust-lang/rust/actions/runs/33385551665

rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
document some rustc_dump attributes



r? @fmease I think you're the most familiar with these at this time?
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 31, 2026
document some rustc_dump attributes

r? @fmease I think you're the most familiar with these at this time?
@Zalathar

Copy link
Copy Markdown
Member

@bors yield (enclosing rollup)

@rust-bors

rust-bors Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #162056.

rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
Rollup of 5 pull requests

Successful merges:

 - #161556 (document some rustc_dump attributes)
 - #161353 (Add test for parallel compiler reproducible build)
 - #161776 (Add a couple polonius tests and move universal region liveness generation)
 - #162002 (Output `tests/debuginfo` raw JSON data on failure in CI)
 - #162049 (Fix a compile error on the ESP-IDF target)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 31, 2026
document some rustc_dump attributes

r? @fmease I think you're the most familiar with these at this time?
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 31, 2026
document some rustc_dump attributes

r? @fmease I think you're the most familiar with these at this time?
rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #162058 (Port 1.98.1 release notes into main)
 - #161556 (document some rustc_dump attributes)
 - #161776 (Add a couple polonius tests and move universal region liveness generation)
 - #162002 (Output `tests/debuginfo` raw JSON data on failure in CI)
 - #162049 (Fix a compile error on the ESP-IDF target)
 - #162054 (Refine InferCtxtInner docs)
rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #162058 (Port 1.98.1 release notes into main)
 - #161556 (document some rustc_dump attributes)
 - #161776 (Add a couple polonius tests and move universal region liveness generation)
 - #162002 (Output `tests/debuginfo` raw JSON data on failure in CI)
 - #162049 (Fix a compile error on the ESP-IDF target)
 - #162054 (Refine InferCtxtInner docs)
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler 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