Skip to content

Rustdoc doesn't show src button for many functions in the rustc docs #70025

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
bjorn3 opened this issue Mar 15, 2020 · 14 comments
Closed

Rustdoc doesn't show src button for many functions in the rustc docs #70025

bjorn3 opened this issue Mar 15, 2020 · 14 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@bjorn3
Copy link
Member

bjorn3 commented Mar 15, 2020

https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html

image

@bjorn3 bjorn3 added the C-bug Category: This is a bug. label Mar 15, 2020
@bjorn3
Copy link
Member Author

bjorn3 commented Mar 15, 2020

@rustbot modify labels:+C-bug +T-rustdoc

@rustbot rustbot added C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Mar 15, 2020
@ehuss
Copy link
Contributor

ehuss commented Mar 29, 2020

I have narrowed this down to #66364. There some interaction between remap-path-prefix and macros in a dependency.

Repro:

cargo new --lib foo
cd foo
cargo new --lib dep
rm dep/src/lib.rs
cat << EOF > dep/src/lib.rs
#[macro_export]
macro_rules! make_item {
    () => {
        pub fn f() {}
    }
}
EOF

echo 'dep = {path="dep"}' >> Cargo.toml
echo 'dep::make_item!{}' >> src/lib.rs
RUSTFLAGS="--remap-path-prefix=`pwd`=/" cargo doc -v  --no-deps

This emits a warning:

warning: source code was requested to be rendered, but processing `/dep/src/lib.rs` had an error: "/dep/src/lib.rs": No such file or directory (os error 2)

and the [src] links don't exist.

If you want to repro with the rustc sources, set remap-debuginfo = true and compiler-docs = true in config.toml and build the rustc docs.

@Centril can you maybe take a look at why this is now broken?

@Centril
Copy link
Contributor

Centril commented Mar 30, 2020

For now, I'll cc @GuillaumeGomez @eddyb @petrochenkov who probably know more about this than I.

@Centril

This comment has been minimized.

@Centril
Copy link
Contributor

Centril commented Mar 31, 2020

Also relevant:

// If we're including source files, and we haven't seen this file yet,
// then we need to render it out to the filesystem.
if self.scx.include_sources
// skip all synthetic "files"
&& item.source.filename.is_real()
// skip non-local items
&& item.def_id.is_local()
{
// If it turns out that we couldn't read this file, then we probably
// can't read any of the files (generating html output from json or
// something like that), so just don't include sources for the
// entire crate. The other option is maintaining this mapping on a
// per-file basis, but that's probably not worth it...
self.scx.include_sources = match self.emit_source(&item.source.filename) {
Ok(()) => true,
Err(e) => {
println!(
"warning: source code was requested to be rendered, \
but processing `{}` had an error: {}",
item.source.filename, e
);

@eddyb
Copy link
Member

eddyb commented Mar 31, 2020

Hang on, but there should be no macros involved in the impl @bjorn3 posted, how is #66364 relevant?

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 31, 2020

That code sets self.scx.include_sources to false when any file could not be read.

@eddyb
Copy link
Member

eddyb commented Mar 31, 2020

Oh, that's just bad UX and should be fixed independently on not being able to load some file.

@eddyb
Copy link
Member

eddyb commented Apr 1, 2020

@Mark-Simulacrum Is there any way to use the try build on #70642 to check if it fixes this issue?
i.e. does it include any docs?

@Mark-Simulacrum
Copy link
Member

Mark-Simulacrum commented Apr 1, 2020

I think it should, but not sure. We have a try build going and once that's done IIRC a command like rustup-toolchain-install-master 40f2b445cd1c6c4e72d663d23c6d1bef2c674ad4 -c rust-docs should work, I believe.

@eddyb
Copy link
Member

eddyb commented Apr 2, 2020

@Mark-Simulacrum Uh oh I can't get anything like https://doc.rust-lang.org/nightly/nightly-rustc even for regular nightly in rustup, and none of alloc/core/proc_macro/std/test are affected.

Also, since this seems to affect the whole crate, it's easier to spot at that level:

And that's all the affected crates! Each uses macros from other crates, which define something.


thread_local! stands out as being from the standard library. Sure enough:

thread_local!(pub static FOO: bool = false);
$ cargo doc
 Documenting test-70025 v0.1.0 (/home/eddy/Projects/test-70025)
warning: source code was requested to be rendered, but processing `/rustc/76b11980ad416c3ad6143504c2277757ecacf9b5/src/libstd/thread/local.rs` had an error: "/rustc/76b11980ad416c3ad6143504c2277757ecacf9b5/src/libstd/thread/local.rs": No such file or directory (os error 2)
         skipping rendering of source code
    Finished dev [unoptimized + debuginfo] target(s) in 3.53s

But with #70642, it works:

$ rustup-toolchain-install-master 40f2b445cd1c6c4e72d663d23c6d1bef2c674ad4 -c rust-src
$ cargo +40f2b445cd1c6c4e72d663d23c6d1bef2c674ad4 doc
 Documenting test-70025 v0.1.0 (/home/eddy/Projects/test-70025)
    Finished dev [unoptimized + debuginfo] target(s) in 2.21s
$ find target/doc/src/ | rg html
target/doc/src/test_70025/lib.rs.html
target/doc/src/test_70025/home/eddy/.rustup/toolchains/40f2b445cd1c6c4e72d663d23c6d1bef2c674ad4/lib/rustlib/src/rust/src/libstd/thread/local.rs.html

However, I have no way to check the CI environment itself, so we'll have to wait for #70642 to land.

@eddyb
Copy link
Member

eddyb commented Apr 2, 2020

Something rustdoc could be doing, though, is checking which CrateNum a file is imported from, and try to use that crate's doc URLs, or at the very least use a separate doc/src dir, e.g. instead of:

  • target/doc/src/test_70025/home/eddy/.rustup/toolchains/40f2b445cd1c6c4e72d663d23c6d1bef2c674ad4/lib/rustlib/src/rust/src/libstd/thread/local.rs.html

it should probably have created:

  • target/doc/src/std/thread/local.rs.html

@jonas-schievink jonas-schievink added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Apr 2, 2020
@eddyb
Copy link
Member

eddyb commented Apr 3, 2020

#70642 landed, let's see what happens in 14-15h from now.

@eddyb
Copy link
Member

eddyb commented Apr 4, 2020

And the source is back! So I'm closing this issue, and I've opened #70757 for the remaining items.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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

7 participants