Skip to content

Commit d926147

Browse files
committed
Remove unnecessary after_run function
It's called at the same time and in the same place as `after_krate`, so they can be combined.
1 parent 1f0fc02 commit d926147

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

src/librustdoc/formats/renderer.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ crate trait FormatRenderer<'tcx>: Clone {
3838
fn mod_item_out(&mut self, item_name: &str) -> Result<(), Error>;
3939

4040
/// Post processing hook for cleanup and dumping output to files.
41-
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error>;
42-
43-
/// Called after everything else to write out errors.
44-
fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error>;
41+
///
42+
/// A handler is available if the renderer wants to report errors.
43+
fn after_krate(
44+
&mut self,
45+
krate: &clean::Crate,
46+
cache: &Cache,
47+
diag: &rustc_errors::Handler,
48+
) -> Result<(), Error>;
4549
}
4650

4751
/// Main method for rendering a crate.
@@ -104,6 +108,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
104108
}
105109
}
106110

107-
format_renderer.after_krate(&krate, &cache)?;
108-
format_renderer.after_run(diag)
111+
format_renderer.after_krate(&krate, &cache, diag)
109112
}

src/librustdoc/html/render/mod.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,12 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
523523
Ok((cx, krate))
524524
}
525525

526-
fn after_run(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error> {
527-
Arc::get_mut(&mut self.shared).unwrap().fs.close();
528-
let nb_errors = self.errors.iter().map(|err| diag.struct_err(&err).emit()).count();
529-
if nb_errors > 0 {
530-
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
531-
} else {
532-
Ok(())
533-
}
534-
}
535-
536-
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
526+
fn after_krate(
527+
&mut self,
528+
krate: &clean::Crate,
529+
cache: &Cache,
530+
diag: &rustc_errors::Handler,
531+
) -> Result<(), Error> {
537532
let final_file = self.dst.join(&*krate.name.as_str()).join("all.html");
538533
let settings_file = self.dst.join("settings.html");
539534
let crate_name = krate.name;
@@ -596,7 +591,15 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
596591
&style_files,
597592
);
598593
self.shared.fs.write(&settings_file, v.as_bytes())?;
599-
Ok(())
594+
595+
// Flush pending errors.
596+
Arc::get_mut(&mut self.shared).unwrap().fs.close();
597+
let nb_errors = self.errors.iter().map(|err| diag.struct_err(&err).emit()).count();
598+
if nb_errors > 0 {
599+
Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), ""))
600+
} else {
601+
Ok(())
602+
}
600603
}
601604

602605
fn mod_item_in(

src/librustdoc/json/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,12 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
199199
Ok(())
200200
}
201201

202-
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
202+
fn after_krate(
203+
&mut self,
204+
krate: &clean::Crate,
205+
cache: &Cache,
206+
_diag: &rustc_errors::Handler,
207+
) -> Result<(), Error> {
203208
debug!("Done with crate");
204209
let mut index = (*self.index).clone().into_inner();
205210
index.extend(self.get_trait_items(cache));
@@ -245,8 +250,4 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
245250
serde_json::ser::to_writer(&file, &output).unwrap();
246251
Ok(())
247252
}
248-
249-
fn after_run(&mut self, _diag: &rustc_errors::Handler) -> Result<(), Error> {
250-
Ok(())
251-
}
252253
}

0 commit comments

Comments
 (0)