Skip to content

Commit cc67175

Browse files
committed
Simplify JsonRenderer.
- It doesn't need to be cloneable. - Some of the `Rc`s and `RefCell`s aren't doing anything. - `after_krate` can consume `self`.
1 parent fb644e6 commit cc67175

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/librustdoc/formats/renderer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(crate) trait FormatRenderer<'tcx>: Sized {
6767
}
6868

6969
/// Post processing hook for cleanup and dumping output to files.
70-
fn after_krate(&mut self) -> Result<(), Error>;
70+
fn after_krate(self) -> Result<(), Error>;
7171

7272
fn cache(&self) -> &Cache;
7373
}

src/librustdoc/html/render/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
609609
self.info = info;
610610
}
611611

612-
fn after_krate(&mut self) -> Result<(), Error> {
612+
fn after_krate(mut self) -> Result<(), Error> {
613613
let crate_name = self.tcx().crate_name(LOCAL_CRATE);
614614
let final_file = self.dst.join(crate_name.as_str()).join("all.html");
615615
let settings_file = self.dst.join("settings.html");

src/librustdoc/json/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,18 @@ use crate::formats::cache::Cache;
3636
use crate::json::conversions::IntoJson;
3737
use crate::{clean, try_err};
3838

39-
#[derive(Clone)]
4039
pub(crate) struct JsonRenderer<'tcx> {
4140
tcx: TyCtxt<'tcx>,
4241
/// A mapping of IDs that contains all local items for this crate which gets output as a top
4342
/// level field of the JSON blob.
44-
index: Rc<RefCell<FxHashMap<types::Id, types::Item>>>,
43+
index: FxHashMap<types::Id, types::Item>,
4544
/// The directory where the JSON blob should be written to.
4645
///
4746
/// If this is `None`, the blob will be printed to `stdout` instead.
4847
out_dir: Option<PathBuf>,
4948
cache: Rc<Cache>,
5049
imported_items: DefIdSet,
51-
id_interner: Rc<RefCell<ids::IdInterner>>,
50+
id_interner: RefCell<ids::IdInterner>,
5251
}
5352

5453
impl<'tcx> JsonRenderer<'tcx> {
@@ -197,7 +196,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
197196
Ok((
198197
JsonRenderer {
199198
tcx,
200-
index: Rc::new(RefCell::new(FxHashMap::default())),
199+
index: FxHashMap::default(),
201200
out_dir: if options.output_to_stdout { None } else { Some(options.output) },
202201
cache: Rc::new(cache),
203202
imported_items,
@@ -272,7 +271,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
272271
| types::ItemEnum::Macro(_)
273272
| types::ItemEnum::ProcMacro(_) => false,
274273
};
275-
let removed = self.index.borrow_mut().insert(new_item.id, new_item.clone());
274+
let removed = self.index.insert(new_item.id, new_item.clone());
276275

277276
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
278277
// to make sure the items are unique. The main place this happens is when an item, is
@@ -295,11 +294,11 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
295294
unreachable!("RUN_ON_MODULE = false, should never call mod_item_in")
296295
}
297296

298-
fn after_krate(&mut self) -> Result<(), Error> {
297+
fn after_krate(self) -> Result<(), Error> {
299298
debug!("Done with crate");
300299

301300
let e = ExternalCrate { crate_num: LOCAL_CRATE };
302-
let index = (*self.index).clone().into_inner();
301+
let index = self.index.clone();
303302

304303
// Note that tcx.rust_target_features is inappropriate here because rustdoc tries to run for
305304
// multiple targets: https://github.com/rust-lang/rust/pull/137632
@@ -324,7 +323,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
324323
types::ItemSummary {
325324
crate_id: k.krate.as_u32(),
326325
path: path.iter().map(|s| s.to_string()).collect(),
327-
kind: kind.into_json(self),
326+
kind: kind.into_json(&self),
328327
},
329328
)
330329
})

0 commit comments

Comments
 (0)