-
Notifications
You must be signed in to change notification settings - Fork 13.7k
fix rustdoc render_call_locations
panicking because of default span DUMMY_SP
pointing at non local-source file
#146091
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
fix rustdoc render_call_locations
panicking because of default span DUMMY_SP
pointing at non local-source file
#146091
Conversation
r? rustdoc |
src/librustdoc/html/render/mod.rs
Outdated
@@ -2829,7 +2829,21 @@ fn render_call_locations<W: fmt::Write>( | |||
file.start_pos + BytePos(byte_max), | |||
)) | |||
})() | |||
.unwrap_or(DUMMY_SP); | |||
.unwrap_or_else(|| { |
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.
Instead of cloning parts of the above code, I think it'd might be simpler to instead tweak it a bit:
let local = tcx.sess.local_crate_source_file()?;
let crate_src = local.into_local_path()?;
let abs_crate_src = crate_src.canonicalize().ok()?;
let crate_root = abs_crate_src.parent()?.parent()?;
let rel_path = path.strip_prefix(crate_root).ok()?;
let files = source_map.files();
let file = files.iter().find(|file| match &file.name {
FileName::Real(RealFileName::LocalPath(other_path)) => rel_path == other_path,
_ => false,
}).or_else(|| files.iter().find(|file| matches!(&file.name, FileName::Real(file_name) if file_name == &local))?;
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.
Then we can replace the unwrap_or(DUMMY_SP)
with expect("no local file found")
.
Some changes occurred in GUI tests. |
@@ -0,0 +1,9 @@ | |||
//@ run-flags:-Zrustdoc-scrape-examples | |||
//@ rustc-env: RUSTDOCFLAGS='--html-after-content after.html' |
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.
Please pass --html-after-content after.html
directly in run-flags
.
Also please squash your commits once done. |
This comment has been minimized.
This comment has been minimized.
a177355
to
6a3975e
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
6a3975e
to
6c8d64e
Compare
This comment has been minimized.
This comment has been minimized.
6c8d64e
to
65567a7
Compare
@@ -52,7 +52,7 @@ compare-elements-size-near: ( | |||
set-window-size: (900, 900) | |||
|
|||
// First we check the current width, height and position. | |||
assert-css: ("#crate-search", {"width": "159px"}) | |||
assert-css: ("#crate-search", {"width": "185px"}) |
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.
This change is because the longest crate name increased.
Note for myself, once merged, I'll need to add a test for the extra HTML added. |
This comment has been minimized.
This comment has been minimized.
…file outside of local_sources add test against crashing with --html-after-content file correctly add --html-after-content to env not args formatting fix for rustdoc-call-locations-after-content/rmake.rs Use local crate source file as default span in `render_call_locations` - avoids unwrapping the first file added to the source map as a local file in `href_from_span` move test to tests/rustdoc-gui, rename to scrape_examples_ice test link is correct use rustdocflags, rename path in example, track lock file factor out duplicate function calls use compile-flags to make sure the after.html file is actually included in the rustdoc call fix goml go-to path increment assert-count in sidebar-source-code.goml adjust crate-search width in search-result-display.goml renamed Bar in scrape_examples_ice test make crate name shorter ..
65567a7
to
f67e29e
Compare
Thanks for the fix! @bors r+ rollup |
Rollup of 14 pull requests Successful merges: - #144066 (stabilize c-style varargs for sysv64, win64, efiapi, aapcs) - #145783 (add span to struct pattern rest (..)) - #146034 (Update target spec metadata of Arm64EC Windows and Trusty targets) - #146064 (Add compiler error when trying to use concat metavar expr in repetitions) - #146070 (rustdoc-search: skip loading unneeded fnData) - #146088 (constify impl Try for ControlFlow) - #146089 (fix a constness ordering bug in rustfmt) - #146091 (fix rustdoc `render_call_locations` panicking because of default span `DUMMY_SP` pointing at non local-source file) - #146094 (Make `Parser::parse_for_head` public for rustfmt usage) - #146102 (Remove dead code stemming from an old effects desugaring) - #146115 (Add maintainer for VxWorks) - #146116 (Adjust issue-118306.rs test after LLVM change) - #146117 (Fix search index generation) - #146118 (improve process::abort rendering in Miri backtraces) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146091 - janis-bhm:rustdoc-default-span-with-simple-test, r=GuillaumeGomez fix rustdoc `render_call_locations` panicking because of default span `DUMMY_SP` pointing at non local-source file fixes #144752 related to/builds on #145008 bevy still crashes in the same way as #144752 when building docs on nightly, and from what I can tell the cause seems to be the following (copied from zulip [#t-rustdoc > docs on nightly with example scrapes crash](https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/docs.20on.20nightly.20with.20example.20scrapes.20crash)): > render_call_locations tries to [find](https://github.com/rust-lang/rust/blob/84a17470220e7adf249b18d7c0178dfbede89462/src/librustdoc/html/render/mod.rs#L2816) the source span of a call to add as an example, but the example files are never actually in the source map from what I can tell, and so it falls back to the default span, which points at the first file in the source map. > Now, the issue that guillaume mentions [here](#145008) adds new files to the source map in order to get them into the dep info, and that leads to some files, namely docs-rs/trait-tags.html in the case of bevy because it's added with --html-after-content, being added before any source files, so then the default span points at them, and when href_from_span tries to find the [source file](https://github.com/rust-lang/rust/blob/84a17470220e7adf249b18d7c0178dfbede89462/src/librustdoc/html/render/context.rs#L368) corresponding to the span, the file doesn't belong to local_sources, and it short circuits. > This can be fixed by just not using DUMMY_SP as the default span and calculating, for example, the crates root source file as the span, because I'm not entirely sure what the href from that span is actually used for; it's not what links to the example in the end. > I think the proper way of fixing this would be to make sure the example files are part of the local_sources or at least the source map, but I don't know nearly enough about rust internals to be able to figure out how to fix that. I've included a test that's mostly copied from #145008's test with the addition of `--html-after-content after.html` in the `RUSTDOCFLAGS`, which panics on master in conjunction with the `-Zrustdoc-scrape-examples` cargo flag. cc `@GuillaumeGomez`
Rollup of 14 pull requests Successful merges: - rust-lang/rust#144066 (stabilize c-style varargs for sysv64, win64, efiapi, aapcs) - rust-lang/rust#145783 (add span to struct pattern rest (..)) - rust-lang/rust#146034 (Update target spec metadata of Arm64EC Windows and Trusty targets) - rust-lang/rust#146064 (Add compiler error when trying to use concat metavar expr in repetitions) - rust-lang/rust#146070 (rustdoc-search: skip loading unneeded fnData) - rust-lang/rust#146088 (constify impl Try for ControlFlow) - rust-lang/rust#146089 (fix a constness ordering bug in rustfmt) - rust-lang/rust#146091 (fix rustdoc `render_call_locations` panicking because of default span `DUMMY_SP` pointing at non local-source file) - rust-lang/rust#146094 (Make `Parser::parse_for_head` public for rustfmt usage) - rust-lang/rust#146102 (Remove dead code stemming from an old effects desugaring) - rust-lang/rust#146115 (Add maintainer for VxWorks) - rust-lang/rust#146116 (Adjust issue-118306.rs test after LLVM change) - rust-lang/rust#146117 (Fix search index generation) - rust-lang/rust#146118 (improve process::abort rendering in Miri backtraces) r? `@ghost` `@rustbot` modify labels: rollup
…d-examples, r=lolbinarycat [rustdoc] Uncomment code to add scraped rustdoc examples in loaded paths Since the bug was fixed in rust-lang#146091, we can now uncomment the code. :) r? lolbinarycat
…s, r=lolbinarycat [rustdoc] Uncomment code to add scraped rustdoc examples in loaded paths Since the bug was fixed in rust-lang/rust#146091, we can now uncomment the code. :) r? lolbinarycat
… r=lolbinarycat Ensure that `--html-after-content` option is used to check `scrape_examples_ice` rustdoc GUI test Follow-up of rust-lang#146091. This test ensures that the spans are correctly handled when a "local source file" is not the first in the file list. To ensure it's actually what's tested, this test checks that the option is actually used by adding an element. r? `@lolbinarycat`
Rollup merge of #146242 - GuillaumeGomez:rustdoc-gui-scrape, r=lolbinarycat Ensure that `--html-after-content` option is used to check `scrape_examples_ice` rustdoc GUI test Follow-up of #146091. This test ensures that the spans are correctly handled when a "local source file" is not the first in the file list. To ensure it's actually what's tested, this test checks that the option is actually used by adding an element. r? `@lolbinarycat`
fixes #144752
related to/builds on #145008
bevy still crashes in the same way as #144752 when building docs on nightly, and from what I can tell the cause seems to be the following (copied from zulip #t-rustdoc > docs on nightly with example scrapes crash):
I've included a test that's mostly copied from #145008's test with the addition of
--html-after-content after.html
in theRUSTDOCFLAGS
, which panics on master in conjunction with the-Zrustdoc-scrape-examples
cargo flag.cc @GuillaumeGomez