Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary after_run function #81184

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should mention when will the handler be called to report errors. In this case it should be after post processing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not guarenteed by this trait, that's an implementation detail of html::render::Context. So I don't think it should be documented.

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(())
}
}