Skip to content

[rustdoc] Retrieve cfg_attr information for derived impls for doc_cfg feature#159722

Merged
rust-bors[bot] merged 7 commits into
rust-lang:mainfrom
GuillaumeGomez:cfg_attr-doc_cfg
Jul 24, 2026
Merged

[rustdoc] Retrieve cfg_attr information for derived impls for doc_cfg feature#159722
rust-bors[bot] merged 7 commits into
rust-lang:mainfrom
GuillaumeGomez:cfg_attr-doc_cfg

Conversation

@GuillaumeGomez

@GuillaumeGomez GuillaumeGomez commented Jul 22, 2026

Copy link
Copy Markdown
Member

View all comments

Fixes #103300.

After long last, this PR finally allows the derive proc-macro cfg_attr cfg predicates information to be kept so rustdoc can use it for its doc_cfg feature (cc #43781).

It works as follows: for impl generated by macro expansion, we then look for the attributes on the type for which the impl block is implemented. Then, to know which cfg_attr attribute we want to look at, we use expn_that_defined on the impl's DefId which returns the Span where the macro was expanded. If it's part of a cfg_attr, then the cfg_attr's Span will contain the derive's, so from then, we just need to add the cfg information.

This PR also adds the cfg predicates into the AttributeKind::CfgAttrTrace variant so it can be reused by rustdoc (hence the compiler/* changes).

Thanks a lot @petrochenkov for the pointers here!

r? @petrochenkov

@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

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-clippy Relevant to the Clippy team. labels Jul 22, 2026
@rustbot rustbot added 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 Jul 22, 2026
@GuillaumeGomez GuillaumeGomez changed the title [rustdoc[ Retrieve cfg_attr information for derived impls for doc_cfg feature [rustdoc] Retrieve cfg_attr information for derived impls for doc_cfg feature Jul 22, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 22, 2026
 [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors try-

@rust-bors

rust-bors Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Unknown command "try-". Run @bors help or go to https://bors.rust-lang.org/help to see available commands.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors try cancel

@rust-bors

rust-bors Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 22, 2026
 [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature
@petrochenkov

Copy link
Copy Markdown
Contributor

LGTM, r=me when CI and perf are green, unless you want an additional rustdoc review from someone else.
@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 Jul 22, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 29dd1b5 (29dd1b5c141ed5381e32c07666d6e757a32cfab2)
Base parent: c188565 (c188565812a9b414ddf02f3c7d89e84f1ba53f7d)

@rust-timer

This comment has been minimized.

@mejrs

mejrs commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Can you update the pr description as well?

The implementation looks good to me, maybe consider a review from someone familiar with rustdoc. Up to you.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Updated description. Just in case:

r? @Urgau

@rustbot rustbot assigned Urgau and unassigned petrochenkov Jul 23, 2026
@Urgau

Urgau commented Jul 23, 2026

Copy link
Copy Markdown
Member

Another cleaver use of expn_that_defined nice.

PR looks good to me as well.

@bors r=petrochenkov,mejrs,Urgau

@rust-bors

rust-bors Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7e294a5 has been approved by petrochenkov,mejrs,Urgau

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 Jul 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
…=petrochenkov,mejrs,Urgau

 [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature

Fixes rust-lang#103300.

After long last, this PR finally allows the derive proc-macro `cfg_attr` cfg predicates information to be kept so rustdoc can use it for its `doc_cfg` feature (cc rust-lang#43781).

It works as follows: for `impl` generated by macro expansion, we then look for the attributes on the type for which the `impl` block is implemented. Then, to know which `cfg_attr` attribute we want to look at, we use `expn_that_defined` on the impl's `DefId` which returns the `Span` where the macro was expanded. If it's part of a `cfg_attr`, then the `cfg_attr`'s `Span` will contain the derive's, so from then, we just need to add the `cfg` information.

This PR also adds the cfg predicates into the `AttributeKind::CfgAttrTrace` variant so it can be reused by rustdoc (hence the `compiler/*` changes).

Thanks a lot @petrochenkov for the pointers here!

r? @petrochenkov
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 24, 2026
…=petrochenkov,mejrs,Urgau

 [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature

Fixes rust-lang#103300.

After long last, this PR finally allows the derive proc-macro `cfg_attr` cfg predicates information to be kept so rustdoc can use it for its `doc_cfg` feature (cc rust-lang#43781).

It works as follows: for `impl` generated by macro expansion, we then look for the attributes on the type for which the `impl` block is implemented. Then, to know which `cfg_attr` attribute we want to look at, we use `expn_that_defined` on the impl's `DefId` which returns the `Span` where the macro was expanded. If it's part of a `cfg_attr`, then the `cfg_attr`'s `Span` will contain the derive's, so from then, we just need to add the `cfg` information.

This PR also adds the cfg predicates into the `AttributeKind::CfgAttrTrace` variant so it can be reused by rustdoc (hence the `compiler/*` changes).

Thanks a lot @petrochenkov for the pointers here!

r? @petrochenkov
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 24, 2026
…=petrochenkov,mejrs,Urgau

 [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature

Fixes rust-lang#103300.

After long last, this PR finally allows the derive proc-macro `cfg_attr` cfg predicates information to be kept so rustdoc can use it for its `doc_cfg` feature (cc rust-lang#43781).

It works as follows: for `impl` generated by macro expansion, we then look for the attributes on the type for which the `impl` block is implemented. Then, to know which `cfg_attr` attribute we want to look at, we use `expn_that_defined` on the impl's `DefId` which returns the `Span` where the macro was expanded. If it's part of a `cfg_attr`, then the `cfg_attr`'s `Span` will contain the derive's, so from then, we just need to add the `cfg` information.

This PR also adds the cfg predicates into the `AttributeKind::CfgAttrTrace` variant so it can be reused by rustdoc (hence the `compiler/*` changes).

Thanks a lot @petrochenkov for the pointers here!

r? @petrochenkov
rust-bors Bot pushed a commit that referenced this pull request Jul 24, 2026
Rollup of 12 pull requests

Successful merges:

 - #159765 (Avoid spurious rebuilds of JSON docs in bootstrap)
 - #159781 (Update bootstrap to use -Zembed-metadata=no instead of -Zno-embed-metadata)
 - #158362 (trait solver: account for universes from replace_bound_vars)
 - #159173 (Add allowed list check on EII implementations attributes)
 - #159718 (Make `DocLinkResMap` an `FxIndexMap`)
 - #159722 ( [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature)
 - #155795 (constify `vec![1, 2, 3]` macro)
 - #157776 (ci: Enable autodiff tests on x86_64 linux)
 - #158766 (Promote riscv64-unknown-linux-musl to tier 2 with host tools)
 - #159271 (str: add ASCII fast path to word_to_titlecase)
 - #159666 (fix(ld64.lld): route version mismatch warnings to linker_info on macOS)
 - #159667 (Make some parser structured suggestions verbose and tweak their wording)
rust-bors Bot pushed a commit that referenced this pull request Jul 24, 2026
Rollup of 14 pull requests

Successful merges:

 - #159765 (Avoid spurious rebuilds of JSON docs in bootstrap)
 - #159781 (Update bootstrap to use -Zembed-metadata=no instead of -Zno-embed-metadata)
 - #158362 (trait solver: account for universes from replace_bound_vars)
 - #158372 (rustfmt: Discover modules via `cfg_select!`)
 - #159173 (Add allowed list check on EII implementations attributes)
 - #159718 (Make `DocLinkResMap` an `FxIndexMap`)
 - #159722 ( [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature)
 - #159731 (std: Implement futex on wasip3 targets, update target spec)
 - #159755 (Improve consistency of attribute error messages)
 - #155795 (constify `vec![1, 2, 3]` macro)
 - #157776 (ci: Enable autodiff tests on x86_64 linux)
 - #158766 (Promote riscv64-unknown-linux-musl to tier 2 with host tools)
 - #159271 (str: add ASCII fast path to word_to_titlecase)
 - #159667 (Make some parser structured suggestions verbose and tweak their wording)
@rust-bors
rust-bors Bot merged commit 7a2710b into rust-lang:main Jul 24, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 24, 2026
rust-timer added a commit that referenced this pull request Jul 24, 2026
Rollup merge of #159722 - GuillaumeGomez:cfg_attr-doc_cfg, r=petrochenkov,mejrs,Urgau

 [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature

Fixes #103300.

After long last, this PR finally allows the derive proc-macro `cfg_attr` cfg predicates information to be kept so rustdoc can use it for its `doc_cfg` feature (cc #43781).

It works as follows: for `impl` generated by macro expansion, we then look for the attributes on the type for which the `impl` block is implemented. Then, to know which `cfg_attr` attribute we want to look at, we use `expn_that_defined` on the impl's `DefId` which returns the `Span` where the macro was expanded. If it's part of a `cfg_attr`, then the `cfg_attr`'s `Span` will contain the derive's, so from then, we just need to add the `cfg` information.

This PR also adds the cfg predicates into the `AttributeKind::CfgAttrTrace` variant so it can be reused by rustdoc (hence the `compiler/*` changes).

Thanks a lot @petrochenkov for the pointers here!

r? @petrochenkov
@GuillaumeGomez
GuillaumeGomez deleted the cfg_attr-doc_cfg branch July 24, 2026 09:30
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jul 25, 2026
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#159765 (Avoid spurious rebuilds of JSON docs in bootstrap)
 - rust-lang/rust#159781 (Update bootstrap to use -Zembed-metadata=no instead of -Zno-embed-metadata)
 - rust-lang/rust#158362 (trait solver: account for universes from replace_bound_vars)
 - rust-lang/rust#158372 (rustfmt: Discover modules via `cfg_select!`)
 - rust-lang/rust#159173 (Add allowed list check on EII implementations attributes)
 - rust-lang/rust#159718 (Make `DocLinkResMap` an `FxIndexMap`)
 - rust-lang/rust#159722 ( [rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature)
 - rust-lang/rust#159731 (std: Implement futex on wasip3 targets, update target spec)
 - rust-lang/rust#159755 (Improve consistency of attribute error messages)
 - rust-lang/rust#155795 (constify `vec![1, 2, 3]` macro)
 - rust-lang/rust#157776 (ci: Enable autodiff tests on x86_64 linux)
 - rust-lang/rust#158766 (Promote riscv64-unknown-linux-musl to tier 2 with host tools)
 - rust-lang/rust#159271 (str: add ASCII fast path to word_to_titlecase)
 - rust-lang/rust#159667 (Make some parser structured suggestions verbose and tweak their wording)
chenyukang added a commit to chenyukang/rust that referenced this pull request Jul 26, 2026
Minor `rustc_ast::ast` doc cleanups

`P` is an outdated reference.

`CfgAttrTrace` was updated in rust-lang#159722

Docs were formatted so that the entire paragraph doesn't show up on the module level docs (pet peeve of mine).

r? @nnethercote
chenyukang added a commit to chenyukang/rust that referenced this pull request Jul 26, 2026
Minor `rustc_ast::ast` doc cleanups

`P` is an outdated reference.

`CfgAttrTrace` was updated in rust-lang#159722

Docs were formatted so that the entire paragraph doesn't show up on the module level docs (pet peeve of mine).

r? @nnethercote
chenyukang added a commit to chenyukang/rust that referenced this pull request Jul 26, 2026
Minor `rustc_ast::ast` doc cleanups

`P` is an outdated reference.

`CfgAttrTrace` was updated in rust-lang#159722

Docs were formatted so that the entire paragraph doesn't show up on the module level docs (pet peeve of mine).

r? @nnethercote
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
Minor `rustc_ast::ast` doc cleanups

`P` is an outdated reference.

`CfgAttrTrace` was updated in rust-lang#159722

Docs were formatted so that the entire paragraph doesn't show up on the module level docs (pet peeve of mine).

r? @nnethercote
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
Minor `rustc_ast::ast` doc cleanups

`P` is an outdated reference.

`CfgAttrTrace` was updated in rust-lang#159722

Docs were formatted so that the entire paragraph doesn't show up on the module level docs (pet peeve of mine).

r? @nnethercote
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
Minor `rustc_ast::ast` doc cleanups

`P` is an outdated reference.

`CfgAttrTrace` was updated in rust-lang#159722

Docs were formatted so that the entire paragraph doesn't show up on the module level docs (pet peeve of mine).

r? @nnethercote
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-clippy Relevant to the Clippy team. 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.

Conditionally derived traits using cfg_attr are not documented as being behind a feature flag.

7 participants