Open
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
#[repr(transparent)]
where the field is non-public #90435GuillaumeGomez commentedon Aug 18, 2023
I think it's because the deps are not built with this
cfg
, only whenrustdoc
is run on them do we have them.fmease commentedon Aug 18, 2023
Yes, exactly.
This is essentially a Cargo issue. If you were to manually use
rustc
andrustdoc
to document your projects, you could just pass--cfg doc
to eachrustc
invocation to avoid this issue entirely.If I understand
cargo doc
correctly, for a project with N crates, it callsrustc
N-1 times (to produce.rmeta
files for cross-crate reexports) andrustdoc
N times1 assuming a cleantarget
directory. Now, we could in theory updatecargo doc
to pass--cfg doc
to eachrustc
invocation. However that would force Cargo to recompile every single dependency whereas presently it can just reuse.rmeta
files produced in a previouscargo <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 therustc
andrustdoc
invocations.Footnotes
For
cargo doc --no-deps
, I think it'srustc
N-1 times,rustdoc
1 time ↩Fryuni commentedon 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 commentedon 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
torustc
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 (cfg
s 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 commentedon Aug 19, 2023
No, neither
rustc
norrustdoc
do that, that's the task of Cargo (or of any other Rust package manager).Fryuni commentedon 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:
--cfg doc
for build scripts cargo#8944#[cfg(doc)]
does not work inCargo.toml
cargo#11570Since the
doc
config is currently added by rustdoc itself it seems this is not handled by cargo at all.doc
cfg to rustc when running cargo doc rust-lang/cargo#12533#[repr(transparent)]
if it isn't part of the public ABI #1154394 remaining items