Skip to content

Commit

Permalink
Remove unnecessary after_run function
Browse files Browse the repository at this point in the history
It's called at the same time and in the same place as `after_krate`, so
they can be combined.
  • Loading branch information
jyn514 committed Jan 19, 2021
1 parent 1f0fc02 commit d926147
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
15 changes: 9 additions & 6 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ crate trait FormatRenderer<'tcx>: Clone {
fn mod_item_out(&mut self, item_name: &str) -> Result<(), Error>;

/// Post processing hook for cleanup and dumping output to files.
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error>;

/// Called after everything else to write out errors.
fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error>;
///
/// A handler is available if the renderer wants to report errors.
fn after_krate(
&mut self,
krate: &clean::Crate,
cache: &Cache,
diag: &rustc_errors::Handler,
) -> Result<(), Error>;
}

/// Main method for rendering a crate.
Expand Down Expand Up @@ -104,6 +108,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
}
}

format_renderer.after_krate(&krate, &cache)?;
format_renderer.after_run(diag)
format_renderer.after_krate(&krate, &cache, diag)
}
27 changes: 15 additions & 12 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,12 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
Ok((cx, krate))
}

fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error> {
Arc::get_mut(&mut self.shared).unwrap().fs.close();
let nb_errors = self.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"), ""))
} else {
Ok(())
}
}

fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
fn after_krate(
&mut self,
krate: &clean::Crate,
cache: &Cache,
diag: &rustc_errors::Handler,
) -> Result<(), Error> {
let final_file = self.dst.join(&*krate.name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
let crate_name = krate.name;
Expand Down Expand Up @@ -596,7 +591,15 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
&style_files,
);
self.shared.fs.write(&settings_file, v.as_bytes())?;
Ok(())

// Flush pending errors.
Arc::get_mut(&mut self.shared).unwrap().fs.close();
let nb_errors = self.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"), ""))
} else {
Ok(())
}
}

fn mod_item_in(
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
Ok(())
}

fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
fn after_krate(
&mut self,
krate: &clean::Crate,
cache: &Cache,
_diag: &rustc_errors::Handler,
) -> Result<(), Error> {
debug!("Done with crate");
let mut index = (*self.index).clone().into_inner();
index.extend(self.get_trait_items(cache));
Expand Down Expand Up @@ -245,8 +250,4 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
serde_json::ser::to_writer(&file, &output).unwrap();
Ok(())
}

fn after_run(&mut self, _diag: &rustc_errors::Handler) -> Result<(), Error> {
Ok(())
}
}

0 comments on commit d926147

Please sign in to comment.