Some cleanups around EarlyDiagCtxt
All callers of EarlyDiagCtxt::early_error now emit a fatal error.
This commit is contained in:
parent
6dd75f0d68
commit
d237378cd1
8 changed files with 26 additions and 40 deletions
|
@ -1819,7 +1819,7 @@ pub fn parse_error_format(
|
|||
ErrorOutputType::HumanReadable(HumanReadableErrorType::Unicode, color)
|
||||
}
|
||||
Some(arg) => {
|
||||
early_dcx.abort_if_error_and_set_error_format(ErrorOutputType::HumanReadable(
|
||||
early_dcx.set_error_format(ErrorOutputType::HumanReadable(
|
||||
HumanReadableErrorType::Default,
|
||||
color,
|
||||
));
|
||||
|
@ -2360,7 +2360,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
|||
|
||||
let error_format = parse_error_format(early_dcx, matches, color, json_color, json_rendered);
|
||||
|
||||
early_dcx.abort_if_error_and_set_error_format(error_format);
|
||||
early_dcx.set_error_format(error_format);
|
||||
|
||||
let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_else(|_| {
|
||||
early_dcx.early_fatal("`--diagnostic-width` must be an positive integer");
|
||||
|
@ -2770,6 +2770,7 @@ pub mod nightly_options {
|
|||
"the option `{}` is only accepted on the nightly compiler",
|
||||
opt.name
|
||||
);
|
||||
// The non-zero nightly_options_on_stable will force an early_fatal eventually.
|
||||
let _ = early_dcx.early_err(msg);
|
||||
}
|
||||
OptionStability::Stable => {}
|
||||
|
|
|
@ -1362,12 +1362,6 @@ pub struct EarlyDiagCtxt {
|
|||
dcx: DiagCtxt,
|
||||
}
|
||||
|
||||
impl Default for EarlyDiagCtxt {
|
||||
fn default() -> Self {
|
||||
Self::new(ErrorOutputType::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyDiagCtxt {
|
||||
pub fn new(output: ErrorOutputType) -> Self {
|
||||
let emitter = mk_emitter(output);
|
||||
|
@ -1375,10 +1369,9 @@ impl EarlyDiagCtxt {
|
|||
}
|
||||
|
||||
/// Swap out the underlying dcx once we acquire the user's preference on error emission
|
||||
/// format. Any errors prior to that will cause an abort and all stashed diagnostics of the
|
||||
/// previous dcx will be emitted.
|
||||
pub fn abort_if_error_and_set_error_format(&mut self, output: ErrorOutputType) {
|
||||
self.dcx.handle().abort_if_errors();
|
||||
/// format. If `early_err` was previously called this will panic.
|
||||
pub fn set_error_format(&mut self, output: ErrorOutputType) {
|
||||
assert!(self.dcx.handle().has_errors().is_none());
|
||||
|
||||
let emitter = mk_emitter(output);
|
||||
self.dcx = DiagCtxt::new(emitter);
|
||||
|
@ -1398,7 +1391,7 @@ impl EarlyDiagCtxt {
|
|||
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[must_use = "ErrorGuaranteed must be returned from `run_compiler` in order to exit with a non-zero status code"]
|
||||
#[must_use = "raise_fatal must be called on the returned ErrorGuaranteed in order to exit with a non-zero status code"]
|
||||
pub fn early_err(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed {
|
||||
self.dcx.handle().err(msg)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue