diff options
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 90 |
2 files changed, 51 insertions, 47 deletions
diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 7113f9b0a2f..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, 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<MultiSpan>, 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<MultiSpan>, 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) { @@ -243,7 +243,7 @@ impl ParseSess { /// Extend an error with a suggestion to wrap an expression with parentheses to allow the /// parser to continue parsing the following operation as part of the same expression. - pub fn expr_parentheses_needed(&self, err: &mut DiagnosticBuilder<'_>, span: Span) { + pub fn expr_parentheses_needed(&self, err: &mut Diagnostic, span: Span) { err.multipart_suggestion( "parentheses are required to parse this as an expression", vec![(span.shrink_to_lo(), "(".to_string()), (span.shrink_to_hi(), ")".to_string())], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 9bcdd7f3da6..b72be735ce4 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -19,7 +19,7 @@ use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter; use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType}; use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; -use rustc_errors::{DiagnosticBuilder, DiagnosticId, ErrorReported}; +use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported}; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; use rustc_span::edition::Edition; @@ -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,37 +303,39 @@ impl Session { self.crate_types.set(crate_types).expect("`crate_types` was initialized twice") } - pub fn struct_span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { - self.diagnostic().struct_span_warn(sp, msg) - } - pub fn struct_span_force_warn<S: Into<MultiSpan>>( + pub fn struct_span_warn<S: Into<MultiSpan>>( &self, sp: S, msg: &str, - ) -> DiagnosticBuilder<'_> { - self.diagnostic().struct_span_force_warn(sp, msg) + ) -> DiagnosticBuilder<'_, ()> { + self.diagnostic().struct_span_warn(sp, msg) } pub fn struct_span_warn_with_code<S: Into<MultiSpan>>( &self, 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_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> { - self.diagnostic().struct_force_warn(msg) - } - pub fn struct_span_allow<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_span_allow<S: Into<MultiSpan>>( + &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<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_span_err<S: Into<MultiSpan>>( + &self, + sp: S, + msg: &str, + ) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_span_err(sp, msg) } pub fn struct_span_err_with_code<S: Into<MultiSpan>>( @@ -341,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<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> { + pub fn struct_span_fatal<S: Into<MultiSpan>>( + &self, + sp: S, + msg: &str, + ) -> DiagnosticBuilder<'_, ErrorReported> { self.diagnostic().struct_span_fatal(sp, msg) } pub fn struct_span_fatal_with_code<S: Into<MultiSpan>>( @@ -359,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) } @@ -396,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] @@ -467,7 +477,7 @@ impl Session { pub fn span_note_without_error<S: Into<MultiSpan>>(&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) } @@ -478,9 +488,9 @@ impl Session { /// Analogous to calling methods on the given `DiagnosticBuilder`, but /// deduplicates on lint ID, span (if any), and message for this `Session` - fn diag_once<'a, 'b>( - &'a self, - diag_builder: &'b mut DiagnosticBuilder<'a>, + fn diag_once( + &self, + diag: &mut Diagnostic, method: DiagnosticBuilderMethod, msg_id: DiagnosticMessageId, message: &str, @@ -491,39 +501,33 @@ impl Session { if fresh { match method { DiagnosticBuilderMethod::Note => { - diag_builder.note(message); + diag.note(message); } DiagnosticBuilderMethod::SpanNote => { let span = span_maybe.expect("`span_note` needs a span"); - diag_builder.span_note(span, message); + diag.span_note(span, message); } } } } - pub fn diag_span_note_once<'a, 'b>( - &'a self, - diag_builder: &'b mut DiagnosticBuilder<'a>, + pub fn diag_span_note_once( + &self, + diag: &mut Diagnostic, msg_id: DiagnosticMessageId, span: Span, message: &str, ) { - self.diag_once( - diag_builder, - DiagnosticBuilderMethod::SpanNote, - msg_id, - message, - Some(span), - ); + self.diag_once(diag, DiagnosticBuilderMethod::SpanNote, msg_id, message, Some(span)); } - pub fn diag_note_once<'a, 'b>( - &'a self, - diag_builder: &'b mut DiagnosticBuilder<'a>, + pub fn diag_note_once( + &self, + diag: &mut Diagnostic, msg_id: DiagnosticMessageId, message: &str, ) { - self.diag_once(diag_builder, DiagnosticBuilderMethod::Note, msg_id, message, None); + self.diag_once(diag, DiagnosticBuilderMethod::Note, msg_id, message, None); } #[inline] |
