diff options
| author | bors <bors@rust-lang.org> | 2024-06-18 16:49:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-18 16:49:19 +0000 |
| commit | dd104ef16315e2387fe94e8c43eb5a66e3dbd660 (patch) | |
| tree | bc7569f842f9454815433b814d6cdf846f91948b /compiler/rustc_session/src | |
| parent | 8814b926f49bc5780753ed9533853679a1181357 (diff) | |
| parent | 3f34196839730cfb5b241667cfcc9b94599ea0c1 (diff) | |
| download | rust-dd104ef16315e2387fe94e8c43eb5a66e3dbd660.tar.gz rust-dd104ef16315e2387fe94e8c43eb5a66e3dbd660.zip | |
Auto merge of #126623 - oli-obk:do_not_count_errors, r=davidtwco
Replace all `&DiagCtxt` with a `DiagCtxtHandle<'_>` wrapper type r? `@davidtwco` This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle Basically I will add a field to the `DiagCtxtHandle` that refers back to the `InferCtxt`'s (and others) `Option<ErrorHandled>`, allowing us to immediately taint these contexts when emitting an error and not needing manual tainting anymore (which is easy to forget and we don't do in general anyway)
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/errors.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 28 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 26 |
3 files changed, 33 insertions, 29 deletions
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index dce56382a53..4cbc1b57022 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -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) } } @@ -401,7 +401,7 @@ pub fn report_lit_error( valid.then(|| format!("0{}{}", base_char.to_ascii_lowercase(), &suffix[1..])) } - let dcx = &psess.dcx; + let dcx = psess.dcx(); match err { LitError::InvalidSuffix(suffix) => { dcx.emit_err(InvalidLiteralSuffix { span, kind: lit.kind.descr(), suffix }) diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index df07f81bc45..200505aaea2 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -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; @@ -106,12 +106,12 @@ 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.psess.dcx.steal_non_err(span, StashKey::EarlySyntaxWarning) { + if let Some(err) = sess.dcx().steal_non_err(span, StashKey::EarlySyntaxWarning) { err.cancel() } } - let mut err = sess.psess.dcx.create_err(FeatureGateError { span, explain: explain.into() }); + let mut err = sess.dcx().create_err(FeatureGateError { span, explain: explain.into() }); add_feature_diagnostics_for_issue(&mut err, sess, feature, issue, false, None); err } @@ -140,7 +140,7 @@ pub fn feature_warn_issue( issue: GateIssue, explain: &'static str, ) { - let mut err = sess.psess.dcx.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, None); // Decorate this as a future-incompatibility lint as in rustc_middle::lint::lint_level @@ -178,30 +178,30 @@ pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>( inject_span: Option<Span>, ) { if let Some(n) = find_feature_issue(feature, issue) { - err.subdiagnostic(sess.dcx(), FeatureDiagnosticForIssue { n }); + err.subdiagnostic(FeatureDiagnosticForIssue { n }); } // #23973: do not suggest `#![feature(...)]` if we are in beta/stable if sess.psess.unstable_features.is_nightly_build() { if feature_from_cli { - err.subdiagnostic(sess.dcx(), CliFeatureDiagnosticHelp { feature }); + err.subdiagnostic(CliFeatureDiagnosticHelp { feature }); } else if let Some(span) = inject_span { - err.subdiagnostic(sess.dcx(), FeatureDiagnosticSuggestion { feature, span }); + err.subdiagnostic(FeatureDiagnosticSuggestion { feature, span }); } else { - err.subdiagnostic(sess.dcx(), FeatureDiagnosticHelp { feature }); + err.subdiagnostic(FeatureDiagnosticHelp { feature }); } if sess.opts.unstable_opts.ui_testing { - err.subdiagnostic(sess.dcx(), SuggestUpgradeCompiler::ui_testing()); + err.subdiagnostic(SuggestUpgradeCompiler::ui_testing()); } else if let Some(suggestion) = SuggestUpgradeCompiler::new() { - err.subdiagnostic(sess.dcx(), suggestion); + err.subdiagnostic(suggestion); } } } /// Info about a parsing session. pub struct ParseSess { - pub dcx: DiagCtxt, + dcx: DiagCtxt, pub unstable_features: UnstableFeatures, pub config: Cfg, pub check_config: CheckCfg, @@ -326,4 +326,8 @@ impl ParseSess { // AppendOnlyVec, so we resort to this scheme. self.proc_macro_quoted_spans.iter_enumerated() } + + pub fn dcx(&self) -> DiagCtxtHandle<'_> { + self.dcx.handle() + } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 20e50ef1b4a..89d029fa6e0 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -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,8 +328,8 @@ impl Session { } #[inline] - pub fn dcx(&self) -> &DiagCtxt { - &self.psess.dcx + pub fn dcx(&self) -> DiagCtxtHandle<'_> { + self.psess.dcx() } #[inline] @@ -1070,7 +1070,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 } } @@ -1371,7 +1371,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); @@ -1380,44 +1380,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) } } |
