Use a dedicated type instead of a reference for the diagnostic context

This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
This commit is contained in:
Oli Scherer
2024-06-18 10:35:56 +00:00
parent c91edc3888
commit 7ba82d61eb
77 changed files with 363 additions and 328 deletions

View File

@@ -22,8 +22,8 @@ use rustc_errors::emitter::{stderr_destination, DynEmitter, HumanEmitter, HumanR
use rustc_errors::json::JsonEmitter;
use rustc_errors::registry::Registry;
use rustc_errors::{
codes::*, fallback_fluent_bundle, Diag, DiagCtxt, DiagMessage, Diagnostic, ErrorGuaranteed,
FatalAbort, FluentBundle, LazyFallbackBundle, TerminalUrl,
codes::*, fallback_fluent_bundle, Diag, DiagCtxt, DiagCtxtHandle, DiagMessage, Diagnostic,
ErrorGuaranteed, FatalAbort, FluentBundle, LazyFallbackBundle, TerminalUrl,
};
use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId;
@@ -328,7 +328,7 @@ impl Session {
}
#[inline]
pub fn dcx(&self) -> &DiagCtxt {
pub fn dcx(&self) -> DiagCtxtHandle<'_> {
self.psess.dcx()
}
@@ -1065,7 +1065,7 @@ pub fn build_session(
match profiler {
Ok(profiler) => Some(Arc::new(profiler)),
Err(e) => {
dcx.emit_warn(errors::FailedToCreateProfiler { err: e.to_string() });
dcx.handle().emit_warn(errors::FailedToCreateProfiler { err: e.to_string() });
None
}
}
@@ -1366,7 +1366,7 @@ impl EarlyDiagCtxt {
/// 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.abort_if_errors();
self.dcx.handle().abort_if_errors();
let emitter = mk_emitter(output);
self.dcx = DiagCtxt::new(emitter);
@@ -1375,44 +1375,44 @@ impl EarlyDiagCtxt {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn early_note(&self, msg: impl Into<DiagMessage>) {
self.dcx.note(msg)
self.dcx.handle().note(msg)
}
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn early_help(&self, msg: impl Into<DiagMessage>) {
self.dcx.struct_help(msg).emit()
self.dcx.handle().struct_help(msg).emit()
}
#[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"]
pub fn early_err(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed {
self.dcx.err(msg)
self.dcx.handle().err(msg)
}
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn early_fatal(&self, msg: impl Into<DiagMessage>) -> ! {
self.dcx.fatal(msg)
self.dcx.handle().fatal(msg)
}
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn early_struct_fatal(&self, msg: impl Into<DiagMessage>) -> Diag<'_, FatalAbort> {
self.dcx.struct_fatal(msg)
self.dcx.handle().struct_fatal(msg)
}
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn early_warn(&self, msg: impl Into<DiagMessage>) {
self.dcx.warn(msg)
self.dcx.handle().warn(msg)
}
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
pub fn early_struct_warn(&self, msg: impl Into<DiagMessage>) -> Diag<'_, ()> {
self.dcx.struct_warn(msg)
self.dcx.handle().struct_warn(msg)
}
}