-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustdoc: Don't try to load source files from external crates #70828
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ use crate::html::format::Buffer; | |
use crate::html::highlight; | ||
use crate::html::layout; | ||
use crate::html::render::{Error, SharedContext, BASIC_KEYWORDS}; | ||
use rustc_hir::def_id::LOCAL_CRATE; | ||
use rustc_span::source_map::FileName; | ||
use std::ffi::OsStr; | ||
use std::fs; | ||
|
@@ -37,8 +38,8 @@ impl<'a> DocFolder for SourceCollector<'a> { | |
if self.scx.include_sources | ||
// skip all synthetic "files" | ||
&& item.source.filename.is_real() | ||
// skip non-local items | ||
&& item.def_id.is_local() | ||
// skip non-local files | ||
&& item.source.cnum == LOCAL_CRATE | ||
{ | ||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to close #70757 without fixing the thing where Feel free to leave a FIXME comment and open an issue about it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I guess we can leave #70757 open to track removing this error case. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// compile-flags:--remap-path-prefix={{src-base}}=/does-not-exist | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surprised |
||
|
||
#![doc(html_root_url = "https://example.com/")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test that uses The libstd URLs should be already valid today, so it'd be a good test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now added a test using |
||
|
||
#[macro_export] | ||
macro_rules! make_foo { | ||
() => { | ||
pub struct Foo; | ||
impl Foo { | ||
pub fn new() -> Foo { | ||
Foo | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// aux-build:external-macro-src.rs | ||
// ignore-tidy-linelength | ||
|
||
#![crate_name = "foo"] | ||
|
||
#[macro_use] | ||
extern crate external_macro_src; | ||
|
||
// @has foo/index.html '//a[@href="../src/foo/external-macro-src.rs.html#4-15"]' '[src]' | ||
|
||
// @has foo/struct.Foo.html | ||
// @has - '//a[@href="https://example.com/src/external_macro_src/external-macro-src.rs.html#8"]' '[src]' | ||
// @has - '//a[@href="https://example.com/src/external_macro_src/external-macro-src.rs.html#9-13"]' '[src]' | ||
// @has - '//a[@href="https://example.com/src/external_macro_src/external-macro-src.rs.html#10-12"]' '[src]' | ||
make_foo!(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![crate_name = "foo"] | ||
|
||
// @has foo/index.html '//a[@href="../src/foo/thread-local-src.rs.html#1-6"]' '[src]' | ||
|
||
// @has foo/constant.FOO.html '//a/@href' 'https://doc.rust-lang.org/nightly/src/std/' | ||
thread_local!(pub static FOO: bool = false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh this is really simple. Although, perhaps a better thing to do would be to keep
lo.file
? And remove thespan_to_filename
call, which is then wasteful.Also cc @Aaron1011 I hope this will continue to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually what I originally tried but it ended up quite a bit more complicated than this. The main advantage to keeping the full
SourceFile
is that rustdoc won't have to load the source files from disk again. I plan to do that as a follow up.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eddyb: This looks good to me: were you thinking of imported spans/hygiene?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly knowing the
CrateNum
a file came from.