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

cfg(doc) is not respected on cross-crate re-export #114952

Open
notriddle opened this issue Aug 17, 2023 · 6 comments
Open

cfg(doc) is not respected on cross-crate re-export #114952

notriddle opened this issue Aug 17, 2023 · 6 comments
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@notriddle
Copy link
Contributor

I tried this code:

// crate a
pub struct MyStruct;
#[cfg(doc)]
impl MyStruct {
    pub fn doc_only_method() {}
}

// crate b
#[doc(inline)]
pub use a::MyStruct;

I expected to see this happen: I expected doc_only_method to appear in crate b

Instead, this happened: It didn't.

Meta

This issue can be reproduced in both the stable and nightly version of the compiler.

@notriddle notriddle added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate labels Aug 17, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 17, 2023
@GuillaumeGomez GuillaumeGomez removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 18, 2023
@GuillaumeGomez
Copy link
Member

I think it's because the deps are not built with this cfg, only when rustdoc is run on them do we have them.

@fmease
Copy link
Member

fmease commented Aug 18, 2023

Yes, exactly.

This is essentially a Cargo issue. If you were to manually use rustc and rustdoc to document your projects, you could just pass --cfg doc to each rustc invocation to avoid this issue entirely.

If I understand cargo doc correctly, for a project with N crates, it calls rustc N-1 times (to produce .rmeta files for cross-crate reexports) and rustdoc N times1 assuming a clean target directory. Now, we could in theory update cargo doc to pass --cfg doc to each rustc invocation. However that would force Cargo to recompile every single dependency whereas presently it can just reuse .rmeta files produced in a previous cargo <check|build|run> run which greatly reduces the time it takes to document your project.

Correct me if I'm wrong. cargo doc --verbose tells you the rustc and rustdoc invocations.

Footnotes

  1. For cargo doc --no-deps, I think it's rustc N-1 times, rustdoc 1 time

@Fryuni
Copy link

Fryuni commented Aug 18, 2023

I think cargo doc doesn't set this config at all, it is injected by rustdoc in the generate_config function if I'm not mistaken. I'd post a link but copy link is not working correctly on my phone.

I though rustdoc was responsible for recursing through the dependencies, but if it gets information from executions of rust then this should be added to cargo doc

@fmease
Copy link
Member

fmease commented Aug 18, 2023

You might be right about generate_config, although that shouldn't contradict anything I was saying. Cargo doesn't pass --cfg doc to rustc which is the problem. The .rmeta files used by cross-crate reexports represent crates that weren't compiled with --cfg doc while ideally they would but that would require recompilation (cfgs have changed) drastically worsening the build times of docs in incremental settings.

Disclaimer: This is just what I can remember, I haven't double-checked any of this.

@fmease
Copy link
Member

fmease commented Aug 19, 2023

I though rustdoc was responsible for recursing through the dependencies

No, neither rustc nor rustdoc do that, that's the task of Cargo (or of any other Rust package manager).

@Fryuni
Copy link

Fryuni commented Aug 20, 2023

Should we open an issue about this on cargo then? (Or someone did that already? If yes could share the link here pls)

I opened an issue there: rust-lang/cargo#12533

I found a few possibly related issues, but not specific for this:

Since the doc config is currently added by rustdoc itself it seems this is not handled by cargo at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. 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