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:
parent
c91edc3888
commit
7ba82d61eb
77 changed files with 363 additions and 328 deletions
|
@ -3,8 +3,8 @@ use std::num::NonZero;
|
|||
use rustc_ast::token;
|
||||
use rustc_ast::util::literal::LitError;
|
||||
use rustc_errors::{
|
||||
codes::*, Diag, DiagCtxt, DiagMessage, Diagnostic, EmissionGuarantee, ErrorGuaranteed, Level,
|
||||
MultiSpan,
|
||||
codes::*, Diag, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, ErrorGuaranteed,
|
||||
Level, MultiSpan,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
@ -19,7 +19,7 @@ pub(crate) struct FeatureGateError {
|
|||
|
||||
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for FeatureGateError {
|
||||
#[track_caller]
|
||||
fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
||||
Diag::new(dcx, level, self.explain).with_span(self.span).with_code(E0658)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
|||
use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc};
|
||||
use rustc_errors::emitter::{stderr_destination, HumanEmitter, SilentEmitter};
|
||||
use rustc_errors::{
|
||||
fallback_fluent_bundle, ColorConfig, Diag, DiagCtxt, DiagMessage, EmissionGuarantee, MultiSpan,
|
||||
StashKey,
|
||||
fallback_fluent_bundle, ColorConfig, Diag, DiagCtxt, DiagCtxtHandle, DiagMessage,
|
||||
EmissionGuarantee, MultiSpan, StashKey,
|
||||
};
|
||||
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
|
||||
use rustc_span::edition::Edition;
|
||||
|
@ -327,7 +327,7 @@ impl ParseSess {
|
|||
self.proc_macro_quoted_spans.iter_enumerated()
|
||||
}
|
||||
|
||||
pub fn dcx(&self) -> &DiagCtxt {
|
||||
&self.dcx
|
||||
pub fn dcx(&self) -> DiagCtxtHandle<'_> {
|
||||
self.dcx.handle()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue