Skip to content

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

Closed
@Nemo157

Description

@Nemo157

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.

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-doc_cfg`#![feature(doc_cfg)]`T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions