rustdoc: correctly propagate cfgs for glob reexports#157039
Conversation
67eb276 to
e1944da
Compare
e1944da to
028afca
Compare
|
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 ? |
|
This change absolutely makes sense to me. And I might be missing something, but it seems that according the rustdoc book, the current behaviour is wrong for glob re-exports?
(BTW, the book also has an instance where it says |
|
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. |
…r=yotamofek Fix `cfg` typo in rustdoc book Fixes typo spotted by @yotamofek [here](rust-lang#157039 (comment)). r? @yotamofek
|
Since the re-export's In general I think the default behavior should be the least surprise and this behavior (with/without |
…r=yotamofek Fix `cfg` typo in rustdoc book Fixes typo spotted by @yotamofek [here](rust-lang#157039 (comment)). r? @yotamofek
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Ah, I thought that the CI failures were a GH issue so I retriggered the runs, but looks like they're actually legit and my tests are failing here in CI. |
This comment has been minimized.
This comment has been minimized.
…r=yotamofek Fix `cfg` typo in rustdoc book Fixes typo spotted by @yotamofek [here](rust-lang#157039 (comment)). r? @yotamofek
…r=yotamofek Fix `cfg` typo in rustdoc book Fixes typo spotted by @yotamofek [here](rust-lang#157039 (comment)). r? @yotamofek
|
Look at the generated docs for your test (somewhere in |
625614b to
9906454
Compare
|
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. |
|
Looks like f658bf6 affected this, that's why it was working locally but not in CI. |
Rollup merge of #157071 - GuillaumeGomez:rustdoc-book-typo, r=yotamofek Fix `cfg` typo in rustdoc book Fixes typo spotted by @yotamofek [here](#157039 (comment)). r? @yotamofek
|
Looks all good, thanks! Just waiting for CI to be done. @bors squash |
This comment has been minimized.
This comment has been minimized.
* rustdoc: correctly propagate cfgs for glob reexports * address review feedback, add a comment explaining the test * empty commit to trigger CI * empty commit to trigger CI * fix sorting of features in tests * assert contents of index.html
|
🔨 6 commits were squashed into 1f5a5a2. |
4560c33 to
1f5a5a2
Compare
Fix `cfg` typo in rustdoc book Fixes typo spotted by @yotamofek [here](rust-lang/rust#157039 (comment)). r? @yotamofek
|
@bors r+ rollup |
…uwer Rollup of 8 pull requests Successful merges: - #156863 (Make hint::cold_path #[cold] so that it works even if the MIR inliner can't inline it) - #156875 (Correct and document semantics of `yield` terminator) - #157115 ([rustdoc] Fix foreign items macro expansion) - #157150 (Revert "drop derive helpers during ast lowering" ) - #156887 (Rename `-Zdebuginfo-for-profiling` switch) - #157039 (rustdoc: correctly propagate cfgs for glob reexports) - #157125 (Rewrite the `#[repr]` attribute parser) - #157154 (Revert workaround used to select the gcc codegen in the coretests CI)
Rollup merge of #157039 - lcian:fix/glob-reexport-feature-combination, r=GuillaumeGomez rustdoc: correctly propagate cfgs for glob reexports 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: <img width="150" height="115" alt="Screenshot_20260528_201140" src="https://github.com/user-attachments/assets/8d611f88-7149-49f6-8ee0-530c049ea858" /> and after: <img width="225" height="125" alt="Screenshot_20260528_201236" src="https://github.com/user-attachments/assets/85cc07c0-9a9a-455f-8ada-69d44d645516" /> 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 `cfg`s. 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
View all comments
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:

and after:

My understanding is that this was basically an off-by-one type of oversight.
We need to update
is_inlinebefore callingget_all_import_attributesto 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_attributeswithis_inline == falseon the "intermediate" re-export, which will skip propagating itscfgs.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