1
Fork 0

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`
This commit is contained in:
Matthias Krüger 2021-12-23 00:28:55 +01:00 committed by GitHub
commit 051d91a5ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View file

@ -272,7 +272,10 @@ crate struct RenderOptions {
crate emit: Vec<EmitType>, crate emit: Vec<EmitType>,
/// If `true`, HTML source pages will generate links for items to their definition. /// If `true`, HTML source pages will generate links for items to their definition.
crate generate_link_to_definition: bool, crate generate_link_to_definition: bool,
/// Set of function-call locations to include as examples
crate call_locations: AllCallLocations, crate call_locations: AllCallLocations,
/// If `true`, Context::init will not emit shared files.
crate no_emit_shared: bool,
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -732,6 +735,7 @@ impl Options {
emit, emit,
generate_link_to_definition, generate_link_to_definition,
call_locations, call_locations,
no_emit_shared: false,
}, },
crate_name, crate_name,
output_format, output_format,

View file

@ -397,6 +397,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
show_type_layout, show_type_layout,
generate_link_to_definition, generate_link_to_definition,
call_locations, call_locations,
no_emit_shared,
.. ..
} = options; } = options;
@ -516,13 +517,16 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
sources::render(&mut cx, &krate)?; sources::render(&mut cx, &krate)?;
} }
// Build our search index if !no_emit_shared {
let index = build_index(&krate, &mut Rc::get_mut(&mut cx.shared).unwrap().cache, tcx); // Build our search index
let index = build_index(&krate, &mut Rc::get_mut(&mut cx.shared).unwrap().cache, tcx);
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
write_shared(&cx, &krate, index, &md_opts)?;
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
}
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
write_shared(&cx, &krate, index, &md_opts)?;
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
Ok((cx, krate)) Ok((cx, krate))
} }

View file

@ -223,13 +223,14 @@ where
crate fn run( crate fn run(
krate: clean::Crate, krate: clean::Crate,
renderopts: config::RenderOptions, mut renderopts: config::RenderOptions,
cache: formats::cache::Cache, cache: formats::cache::Cache,
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
options: ScrapeExamplesOptions, options: ScrapeExamplesOptions,
) -> interface::Result<()> { ) -> interface::Result<()> {
let inner = move || -> Result<(), String> { let inner = move || -> Result<(), String> {
// Generates source files for examples // Generates source files for examples
renderopts.no_emit_shared = true;
let (cx, _) = Context::init(krate, renderopts, cache, tcx).map_err(|e| e.to_string())?; let (cx, _) = Context::init(krate, renderopts, cache, tcx).map_err(|e| e.to_string())?;
// Collect CrateIds corresponding to provided target crates // Collect CrateIds corresponding to provided target crates