Refactor run_global_ctxt.

It currently is infallible and uses `abort_if_errors` and
`FatalError.raise()` to signal errors. It's easy to instead return a
`Result<_, ErrorGuaranteed>`, which is the more usual way of doing
things.
This commit is contained in:
Nicholas Nethercote 2024-02-19 10:27:23 +11:00
parent c2512a130f
commit 44006444c8
2 changed files with 10 additions and 7 deletions

View file

@ -3,7 +3,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_data_structures::unord::UnordSet;
use rustc_errors::emitter::{DynEmitter, HumanEmitter};
use rustc_errors::json::JsonEmitter;
use rustc_errors::{codes::*, TerminalUrl};
use rustc_errors::{codes::*, ErrorGuaranteed, TerminalUrl};
use rustc_feature::UnstableFeatures;
use rustc_hir::def::Res;
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId};
@ -306,7 +306,7 @@ pub(crate) fn run_global_ctxt(
show_coverage: bool,
render_options: RenderOptions,
output_format: OutputFormat,
) -> (clean::Crate, RenderOptions, Cache) {
) -> Result<(clean::Crate, RenderOptions, Cache), ErrorGuaranteed> {
// Certain queries assume that some checks were run elsewhere
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
// so type-check everything other than function bodies in this crate before running lints.
@ -331,7 +331,10 @@ pub(crate) fn run_global_ctxt(
});
});
tcx.dcx().abort_if_errors();
if let Some(guar) = tcx.dcx().has_errors() {
return Err(guar);
}
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
tcx.sess.time("check_mod_attrs", || {
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_attrs(module))
@ -452,13 +455,13 @@ pub(crate) fn run_global_ctxt(
tcx.sess.time("check_lint_expectations", || tcx.check_expectations(Some(sym::rustdoc)));
if tcx.dcx().has_errors().is_some() {
rustc_errors::FatalError.raise();
if let Some(guar) = tcx.dcx().has_errors() {
return Err(guar);
}
krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));
(krate, ctxt.render_options, ctxt.cache)
Ok((krate, ctxt.render_options, ctxt.cache))
}
/// Due to <https://github.com/rust-lang/rust/pull/73566>,

View file

@ -787,7 +787,7 @@ fn main_args(
gcx.enter(|tcx| {
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
});
})?;
info!("finished with rustc");
if let Some(options) = scrape_examples_options {