Skip to content

Commit 85a86c8

Browse files
committed
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.
1 parent 80543f7 commit 85a86c8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/librustdoc/core.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_data_structures::sync::Lrc;
33
use rustc_data_structures::unord::UnordSet;
44
use rustc_errors::emitter::{DynEmitter, HumanEmitter};
55
use rustc_errors::json::JsonEmitter;
6-
use rustc_errors::{codes::*, TerminalUrl};
6+
use rustc_errors::{codes::*, ErrorGuaranteed, TerminalUrl};
77
use rustc_feature::UnstableFeatures;
88
use rustc_hir::def::Res;
99
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId};
@@ -306,7 +306,7 @@ pub(crate) fn run_global_ctxt(
306306
show_coverage: bool,
307307
render_options: RenderOptions,
308308
output_format: OutputFormat,
309-
) -> (clean::Crate, RenderOptions, Cache) {
309+
) -> Result<(clean::Crate, RenderOptions, Cache), ErrorGuaranteed> {
310310
// Certain queries assume that some checks were run elsewhere
311311
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
312312
// so type-check everything other than function bodies in this crate before running lints.
@@ -331,7 +331,10 @@ pub(crate) fn run_global_ctxt(
331331
});
332332
});
333333

334-
tcx.dcx().abort_if_errors();
334+
if let Some(guar) = tcx.dcx().has_errors() {
335+
return Err(guar);
336+
}
337+
335338
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
336339
tcx.sess.time("check_mod_attrs", || {
337340
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_attrs(module))
@@ -452,13 +455,13 @@ pub(crate) fn run_global_ctxt(
452455

453456
tcx.sess.time("check_lint_expectations", || tcx.check_expectations(Some(sym::rustdoc)));
454457

455-
if tcx.dcx().has_errors().is_some() {
456-
rustc_errors::FatalError.raise();
458+
if let Some(guar) = tcx.dcx().has_errors() {
459+
return Err(guar);
457460
}
458461

459462
krate = tcx.sess.time("create_format_cache", || Cache::populate(&mut ctxt, krate));
460463

461-
(krate, ctxt.render_options, ctxt.cache)
464+
Ok((krate, ctxt.render_options, ctxt.cache))
462465
}
463466

464467
/// Due to <https://github.com/rust-lang/rust/pull/73566>,

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ fn main_args(
787787
gcx.enter(|tcx| {
788788
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
789789
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
790-
});
790+
})?;
791791
info!("finished with rustc");
792792

793793
if let Some(options) = scrape_examples_options {

0 commit comments

Comments
 (0)