fix rustdoc `render_call_locations` panicking because of default span `DUMMY_SP` pointing at non local-source file by janis-bhm · Pull Request #146091 · rust-lang/rust

@rustbot rustbot added A-run-make

Area: port run-make Makefiles to rmake.rs

S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

T-rustdoc

Relevant to the rustdoc team, which will review and decide on the PR/issue.

T-rustdoc-frontend

Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

labels

Sep 1, 2025

GuillaumeGomez

GuillaumeGomez

GuillaumeGomez

@janis-bhm

…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 ..

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Sep 2, 2025

GuillaumeGomez

bors added a commit that referenced this pull request

Sep 2, 2025
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

rust-timer added a commit that referenced this pull request

Sep 2, 2025
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`

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request

Sep 3, 2025

Zalathar added a commit to Zalathar/rust that referenced this pull request

Sep 4, 2025
…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

rust-timer added a commit that referenced this pull request

Sep 4, 2025
Rollup merge of #146161 - GuillaumeGomez:loaded-paths-scraped-examples, r=lolbinarycat

[rustdoc] Uncomment code to add scraped rustdoc examples in loaded paths

Since the bug was fixed in #146091, we can now uncomment the code. :)

r? lolbinarycat

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request

Sep 5, 2025
…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

fmease added a commit to fmease/rust that referenced this pull request

Sep 5, 2025
… 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`

rust-timer added a commit that referenced this pull request

Sep 5, 2025
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`

github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request

Sep 8, 2025
…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

rust-cloud-vms bot pushed a commit to makai410/rustc_public that referenced this pull request

Oct 12, 2025

makai410 pushed a commit to makai410/rust that referenced this pull request

Nov 8, 2025
…llaumeGomez

Rollup of 14 pull requests

Successful merges:

 - rust-lang#144066 (stabilize c-style varargs for sysv64, win64, efiapi, aapcs)
 - rust-lang#145783 (add span to struct pattern rest (..))
 - rust-lang#146034 (Update target spec metadata of Arm64EC Windows and Trusty targets)
 - rust-lang#146064 (Add compiler error when trying to use concat metavar expr in repetitions)
 - rust-lang#146070 (rustdoc-search: skip loading unneeded fnData)
 - rust-lang#146088 (constify impl Try for ControlFlow)
 - rust-lang#146089 (fix a constness ordering bug in rustfmt)
 - rust-lang#146091 (fix rustdoc `render_call_locations`  panicking because of default span `DUMMY_SP` pointing at non local-source file)
 - rust-lang#146094 (Make `Parser::parse_for_head` public for rustfmt usage)
 - rust-lang#146102 (Remove dead code stemming from an old effects desugaring)
 - rust-lang#146115 (Add maintainer for VxWorks)
 - rust-lang#146116 (Adjust issue-118306.rs test after LLVM change)
 - rust-lang#146117 (Fix search index generation)
 - rust-lang#146118 (improve process::abort rendering in Miri backtraces)

r? `@ghost`
`@rustbot` modify labels: rollup

makai410 pushed a commit to makai410/rust that referenced this pull request

Nov 10, 2025
…h-simple-test, r=GuillaumeGomez

fix rustdoc `render_call_locations`  panicking because of default span `DUMMY_SP` pointing at non local-source file

fixes rust-lang#144752
related to/builds on rust-lang#145008

bevy still crashes in the same way as rust-lang#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](rust-lang#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 rust-lang#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`

makai410 pushed a commit to makai410/rust that referenced this pull request

Nov 10, 2025
…llaumeGomez

Rollup of 14 pull requests

Successful merges:

 - rust-lang#144066 (stabilize c-style varargs for sysv64, win64, efiapi, aapcs)
 - rust-lang#145783 (add span to struct pattern rest (..))
 - rust-lang#146034 (Update target spec metadata of Arm64EC Windows and Trusty targets)
 - rust-lang#146064 (Add compiler error when trying to use concat metavar expr in repetitions)
 - rust-lang#146070 (rustdoc-search: skip loading unneeded fnData)
 - rust-lang#146088 (constify impl Try for ControlFlow)
 - rust-lang#146089 (fix a constness ordering bug in rustfmt)
 - rust-lang#146091 (fix rustdoc `render_call_locations`  panicking because of default span `DUMMY_SP` pointing at non local-source file)
 - rust-lang#146094 (Make `Parser::parse_for_head` public for rustfmt usage)
 - rust-lang#146102 (Remove dead code stemming from an old effects desugaring)
 - rust-lang#146115 (Add maintainer for VxWorks)
 - rust-lang#146116 (Adjust issue-118306.rs test after LLVM change)
 - rust-lang#146117 (Fix search index generation)
 - rust-lang#146118 (improve process::abort rendering in Miri backtraces)

r? `@ghost`
`@rustbot` modify labels: rollup

makai410 pushed a commit to makai410/rustc_public that referenced this pull request

Nov 16, 2025

Kobzol pushed a commit to Kobzol/portable-simd that referenced this pull request

Feb 3, 2026
…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