diff options
Diffstat (limited to 'compiler/rustc_session/src/parse.rs')
-rw-r--r-- | compiler/rustc_session/src/parse.rs | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 4d20d6d41..2cb47e3a9 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -11,10 +11,10 @@ use crate::lint::{ use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc}; -use rustc_errors::{emitter::SilentEmitter, Handler}; +use rustc_errors::{emitter::SilentEmitter, DiagCtxt}; use rustc_errors::{ fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, - EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, Noted, StashKey, + ErrorGuaranteed, IntoDiagnostic, MultiSpan, Noted, StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; @@ -51,6 +51,9 @@ impl GatedSpans { /// Prepend the given set of `spans` onto the set in `self`. pub fn merge(&self, mut spans: FxHashMap<Symbol, Vec<Span>>) { let mut inner = self.spans.borrow_mut(); + // The entries will be moved to another map so the drain order does not + // matter. + #[allow(rustc::potential_query_instability)] for (gate, mut gate_spans) in inner.drain() { spans.entry(gate).or_default().append(&mut gate_spans); } @@ -100,8 +103,7 @@ pub fn feature_err_issue( // Cancel an earlier warning for this same error, if it exists. if let Some(span) = span.primary_span() { - if let Some(err) = sess.span_diagnostic.steal_diagnostic(span, StashKey::EarlySyntaxWarning) - { + if let Some(err) = sess.dcx.steal_diagnostic(span, StashKey::EarlySyntaxWarning) { err.cancel() } } @@ -135,7 +137,7 @@ pub fn feature_warn_issue( issue: GateIssue, explain: &'static str, ) { - let mut err = sess.span_diagnostic.struct_span_warn(span, explain); + let mut err = sess.dcx.struct_span_warn(span, explain); add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false); // Decorate this as a future-incompatibility lint as in rustc_middle::lint::struct_lint_level @@ -186,7 +188,7 @@ pub fn add_feature_diagnostics_for_issue( /// Info about a parsing session. pub struct ParseSess { - pub span_diagnostic: Handler, + pub dcx: DiagCtxt, pub unstable_features: UnstableFeatures, pub config: Cfg, pub check_config: CheckCfg, @@ -214,7 +216,7 @@ pub struct ParseSess { pub assume_incomplete_release: bool, /// Spans passed to `proc_macro::quote_span`. Each span has a numerical /// identifier represented by its position in the vector. - pub proc_macro_quoted_spans: AppendOnlyVec<Span>, + proc_macro_quoted_spans: AppendOnlyVec<Span>, /// Used to generate new `AttrId`s. Every `AttrId` is unique. pub attr_id_generator: AttrIdGenerator, } @@ -224,13 +226,13 @@ impl ParseSess { pub fn new(locale_resources: Vec<&'static str>, file_path_mapping: FilePathMapping) -> Self { let fallback_bundle = fallback_fluent_bundle(locale_resources, false); let sm = Lrc::new(SourceMap::new(file_path_mapping)); - let handler = Handler::with_tty_emitter(Some(sm.clone()), fallback_bundle); - ParseSess::with_span_handler(handler, sm) + let dcx = DiagCtxt::with_tty_emitter(Some(sm.clone()), fallback_bundle); + ParseSess::with_dcx(dcx, sm) } - pub fn with_span_handler(handler: Handler, source_map: Lrc<SourceMap>) -> Self { + pub fn with_dcx(dcx: DiagCtxt, source_map: Lrc<SourceMap>) -> Self { Self { - span_diagnostic: handler, + dcx, unstable_features: UnstableFeatures::from_environment(None), config: Cfg::default(), check_config: CheckCfg::default(), @@ -253,10 +255,10 @@ impl ParseSess { pub fn with_silent_emitter(fatal_note: Option<String>) -> Self { let fallback_bundle = fallback_fluent_bundle(Vec::new(), false); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let fatal_handler = Handler::with_tty_emitter(None, fallback_bundle).disable_warnings(); - let handler = Handler::with_emitter(Box::new(SilentEmitter { fatal_handler, fatal_note })) + let fatal_dcx = DiagCtxt::with_tty_emitter(None, fallback_bundle).disable_warnings(); + let dcx = DiagCtxt::with_emitter(Box::new(SilentEmitter { fatal_dcx, fatal_note })) .disable_warnings(); - ParseSess::with_span_handler(handler, sm) + ParseSess::with_dcx(dcx, sm) } #[inline] @@ -320,7 +322,7 @@ impl ParseSess { &'a self, err: impl IntoDiagnostic<'a>, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { - err.into_diagnostic(&self.span_diagnostic) + err.into_diagnostic(&self.dcx) } #[track_caller] @@ -333,7 +335,7 @@ impl ParseSess { &'a self, warning: impl IntoDiagnostic<'a, ()>, ) -> DiagnosticBuilder<'a, ()> { - warning.into_diagnostic(&self.span_diagnostic) + warning.into_diagnostic(&self.dcx) } #[track_caller] @@ -346,7 +348,7 @@ impl ParseSess { &'a self, note: impl IntoDiagnostic<'a, Noted>, ) -> DiagnosticBuilder<'a, Noted> { - note.into_diagnostic(&self.span_diagnostic) + note.into_diagnostic(&self.dcx) } #[track_caller] @@ -359,7 +361,7 @@ impl ParseSess { &'a self, fatal: impl IntoDiagnostic<'a, !>, ) -> DiagnosticBuilder<'a, !> { - fatal.into_diagnostic(&self.span_diagnostic) + fatal.into_diagnostic(&self.dcx) } #[track_caller] @@ -373,27 +375,18 @@ impl ParseSess { &self, msg: impl Into<DiagnosticMessage>, ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { - self.span_diagnostic.struct_err(msg) + self.dcx.struct_err(msg) } #[rustc_lint_diagnostics] #[track_caller] pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> { - self.span_diagnostic.struct_warn(msg) + self.dcx.struct_warn(msg) } #[rustc_lint_diagnostics] #[track_caller] pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> { - self.span_diagnostic.struct_fatal(msg) - } - - #[rustc_lint_diagnostics] - #[track_caller] - pub fn struct_diagnostic<G: EmissionGuarantee>( - &self, - msg: impl Into<DiagnosticMessage>, - ) -> DiagnosticBuilder<'_, G> { - self.span_diagnostic.struct_diagnostic(msg) + self.dcx.struct_fatal(msg) } } |