Files
Jacob Pratt 7a2710b9d4 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 https://github.com/rust-lang/rust/issues/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 https://github.com/rust-lang/rust/issues/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
2026-07-24 01:59:21 -04:00
..

The rustc_ast crate contains those things concerned purely with syntax that is, the AST ("abstract syntax tree"), along with some definitions for tokens and token streams, data structures/traits for mutating ASTs, and shared definitions for other AST-related parts of the compiler (like the lexer and macro-expansion).

For more information about how these things work in rustc, see the rustc dev guide: