Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc_cfg should not merge cfgs on non-glob inlined reexports #112881

Closed
Nemo157 opened this issue Jun 21, 2023 · 2 comments · Fixed by #113091
Closed

doc_cfg should not merge cfgs on non-glob inlined reexports #112881

Nemo157 opened this issue Jun 21, 2023 · 2 comments · Fixed by #113091
Assignees
Labels
C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Jun 21, 2023

I tried this code:

#![feature(doc_auto_cfg)]

#[cfg(a)]
pub mod a {
    pub use crate::b::B;
}

#[cfg(any(a, b))]
mod b {
    pub struct B;
}

I expected to see this happen: The docs show that a::B requires the cfg a only.

Instead, this happened: The docs show that a::B requires the cfg a and (a or b).

image

Reasoning: When re-exporting things with different cfgs like this there are two things that can happen:

  1. The re-export uses a subset of cfgs like the example, this subset is sufficient so that the item will appear exactly with the subset
  2. The re-export uses a non-subset of cfgs (e.g. cfg(any(a, c)) on mod a above), if the non-subset cfgs are active (--cfg=c) then this will be a compile error as the item doesn't exist to re-export, if the subset cfgs are active it behaves like 1.

This only applies to non-glob inlined re-exports, for glob re-exports the item may or may not exist to be re-exported (potentially the cfgs on the path up until the glob can be removed, and only cfgs on the globbed item itself matter, but I haven't thought through all the details), for non-inlined re-exports see #85043.

@Nemo157 Nemo157 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` labels Jun 21, 2023
@GuillaumeGomez
Copy link
Member

Just to be sure, you mean that only the cfgs on the final re-export itself should be visible for this re-export, right?

@Nemo157
Copy link
Member Author

Nemo157 commented Jun 26, 2023

Yes

@GuillaumeGomez GuillaumeGomez self-assigned this Jun 26, 2023
@bors bors closed this as completed in ec0008a Dec 15, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 15, 2023
Rollup merge of rust-lang#113091 - GuillaumeGomez:prevent-cfg-merge-reexport, r=rustdoc

Don't merge cfg and doc(cfg) attributes for re-exports

Fixes rust-lang#112881.

## Explanations

When re-exporting things with different `cfg`s there are two things that can happen:

 * The re-export uses a subset of `cfg`s, this subset is sufficient so that the item will appear exactly with the subset
 * The re-export uses a non-subset of `cfg`s (e.g. like the example I posted just above where the re-export is ungated), if the non-subset `cfg`s are active (e.g. compiling that example on windows) then this will be a compile error as the item doesn't exist to re-export, if the subset `cfg`s are active it behaves like 1.

### Glob re-exports?

**This only applies to non-glob inlined re-exports.** For glob re-exports the item may or may not exist to be re-exported (potentially the `cfg`s on the path up until the glob can be removed, and only `cfg`s on the globbed item itself matter), for non-inlined re-exports see rust-lang#85043.

cc `@Nemo157`
r? `@notriddle`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants