Skip to content

doc_auto_cfg no longer applies a cfg badge to certain inlined cross-crate re-exported items with a #[cfg] #141301

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

Open
epage opened this issue May 20, 2025 · 10 comments
Labels
A-cfg Area: `cfg` conditional compilation A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. F-doc_auto_cfg `#![feature(doc_auto_cfg)]` S-has-bisection Status: A bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@epage
Copy link
Contributor

epage commented May 20, 2025

I tried something like this code:

clap_builder:

#[cfg(feature = "env")]
pub fn env() {}

clap:

pub use clap_builder::env;

I expected to see this happen: a cfg badge appears in both clap and clap_builders docs for this function

Instead, this happened: the cfg badge only appears on clap_builder

Meta

docs.rs build on 2025-03-27 (4.5.34) worked for clap and clap_builder

docs.rs build on 2025-04-01 (4.5.35) didn't work for clap while clap_builder did

clap diff

clap_builder diff

Backtrace

<backtrace>

@epage epage 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_auto_cfg `#![feature(doc_auto_cfg)]` labels May 20, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 20, 2025
@fmease fmease added E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 20, 2025
@fmease
Copy link
Member

fmease commented May 20, 2025

@fmease fmease added A-cfg Area: `cfg` conditional compilation A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example and removed S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. labels May 20, 2025
@fmease
Copy link
Member

fmease commented May 20, 2025

Actually, this never(?) worked for free items (as contained in the issue description), only ever(?) for associated items. That's odd on its own and should be dealt with, too. The question is: Which of the two is the expected behavior? Not accurate, free items are also affected if downstream uses a glob import instead of explicitly/individually naming the item(s) in question (that's still odd, tho, and needs to be investigated).

@fmease
Copy link
Member

fmease commented May 20, 2025

MCVE:

rustc dep.rs --crate-type=lib --cfg cond:

pub struct Owner;
impl Owner { #[cfg(cond)] pub fn func() {} 

rustdoc usr.rs -L.:

#![feature(doc_auto_cfg)]
extern crate dep;
pub use dep::Owner;

@fmease fmease added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels May 20, 2025
@fmease
Copy link
Member

fmease commented May 20, 2025

My crude manual bisection leads me to believe that PR #138844 most likely regressed this.

@fmease fmease added S-has-bisection Status: A bisection has been found for this issue and removed E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels May 20, 2025
@fmease fmease changed the title doc_auto_cfg used to apply a cfg badge to items with a #[cfg] that were re-export but no longer does doc_auto_cfg no longer applies a cfg badge to inlined cross-crate re-exported associated(!) items with a #[cfg] May 20, 2025
@fmease fmease added the A-associated-items Area: Associated items (types, constants & functions) label May 20, 2025
@fmease fmease changed the title doc_auto_cfg no longer applies a cfg badge to inlined cross-crate re-exported associated(!) items with a #[cfg] doc_auto_cfg no longer applies a cfg badge to certain inlined cross-crate re-exported items with a #[cfg] May 20, 2025
@fmease fmease removed the A-associated-items Area: Associated items (types, constants & functions) label May 20, 2025
@fmease
Copy link
Member

fmease commented May 20, 2025

MCVE with a free item (the glob import over an explicit/individual import is imperative for the repro (the latter never "worked")):

rustc dep.rs --crate-type=lib --cfg cond:

#[cfg(cond)] pub fn func() {}

rustdoc usr.rs -L.:

#![feature(doc_auto_cfg)]
extern crate dep;
pub use dep::*;

@fmease
Copy link
Member

fmease commented May 21, 2025

cc @GuillaumeGomez

@GuillaumeGomez
Copy link
Member

I'm gonna take a look once #138907 will be merged.

@fmease
Copy link
Member

fmease commented May 27, 2025

I think we now simply need to look for cfg_trace and cfg_attr_trace instead of cfg and cfg_attr respectively when we're cross-crate inlining.

I haven't investigated anything that's just what I remember from reading petrochenkov's PRs when they were newly opened.

@GuillaumeGomez
Copy link
Member

Yes we do but it's already done in #138907 so I think it's better to check if it's still an issue once merged to reduce the workload for us. :3

@Nemo157
Copy link
Member

Nemo157 commented May 27, 2025

Huh, I'm surprised that ever worked, how is rustdoc supposed to know whether these cfg should be shown? They make sense in the case of façade crates with the same set of features as the crates they reëxport from, but not in other reëxport cases (and not every façade crate will use the exact same feature names as their components too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cfg Area: `cfg` conditional compilation A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. F-doc_auto_cfg `#![feature(doc_auto_cfg)]` S-has-bisection Status: A bisection has been found for this issue S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants