Skip to content

Commit 051d91a

Browse files
authored
Rollup merge of #92146 - willcrichton:example-analyzer, r=jyn514
Don't emit shared files when scraping examples from dependencies in Rustdoc This PR fixes #91605. The issue is that `Context::init` gets called when scraping dependencies. By default, just calling `init` calls into `write_shared` and `build_index` which register the scraped crate into a list that later gets used for the Rustdoc sidebar. The fix is to ensure that `write_shared` is not called when scraping. r? `@jyn514`
2 parents 12e4907 + b7de797 commit 051d91a

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/librustdoc/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ crate struct RenderOptions {
272272
crate emit: Vec<EmitType>,
273273
/// If `true`, HTML source pages will generate links for items to their definition.
274274
crate generate_link_to_definition: bool,
275+
/// Set of function-call locations to include as examples
275276
crate call_locations: AllCallLocations,
277+
/// If `true`, Context::init will not emit shared files.
278+
crate no_emit_shared: bool,
276279
}
277280

278281
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -732,6 +735,7 @@ impl Options {
732735
emit,
733736
generate_link_to_definition,
734737
call_locations,
738+
no_emit_shared: false,
735739
},
736740
crate_name,
737741
output_format,

src/librustdoc/html/render/context.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
397397
show_type_layout,
398398
generate_link_to_definition,
399399
call_locations,
400+
no_emit_shared,
400401
..
401402
} = options;
402403

@@ -516,13 +517,16 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
516517
sources::render(&mut cx, &krate)?;
517518
}
518519

519-
// Build our search index
520-
let index = build_index(&krate, &mut Rc::get_mut(&mut cx.shared).unwrap().cache, tcx);
520+
if !no_emit_shared {
521+
// Build our search index
522+
let index = build_index(&krate, &mut Rc::get_mut(&mut cx.shared).unwrap().cache, tcx);
523+
524+
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
525+
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
526+
write_shared(&cx, &krate, index, &md_opts)?;
527+
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
528+
}
521529

522-
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
523-
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
524-
write_shared(&cx, &krate, index, &md_opts)?;
525-
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
526530
Ok((cx, krate))
527531
}
528532

src/librustdoc/scrape_examples.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,14 @@ where
223223

224224
crate fn run(
225225
krate: clean::Crate,
226-
renderopts: config::RenderOptions,
226+
mut renderopts: config::RenderOptions,
227227
cache: formats::cache::Cache,
228228
tcx: TyCtxt<'_>,
229229
options: ScrapeExamplesOptions,
230230
) -> interface::Result<()> {
231231
let inner = move || -> Result<(), String> {
232232
// Generates source files for examples
233+
renderopts.no_emit_shared = true;
233234
let (cx, _) = Context::init(krate, renderopts, cache, tcx).map_err(|e| e.to_string())?;
234235

235236
// Collect CrateIds corresponding to provided target crates

0 commit comments

Comments
 (0)