rustdoc output directory structure leaks home directory structure
Since Rust-CI has been continuously failing I've been looking to move my docs to GitHub Pages. This led me to notice that when rustdoc is called with an absolute path as input (as cargo does) the files in doc/src will show your entire home directory layout.
This is problematic not only because of the leak of someone's home directory layout, but because those links will break if I build from a new directory, a new computer, and a different contributor commits those changes. Also if you have 2+ contributors you're going to have massive churn on a repo checking in those files. Least importantly the URLs are ugly when clicking on a src link. :)
As an example on Rust's own API docs, If you click the [src] link on http://doc.rust-lang.org/std/vec/ you end up at http://doc.rust-lang.org/src/collections/home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libcollections/vec.rs.html#11-2901
I think this is fixed by #19436.
Kang Seonghoon at 2014-12-02 08:36:16
Thanks @lifthrasiir!
Alex Crichton at 2014-12-03 08:08:36
Thanks @lifthrasiir !
gary at 2014-12-03 08:21:21
This appears to be a problem again. I'm seeing stuff like
<a class='srclink' href='../../src/msfs/home/snek/Desktop/projects/msfs-rs/target/debug/build/msfs-7d0246a486c664b1/out/bindings.rs.html#3101' title='goto source code'>[src]</a>in my output.
snek at 2020-11-03 18:14:09
That looks like it's specific to files generated by build scripts, I haven't seen it for most pages.
jyn at 2020-11-05 22:49:43
Isn't it possible only for local builds? On docs.rs and hosted docs, it shouldn't be possible, no?
Guillaume Gomez at 2020-11-06 18:41:34
Hmm, I thought it was possible on docs.rs, but looking at https://docs.rs/zstd-sys/1.4.17+zstd.1.4.5/zstd_sys/struct.ZSTD_DDict_s.html it looks like the file path is not leaked. I could have sworn I'd seen this on docs.rs before, though.
jyn at 2020-11-06 18:48:11
What does docs.rs do differently so that this doesn't occur? @GuillaumeGomez
snek at 2020-11-06 20:13:38
Triage: This is happening on docs.rs too: https://docs.rs/mbedtls-sys-auto/2.26.0/src/mbedtls_sys/opt/rustwide/target/debug/build/mbedtls-sys-auto-bbf58e089d61f478/out/bindings.rs.html
jyn at 2021-04-08 18:41:37
I'm not sure this is rustdoc's fault - it does the same thing for build scripts as for anything else: https://github.com/rust-lang/rust/blob/010c2368fa33ef08df3080228498db8d2ba5a93b/src/librustdoc/html/sources.rs#L48 Maybe there's some bug in
span_to_filename? https://github.com/rust-lang/rust/blob/010c2368fa33ef08df3080228498db8d2ba5a93b/compiler/rustc_span/src/source_map.rs#L473-L475jyn at 2021-04-08 18:45:21