diff options
Diffstat (limited to 'compiler/rustc_session/src/parse.rs')
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 9170b265748..398138d7e1f 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -7,7 +7,7 @@ use crate::errors::{ SuggestUpgradeCompiler, }; use crate::lint::{ - builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId, + builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiag, Lint, LintId, }; use crate::Session; use rustc_ast::node_id::NodeId; @@ -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, DiagnosticMessage, EmissionGuarantee, - MultiSpan, StashKey, + fallback_fluent_bundle, ColorConfig, Diag, DiagCtxt, DiagMessage, EmissionGuarantee, MultiSpan, + StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; @@ -85,7 +85,7 @@ pub fn feature_err( sess: &Session, feature: Symbol, span: impl Into<MultiSpan>, - explain: impl Into<DiagnosticMessage>, + explain: impl Into<DiagMessage>, ) -> Diag<'_> { feature_err_issue(sess, feature, span, GateIssue::Language, explain) } @@ -100,19 +100,18 @@ pub fn feature_err_issue( feature: Symbol, span: impl Into<MultiSpan>, issue: GateIssue, - explain: impl Into<DiagnosticMessage>, + explain: impl Into<DiagMessage>, ) -> Diag<'_> { let span = span.into(); // Cancel an earlier warning for this same error, if it exists. if let Some(span) = span.primary_span() { - if let Some(err) = sess.parse_sess.dcx.steal_non_err(span, StashKey::EarlySyntaxWarning) { + if let Some(err) = sess.psess.dcx.steal_non_err(span, StashKey::EarlySyntaxWarning) { err.cancel() } } - let mut err = - sess.parse_sess.dcx.create_err(FeatureGateError { span, explain: explain.into() }); + let mut err = sess.psess.dcx.create_err(FeatureGateError { span, explain: explain.into() }); add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false); err } @@ -141,7 +140,7 @@ pub fn feature_warn_issue( issue: GateIssue, explain: &'static str, ) { - let mut err = sess.parse_sess.dcx.struct_span_warn(span, explain); + let mut err = sess.psess.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::lint_level @@ -169,6 +168,7 @@ pub fn add_feature_diagnostics<G: EmissionGuarantee>( /// This variant allows you to control whether it is a library or language feature. /// Almost always, you want to use this for a language feature. If so, prefer /// `add_feature_diagnostics`. +#[allow(rustc::diagnostic_outside_of_impl)] // FIXME pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>( err: &mut Diag<'_, G>, sess: &Session, @@ -181,7 +181,7 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>( } // #23973: do not suggest `#![feature(...)]` if we are in beta/stable - if sess.parse_sess.unstable_features.is_nightly_build() { + if sess.psess.unstable_features.is_nightly_build() { if feature_from_cli { err.subdiagnostic(sess.dcx(), CliFeatureDiagnosticHelp { feature }); } else { @@ -233,9 +233,9 @@ pub struct ParseSess { impl ParseSess { /// Used for testing. - pub fn new(locale_resources: Vec<&'static str>, file_path_mapping: FilePathMapping) -> Self { + pub fn new(locale_resources: Vec<&'static str>) -> Self { let fallback_bundle = fallback_fluent_bundle(locale_resources, false); - let sm = Lrc::new(SourceMap::new(file_path_mapping)); + let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let emitter = Box::new( HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle) .sm(Some(sm.clone())), @@ -266,14 +266,20 @@ impl ParseSess { } } - pub fn with_silent_emitter(fatal_note: String) -> Self { - let fallback_bundle = fallback_fluent_bundle(Vec::new(), false); + pub fn with_silent_emitter(locale_resources: Vec<&'static str>, fatal_note: String) -> Self { + let fallback_bundle = fallback_fluent_bundle(locale_resources, false); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let emitter = - Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle)); + let emitter = Box::new(HumanEmitter::new( + stderr_destination(ColorConfig::Auto), + fallback_bundle.clone(), + )); let fatal_dcx = DiagCtxt::new(emitter); - let dcx = - DiagCtxt::new(Box::new(SilentEmitter { fatal_dcx, fatal_note })).disable_warnings(); + let dcx = DiagCtxt::new(Box::new(SilentEmitter { + fallback_bundle, + fatal_dcx, + fatal_note: Some(fatal_note), + })) + .disable_warnings(); ParseSess::with_dcx(dcx, sm) } @@ -291,7 +297,7 @@ impl ParseSess { lint: &'static Lint, span: impl Into<MultiSpan>, node_id: NodeId, - msg: impl Into<DiagnosticMessage>, + msg: impl Into<DiagMessage>, ) { self.buffered_lints.with_lock(|buffered_lints| { buffered_lints.push(BufferedEarlyLint { @@ -299,7 +305,7 @@ impl ParseSess { node_id, msg: msg.into(), lint_id: LintId::of(lint), - diagnostic: BuiltinLintDiagnostics::Normal, + diagnostic: BuiltinLintDiag::Normal, }); }); } @@ -309,8 +315,8 @@ impl ParseSess { lint: &'static Lint, span: impl Into<MultiSpan>, node_id: NodeId, - msg: impl Into<DiagnosticMessage>, - diagnostic: BuiltinLintDiagnostics, + msg: impl Into<DiagMessage>, + diagnostic: BuiltinLintDiag, ) { self.buffered_lints.with_lock(|buffered_lints| { buffered_lints.push(BufferedEarlyLint { |
