Skip to content

Commit d369a1f

Browse files
Rollup merge of #145008 - GuillaumeGomez:fix-rustdoc-scrape-examples-crash, r=fmease
Fix rustdoc scrape examples crash Fixes #144752. The regression was introduced in #144600. Although I don't understand why it is an issue currently, this allows to bypass the failure for now until we can figure out what's wrong as it's currently blocking new `bevy`'s release. cc `@alice-i-cecile` r? `@fmease`
2 parents c17f50b + a2b1714 commit d369a1f

File tree

7 files changed

+41
-4
lines changed

7 files changed

+41
-4
lines changed

src/librustdoc/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,7 @@ impl Options {
804804

805805
let scrape_examples_options = ScrapeExamplesOptions::new(matches, dcx);
806806
let with_examples = matches.opt_strs("with-examples");
807-
let call_locations =
808-
crate::scrape_examples::load_call_locations(with_examples, dcx, &mut loaded_paths);
807+
let call_locations = crate::scrape_examples::load_call_locations(with_examples, dcx);
809808
let doctest_build_args = matches.opt_strs("doctest-build-arg");
810809

811810
let unstable_features =

src/librustdoc/scrape_examples.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,14 @@ pub(crate) fn run(
333333
pub(crate) fn load_call_locations(
334334
with_examples: Vec<String>,
335335
dcx: DiagCtxtHandle<'_>,
336-
loaded_paths: &mut Vec<PathBuf>,
337336
) -> AllCallLocations {
338337
let mut all_calls: AllCallLocations = FxIndexMap::default();
339338
for path in with_examples {
340-
loaded_paths.push(path.clone().into());
339+
// FIXME: Figure out why this line is causing this feature to crash in specific contexts.
340+
// Full issue backlog is available here: <https://github.com/rust-lang/rust/pull/144600>.
341+
//
342+
// Can be checked with `tests/run-make/rustdoc-scrape-examples-paths`.
343+
// loaded_paths.push(path.clone().into());
341344
let bytes = match fs::read(&path) {
342345
Ok(bytes) => bytes,
343346
Err(e) => dcx.fatal(format!("failed to load examples: {e}")),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "foo"
3+
version = "0.0.1"
4+
edition = "2024"
5+
6+
[[example]]
7+
name = "complex"
8+
doc-scrape-examples = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let mut x = foo::X::new();
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// This file MUST exist to trigger the original bug.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub struct X;
2+
3+
impl X {
4+
pub fn new() -> Self {
5+
X
6+
}
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Test to ensure that the rustdoc `scrape-examples` feature is not panicking.
2+
//! Regression test for <https://github.com/rust-lang/rust/issues/144752>.
3+
4+
use run_make_support::{cargo, path, rfs};
5+
6+
fn main() {
7+
// We copy the crate to be documented "outside" to prevent documenting
8+
// the whole compiler.
9+
let tmp = std::env::temp_dir();
10+
let test_crate = tmp.join("foo");
11+
rfs::copy_dir_all(path("foo"), &test_crate);
12+
13+
// The `scrape-examples` feature is also implemented in `cargo` so instead of reproducing
14+
// what `cargo` does, better to just let `cargo` do it.
15+
cargo().current_dir(&test_crate).args(["doc", "-p", "foo", "-Zrustdoc-scrape-examples"]).run();
16+
}

0 commit comments

Comments
 (0)