rustdoc: Replace Arc around SharedContext with Rc

It doesn't look like it's shared across threads, so it doesn't need to
be thread-safe. Of course, since we're using Rust, we'll get an error if
we try to share it across threads, so this should be safe :)
This commit is contained in:
Camelid 2021-02-21 14:25:21 -08:00
parent 9763eb87a3
commit c4bb66c284

View File

@ -4,7 +4,6 @@ use std::io;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::mpsc::channel;
use std::sync::Arc;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LOCAL_CRATE;
@ -53,7 +52,7 @@ crate struct Context<'tcx> {
/// real location of an item. This is used to allow external links to
/// publicly reused items to redirect to the right location.
crate render_redirect_pages: bool,
crate shared: Arc<SharedContext<'tcx>>,
crate shared: Rc<SharedContext<'tcx>>,
/// The [`Cache`] used during rendering.
///
/// Ideally the cache would be in [`SharedContext`], but it's mutated
@ -410,16 +409,16 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
current: Vec::new(),
dst,
render_redirect_pages: false,
shared: Arc::new(scx),
shared: Rc::new(scx),
cache: Rc::new(cache),
};
CURRENT_DEPTH.with(|s| s.set(0));
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
Arc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true);
write_shared(&cx, &krate, index, &md_opts)?;
Arc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false);
Ok((cx, krate))
}
@ -501,7 +500,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
}
// Flush pending errors.
Arc::get_mut(&mut self.shared).unwrap().fs.close();
Rc::get_mut(&mut self.shared).unwrap().fs.close();
let nb_errors = self.shared.errors.iter().map(|err| diag.struct_err(&err).emit()).count();
if nb_errors > 0 {
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))