From b7e95dee65c35db8f8e07046d445b12d92cbae12 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 27 Jan 2022 09:44:25 +0000 Subject: rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission". --- compiler/rustc_session/src/parse.rs | 6 ++--- compiler/rustc_session/src/session.rs | 50 ++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 18 deletions(-) (limited to 'compiler/rustc_session/src') diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 5c71bef31c2..e287764a52a 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -7,7 +7,7 @@ use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; -use rustc_errors::{error_code, Applicability, Diagnostic, DiagnosticBuilder}; +use rustc_errors::{error_code, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported}; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; use rustc_span::hygiene::ExpnId; @@ -82,7 +82,7 @@ pub fn feature_err<'a>( feature: Symbol, span: impl Into, explain: &str, -) -> DiagnosticBuilder<'a> { +) -> DiagnosticBuilder<'a, ErrorReported> { feature_err_issue(sess, feature, span, GateIssue::Language, explain) } @@ -96,7 +96,7 @@ pub fn feature_err_issue<'a>( span: impl Into, issue: GateIssue, explain: &str, -) -> DiagnosticBuilder<'a> { +) -> DiagnosticBuilder<'a, ErrorReported> { let mut err = sess.span_diagnostic.struct_span_err_with_code(span, explain, error_code!(E0658)); if let Some(n) = find_feature_issue(feature, issue) { diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 0515c440ab8..b72be735ce4 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -221,7 +221,7 @@ enum DiagnosticBuilderMethod { pub trait SessionDiagnostic<'a> { /// Write out as a diagnostic out of `sess`. #[must_use] - fn into_diagnostic(self, sess: &'a Session) -> DiagnosticBuilder<'a>; + fn into_diagnostic(self, sess: &'a Session) -> DiagnosticBuilder<'a, ErrorReported>; } /// Diagnostic message ID, used by `Session.one_time_diagnostics` to avoid @@ -303,7 +303,11 @@ impl Session { self.crate_types.set(crate_types).expect("`crate_types` was initialized twice") } - pub fn struct_span_warn>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_span_warn>( + &self, + sp: S, + msg: &str, + ) -> DiagnosticBuilder<'_, ()> { self.diagnostic().struct_span_warn(sp, msg) } pub fn struct_span_warn_with_code>( @@ -311,19 +315,27 @@ impl Session { sp: S, msg: &str, code: DiagnosticId, - ) -> DiagnosticBuilder<'_> { + ) -> DiagnosticBuilder<'_, ()> { self.diagnostic().struct_span_warn_with_code(sp, msg, code) } - pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_, ()> { self.diagnostic().struct_warn(msg) } - pub fn struct_span_allow>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_span_allow>( + &self, + sp: S, + msg: &str, + ) -> DiagnosticBuilder<'_, ()> { self.diagnostic().struct_span_allow(sp, msg) } - pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_allow(&self, msg: &str) -> DiagnosticBuilder<'_, ()> { self.diagnostic().struct_allow(msg) } - pub fn struct_span_err>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_span_err>( + &self, + sp: S, + msg: &str, + ) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_span_err(sp, msg) } pub fn struct_span_err_with_code>( @@ -331,17 +343,25 @@ impl Session { sp: S, msg: &str, code: DiagnosticId, - ) -> DiagnosticBuilder<'_> { + ) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_span_err_with_code(sp, msg, code) } // FIXME: This method should be removed (every error should have an associated error code). - pub fn struct_err(&self, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_err(&self, msg: &str) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_err(msg) } - pub fn struct_err_with_code(&self, msg: &str, code: DiagnosticId) -> DiagnosticBuilder<'_> { + pub fn struct_err_with_code( + &self, + msg: &str, + code: DiagnosticId, + ) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_err_with_code(msg, code) } - pub fn struct_span_fatal>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_span_fatal>( + &self, + sp: S, + msg: &str, + ) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_span_fatal(sp, msg) } pub fn struct_span_fatal_with_code>( @@ -349,10 +369,10 @@ impl Session { sp: S, msg: &str, code: DiagnosticId, - ) -> DiagnosticBuilder<'_> { + ) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_span_fatal_with_code(sp, msg, code) } - pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_fatal(msg) } @@ -386,7 +406,7 @@ impl Session { pub fn err(&self, msg: &str) { self.diagnostic().err(msg) } - pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) { + pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorReported { err.into_diagnostic(self).emit() } #[inline] @@ -457,7 +477,7 @@ impl Session { pub fn span_note_without_error>(&self, sp: S, msg: &str) { self.diagnostic().span_note_without_error(sp, msg) } - pub fn struct_note_without_error(&self, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_note_without_error(&self, msg: &str) -> DiagnosticBuilder<'_, ()> { self.diagnostic().struct_note_without_error(msg) } -- cgit 1.4.1-3-g733a5