# Source code on docs.rs: ambiguous and obscure

**URL:** <https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438>\
**Category:** tools and infrastructure\
**Created:** [July 6, 2026, 11:16pm UTC](https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438 "2026-07-06T23:16:07Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![programmerjake](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/programmerjake/32/5893_2.png) [@programmerjake](https://internals.rust-lang.org/u/programmerjake)\
**Post date:** [July 10, 2026, 11:04pm UTC](https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438/22 "2026-07-10T23:04:56Z")

</div>

this makes me think that there should be a way for rustdoc's output to be merged with the source view so all files are present, it errors if rustdoc's output doesn't match the source (to catch malicious builds), and it just has rustdoc's extra features on the files that rustdoc processed, other files will just have code highlighting and that's it.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [July 11, 2026, 2:21am UTC](https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438/23 "2026-07-11T02:21:53Z")

</div>

The default doc build is done on Linux, so a conditional include like this:

> **[windows.rs - source](https://docs.rs/tokio/1.52.3/src/tokio/signal/windows.rs.html)**
>
> Source of the Rust file \`src/signal/windows.rs\`.

includes:

> **[stub.rs - source](https://docs.rs/tokio/1.52.3/src/tokio/signal/windows/stub.rs.html)**
>
> Source of the Rust file \`src/signal/windows/stub.rs\`.

and you don't see `windows/sys.rs` in the file tree sidebar, as if the file didn't exist.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [July 11, 2026, 10:44am UTC](https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438/24 "2026-07-11T10:44:34Z")

</div>

> [@programmerjake](#):
>
> this makes me think that there should be a way for rustdoc's output to be merged with the source view so all files are present, it errors if rustdoc's output doesn't match the source (to catch malicious builds), and it just has rustdoc's extra features on the files that rustdoc processed, other files will just have code highlighting and that's it.

That merging would have to be done outside of rustdoc and would need to apply a sanitizer to the rustdoc output to remove any `display: none;` or equivalent that could affect the source view in a way that confuses the user. Because of proc-macros getting loaded by rustdoc, the rustdoc source pages can contain arbitrary html and javascript.

---

<div class="post-metadata">

**Author:** ![decathorpe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/decathorpe/32/12334_2.png) [@decathorpe](https://internals.rust-lang.org/u/decathorpe)\
**Post date:** [July 15, 2026, 4:08pm UTC](https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438/25 "2026-07-15T16:08:42Z")

</div>

> [@kornel](#):
>
> I've looked in detail into git\<\>crate correspondence and it's a mess:

You might be interested in [ingredients](https://crates.io/crates/ingredients) which attempts to work around the mess to some degree, and give decently meaningful information. It seems to work well in testing against the ~3000 Rust crates we have packaged in Fedora Linux, and I'm working on integrating it into our packaging workflow.

But in general I 💯 agree with

> [@kornel](#):
>
> In the end you have to look at the same source that Cargo gets. Cargo doesn't get source from git, so trying to look at git will only make it a weaker, potentially misleading derivative. Making users aware where is the true content of a crate is technically way simpler than trying to build a secure chain between a git repo and what Cargo compiles (fetching via git protocol has a bunch of trust and perf issues)

and this is also why for Fedora packaging, we treat what is published to / distributed by cratesio as the canonical source for all Rust crates, and the tooling I'm working on is only supposed to provide immediate informational value (for example, knowing that the linked repository no longer exists can be valuable).

---

<div class="post-metadata">

**Author:** ![Vorpal](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vorpal](https://internals.rust-lang.org/u/Vorpal)\
**Post date:** [July 18, 2026, 10:02pm UTC](https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438/26 "2026-07-18T22:02:26Z")

</div>

> [@kpreid](#):
>
> As far as I know, the displayed text of the files that are present will always be the same, modulo build-time malicious code.

What about generated code from build scripts? Things like protobufs in prost should presumably not vary by platform, but I could conceivably see cases where generated code varied by target platform rather than generating macros and cfgs to deal with that. Perhaps a reasonable example would be FFI bindings to OS libraries that vary by platform and specific version.

[Previous page](https://internals.rust-lang.org/t/source-code-on-docs-rs-ambiguous-and-obscure/24438.md?page=1)
