Skip to content

rustdoc: correctly propagate cfgs for glob reexports#157039

Open
lcian wants to merge 4 commits into
rust-lang:mainfrom
lcian:fix/glob-reexport-feature-combination
Open

rustdoc: correctly propagate cfgs for glob reexports#157039
lcian wants to merge 4 commits into
rust-lang:mainfrom
lcian:fix/glob-reexport-feature-combination

Conversation

@lcian
Copy link
Copy Markdown

@lcian lcian commented May 27, 2026

This fixes some cases of rustdoc not surfacing the correct required feature combination when using #[cfg(feature = ...)] in combination with glob reexports.

See the example cases included as tests.

Here's the generated HTML for those test cases before this change:
Screenshot_20260528_201140

and after:
Screenshot_20260528_201236

My understanding is that this was basically an off-by-one type of oversight.
We need to update is_inline before calling get_all_import_attributes to immediately reflect that the outermost import we're processing shall indeed be considered as inline, as it's a glob.
Otherwise, we will end up calling add_without_unwanted_attributes with is_inline == false on the "intermediate" re-export, which will skip propagating its cfgs.

I believe this fixes #96166, even though the description there is not super clear on the exact test case they used (there's a snippet but the author says their code is actually different).

Refs #43781
@rustbot label +F-doc_cfg
@rustbot r? @GuillaumeGomez

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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. F-doc_cfg `#![feature(doc_cfg)]` labels May 27, 2026
@lcian lcian force-pushed the fix/glob-reexport-feature-combination branch 2 times, most recently from 67eb276 to e1944da Compare May 27, 2026 23:28
@lcian lcian changed the title rustdoc: fix cfg combination for glob reexports rustdoc: correctly propagate cfgs for glob reexports May 27, 2026
@lcian lcian force-pushed the fix/glob-reexport-feature-combination branch from e1944da to 028afca Compare May 28, 2026 07:07
@lcian lcian marked this pull request as ready for review May 28, 2026 08:35
@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 May 28, 2026
@GuillaumeGomez
Copy link
Copy Markdown
Member

This is the expected behaviour as described in the rustdoc book: https://doc.rust-lang.org/rustdoc/write-documentation/re-exports.html?highlight=glob#attributes

Although I don't mind changing it. What do you think @rust-lang/rustdoc-internals ?

@yotamofek
Copy link
Copy Markdown
Contributor

yotamofek commented May 28, 2026

This change absolutely makes sense to me.
The re-exported item will only be visible if the re-export's cfg's predicate is also up-held.

And I might be missing something, but it seems that according the rustdoc book, the current behaviour is wrong for glob re-exports?

These rules also apply if the item is inlined with a glob re-export:

(BTW, the book also has an instance where it says #[cfg(a, b, c)], but I think it should say #[cfg(all(a, b, c))]?)

@GuillaumeGomez
Copy link
Copy Markdown
Member

Oh you're right. Somehow I read the opposite... Sorry about that @lcian.

And yeah, the book has a typo. Feel free to send a PR, otherwise I'll do it once I'm done with my current work.

Comment thread tests/rustdoc-html/reexport/glob-reexport-feature-combination.rs Outdated
Comment thread tests/rustdoc-html/reexport/glob-reexport-feature-combination.rs Outdated
Comment thread tests/rustdoc-html/reexport/glob-reexport-feature-combination.rs Outdated
Comment thread tests/rustdoc-html/reexport/glob-reexport-feature-combination.rs Outdated
Comment thread tests/rustdoc-html/reexport/glob-reexport-feature-combination.rs
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 28, 2026
…r=yotamofek

Fix `cfg` typo in rustdoc book

Fixes typo spotted by @yotamofek [here](rust-lang#157039 (comment)).

r? @yotamofek
@Urgau
Copy link
Copy Markdown
Member

Urgau commented May 28, 2026

Since the re-export's cfg's predicate must also be up-held for the item to be accessible, the change also makes sense to me.

In general I think the default behavior should be the least surprise and this behavior (with/without #[doc(inline)]) seems a bit surprising to me.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 28, 2026
…r=yotamofek

Fix `cfg` typo in rustdoc book

Fixes typo spotted by @yotamofek [here](rust-lang#157039 (comment)).

r? @yotamofek
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

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

Labels

F-doc_cfg `#![feature(doc_cfg)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

doc(cfg) doesn't work on glob reexports

6 participants