From 18715c98c67235274843974c928a70e84946398b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Feb 2024 11:58:51 +1100 Subject: [PATCH] Rename `DiagnosticMessage` as `DiagMessage`. --- compiler/rustc_codegen_ssa/src/back/write.rs | 8 +- .../rustc_const_eval/src/const_eval/error.rs | 6 +- compiler/rustc_const_eval/src/errors.rs | 19 +++-- compiler/rustc_error_messages/src/lib.rs | 80 +++++++++---------- .../src/annotate_snippet_emitter_writer.rs | 6 +- compiler/rustc_errors/src/diagnostic.rs | 28 +++---- compiler/rustc_errors/src/emitter.rs | 20 +++-- compiler/rustc_errors/src/lib.rs | 68 ++++++++-------- compiler/rustc_errors/src/tests.rs | 16 ++-- compiler/rustc_errors/src/translation.rs | 14 ++-- compiler/rustc_expand/src/mbe/diagnostics.rs | 6 +- compiler/rustc_expand/src/mbe/macro_check.rs | 4 +- .../rustc_expand/src/proc_macro_server.rs | 2 +- compiler/rustc_fluent_macro/src/fluent.rs | 7 +- compiler/rustc_fluent_macro/src/lib.rs | 8 +- .../rustc_hir_analysis/src/check/intrinsic.rs | 4 +- compiler/rustc_infer/src/errors/mod.rs | 10 +-- compiler/rustc_lint/src/context.rs | 14 ++-- compiler/rustc_lint/src/internal.rs | 2 +- compiler/rustc_lint/src/levels.rs | 4 +- compiler/rustc_lint/src/lints.rs | 30 +++---- compiler/rustc_lint/src/types.rs | 8 +- compiler/rustc_lint_defs/src/lib.rs | 10 +-- .../src/diagnostics/diagnostic.rs | 2 +- compiler/rustc_middle/src/error.rs | 8 +- compiler/rustc_middle/src/lint.rs | 6 +- .../rustc_middle/src/mir/interpret/error.rs | 6 +- compiler/rustc_middle/src/mir/mod.rs | 4 +- compiler/rustc_middle/src/mir/terminator.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 6 +- compiler/rustc_middle/src/ty/layout.rs | 4 +- compiler/rustc_middle/src/ty/sty.rs | 6 +- .../src/dataflow_const_prop.rs | 2 +- compiler/rustc_mir_transform/src/errors.rs | 10 +-- compiler/rustc_session/src/errors.rs | 6 +- compiler/rustc_session/src/parse.rs | 12 +-- compiler/rustc_session/src/session.rs | 16 ++-- compiler/rustc_span/src/symbol.rs | 2 +- .../src/traits/error_reporting/suggestions.rs | 3 +- src/librustdoc/html/markdown.rs | 8 +- .../passes/collect_intra_doc_links.rs | 6 +- .../tests/ui-internal/disallow_span_lint.rs | 11 ++- src/tools/miri/src/diagnostics.rs | 4 +- src/tools/rustfmt/src/parse/session.rs | 2 +- tests/ui-fulldeps/fluent-messages/test.rs | 6 +- .../diagnostic-derive-doc-comment-field.rs | 2 +- .../session-diagnostic/diagnostic-derive.rs | 2 +- .../session-diagnostic/invalid-variable.rs | 2 +- .../subdiagnostic-derive.rs | 2 +- 49 files changed, 253 insertions(+), 261 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 60865d06ab9..33b58035a09 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -16,8 +16,8 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::emitter::Emitter; use rustc_errors::translation::Translate; use rustc_errors::{ - Diag, DiagArgMap, DiagCtxt, DiagnosticMessage, ErrCode, FatalError, FluentBundle, Level, - MultiSpan, Style, + Diag, DiagArgMap, DiagCtxt, DiagMessage, ErrCode, FatalError, FluentBundle, Level, MultiSpan, + Style, }; use rustc_fs_util::link_or_copy; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; @@ -1015,7 +1015,7 @@ pub struct CguMessage; // - `emitted_at`: not used for codegen diagnostics. struct Diagnostic { level: Level, - messages: Vec<(DiagnosticMessage, Style)>, + messages: Vec<(DiagMessage, Style)>, code: Option, children: Vec, args: DiagArgMap, @@ -1026,7 +1026,7 @@ struct Diagnostic { // - `span`: it doesn't impl `Send`. pub struct Subdiagnostic { level: Level, - messages: Vec<(DiagnosticMessage, Style)>, + messages: Vec<(DiagMessage, Style)>, } #[derive(PartialEq, Clone, Copy, Debug)] diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs index 62bc68b1a20..e5b4fc3a574 100644 --- a/compiler/rustc_const_eval/src/const_eval/error.rs +++ b/compiler/rustc_const_eval/src/const_eval/error.rs @@ -1,8 +1,6 @@ use std::mem; -use rustc_errors::{ - DiagArgName, DiagArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg, -}; +use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, IntoDiagnostic, IntoDiagnosticArg}; use rustc_hir::CRATE_HIR_ID; use rustc_middle::mir::AssertKind; use rustc_middle::query::TyCtxtAt; @@ -25,7 +23,7 @@ pub enum ConstEvalErrKind { } impl MachineStopType for ConstEvalErrKind { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; use ConstEvalErrKind::*; match self { diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index c59e0a0df9f..afabd9689c6 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -1,8 +1,7 @@ use std::borrow::Cow; use rustc_errors::{ - codes::*, Diag, DiagArgValue, DiagCtxt, DiagnosticMessage, EmissionGuarantee, IntoDiagnostic, - Level, + codes::*, Diag, DiagArgValue, DiagCtxt, DiagMessage, EmissionGuarantee, IntoDiagnostic, Level, }; use rustc_hir::ConstContext; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; @@ -424,7 +423,7 @@ pub struct UndefinedBehavior { pub trait ReportErrorExt { /// Returns the diagnostic message for this error. - fn diagnostic_message(&self) -> DiagnosticMessage; + fn diagnostic_message(&self) -> DiagMessage; fn add_args(self, diag: &mut Diag<'_, G>); fn debug(self) -> String @@ -433,7 +432,7 @@ pub trait ReportErrorExt { { ty::tls::with(move |tcx| { let dcx = tcx.dcx(); - let mut diag = dcx.struct_allow(DiagnosticMessage::Str(String::new().into())); + let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into())); let message = self.diagnostic_message(); self.add_args(&mut diag); let s = dcx.eagerly_translate_to_string(message, diag.args.iter()); @@ -457,7 +456,7 @@ fn bad_pointer_message(msg: CheckInAllocMsg, dcx: &DiagCtxt) -> String { } impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; use UndefinedBehaviorInfo::*; match self { @@ -595,7 +594,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { } impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; use rustc_middle::mir::interpret::ValidationErrorKind::*; match self.kind { @@ -783,7 +782,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { } impl ReportErrorExt for UnsupportedOpInfo { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; match self { UnsupportedOpInfo::Unsupported(s) => s.clone().into(), @@ -819,7 +818,7 @@ impl ReportErrorExt for UnsupportedOpInfo { } impl<'tcx> ReportErrorExt for InterpError<'tcx> { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { match self { InterpError::UndefinedBehavior(ub) => ub.diagnostic_message(), InterpError::Unsupported(e) => e.diagnostic_message(), @@ -842,7 +841,7 @@ impl<'tcx> ReportErrorExt for InterpError<'tcx> { } impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; match self { InvalidProgramInfo::TooGeneric => const_eval_too_generic, @@ -877,7 +876,7 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> { } impl ReportErrorExt for ResourceExhaustionInfo { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; match self { ResourceExhaustionInfo::StackFrameLimitReached => const_eval_stack_frame_limit_reached, diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index f91b6655f63..f64ea3e0320 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -253,8 +253,8 @@ type FluentId = Cow<'static, str>; /// translatable and non-translatable diagnostic messages. /// /// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent -/// message so messages of this type must be combined with a `DiagnosticMessage` (using -/// `DiagnosticMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from +/// message so messages of this type must be combined with a `DiagMessage` (using +/// `DiagMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from /// the `Subdiagnostic` derive refer to Fluent identifiers directly. #[rustc_diagnostic_item = "SubdiagnosticMessage"] pub enum SubdiagnosticMessage { @@ -265,7 +265,7 @@ pub enum SubdiagnosticMessage { /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would /// be instantiated multiple times with different values. These subdiagnostics' messages /// are translated when they are added to the parent diagnostic, producing this variant of - /// `DiagnosticMessage`. + /// `DiagMessage`. Translated(Cow<'static, str>), /// Identifier of a Fluent message. Instances of this variant are generated by the /// `Subdiagnostic` derive. @@ -299,8 +299,8 @@ impl From> for SubdiagnosticMessage { /// /// Intended to be removed once diagnostics are entirely translatable. #[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] -#[rustc_diagnostic_item = "DiagnosticMessage"] -pub enum DiagnosticMessage { +#[rustc_diagnostic_item = "DiagMessage"] +pub enum DiagMessage { /// Non-translatable diagnostic message. Str(Cow<'static, str>), /// Translatable message which has been already translated. @@ -308,7 +308,7 @@ pub enum DiagnosticMessage { /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would /// be instantiated multiple times with different values. These subdiagnostics' messages /// are translated when they are added to the parent diagnostic, producing this variant of - /// `DiagnosticMessage`. + /// `DiagMessage`. Translated(Cow<'static, str>), /// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic /// message. Yet to be translated. @@ -318,85 +318,81 @@ pub enum DiagnosticMessage { FluentIdentifier(FluentId, Option), } -impl DiagnosticMessage { +impl DiagMessage { /// Given a `SubdiagnosticMessage` which may contain a Fluent attribute, create a new - /// `DiagnosticMessage` that combines that attribute with the Fluent identifier of `self`. + /// `DiagMessage` that combines that attribute with the Fluent identifier of `self`. /// /// - If the `SubdiagnosticMessage` is non-translatable then return the message as a - /// `DiagnosticMessage`. + /// `DiagMessage`. /// - If `self` is non-translatable then return `self`'s message. pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self { let attr = match sub { - SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s), - SubdiagnosticMessage::Translated(s) => return DiagnosticMessage::Translated(s), + SubdiagnosticMessage::Str(s) => return DiagMessage::Str(s), + SubdiagnosticMessage::Translated(s) => return DiagMessage::Translated(s), SubdiagnosticMessage::FluentIdentifier(id) => { - return DiagnosticMessage::FluentIdentifier(id, None); + return DiagMessage::FluentIdentifier(id, None); } SubdiagnosticMessage::FluentAttr(attr) => attr, }; match self { - DiagnosticMessage::Str(s) => DiagnosticMessage::Str(s.clone()), - DiagnosticMessage::Translated(s) => DiagnosticMessage::Translated(s.clone()), - DiagnosticMessage::FluentIdentifier(id, _) => { - DiagnosticMessage::FluentIdentifier(id.clone(), Some(attr)) + DiagMessage::Str(s) => DiagMessage::Str(s.clone()), + DiagMessage::Translated(s) => DiagMessage::Translated(s.clone()), + DiagMessage::FluentIdentifier(id, _) => { + DiagMessage::FluentIdentifier(id.clone(), Some(attr)) } } } pub fn as_str(&self) -> Option<&str> { match self { - DiagnosticMessage::Translated(s) | DiagnosticMessage::Str(s) => Some(s), - DiagnosticMessage::FluentIdentifier(_, _) => None, + DiagMessage::Translated(s) | DiagMessage::Str(s) => Some(s), + DiagMessage::FluentIdentifier(_, _) => None, } } } -impl From for DiagnosticMessage { +impl From for DiagMessage { fn from(s: String) -> Self { - DiagnosticMessage::Str(Cow::Owned(s)) + DiagMessage::Str(Cow::Owned(s)) } } -impl From<&'static str> for DiagnosticMessage { +impl From<&'static str> for DiagMessage { fn from(s: &'static str) -> Self { - DiagnosticMessage::Str(Cow::Borrowed(s)) + DiagMessage::Str(Cow::Borrowed(s)) } } -impl From> for DiagnosticMessage { +impl From> for DiagMessage { fn from(s: Cow<'static, str>) -> Self { - DiagnosticMessage::Str(s) + DiagMessage::Str(s) } } /// A workaround for must_produce_diag ICEs when formatting types in disabled lints. /// -/// Delays formatting until `.into(): DiagnosticMessage` is used. +/// Delays formatting until `.into(): DiagMessage` is used. pub struct DelayDm(pub F); -impl String> From> for DiagnosticMessage { +impl String> From> for DiagMessage { fn from(DelayDm(f): DelayDm) -> Self { - DiagnosticMessage::from(f()) + DiagMessage::from(f()) } } /// Translating *into* a subdiagnostic message from a diagnostic message is a little strange - but /// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagnosticMessage` and the -/// subdiagnostic derive refers to typed identifiers that are `DiagnosticMessage`s, so need to be -/// able to convert between these, as much as they'll be converted back into `DiagnosticMessage` +/// subdiagnostic derive refers to typed identifiers that are `DiagMessage`s, so need to be +/// able to convert between these, as much as they'll be converted back into `DiagMessage` /// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive. -impl Into for DiagnosticMessage { +impl Into for DiagMessage { fn into(self) -> SubdiagnosticMessage { match self { - DiagnosticMessage::Str(s) => SubdiagnosticMessage::Str(s), - DiagnosticMessage::Translated(s) => SubdiagnosticMessage::Translated(s), - DiagnosticMessage::FluentIdentifier(id, None) => { - SubdiagnosticMessage::FluentIdentifier(id) - } + DiagMessage::Str(s) => SubdiagnosticMessage::Str(s), + DiagMessage::Translated(s) => SubdiagnosticMessage::Translated(s), + DiagMessage::FluentIdentifier(id, None) => SubdiagnosticMessage::FluentIdentifier(id), // There isn't really a sensible behaviour for this because it loses information but // this is the most sensible of the behaviours. - DiagnosticMessage::FluentIdentifier(_, Some(attr)) => { - SubdiagnosticMessage::FluentAttr(attr) - } + DiagMessage::FluentIdentifier(_, Some(attr)) => SubdiagnosticMessage::FluentAttr(attr), } } } @@ -412,7 +408,7 @@ pub struct SpanLabel { pub is_primary: bool, /// What label should we attach to this span (if any)? - pub label: Option, + pub label: Option, } /// A collection of `Span`s. @@ -426,7 +422,7 @@ pub struct SpanLabel { #[derive(Clone, Debug, Hash, PartialEq, Eq, Encodable, Decodable)] pub struct MultiSpan { primary_spans: Vec, - span_labels: Vec<(Span, DiagnosticMessage)>, + span_labels: Vec<(Span, DiagMessage)>, } impl MultiSpan { @@ -444,7 +440,7 @@ impl MultiSpan { MultiSpan { primary_spans: vec, span_labels: vec![] } } - pub fn push_span_label(&mut self, span: Span, label: impl Into) { + pub fn push_span_label(&mut self, span: Span, label: impl Into) { self.span_labels.push((span, label.into())); } @@ -487,7 +483,7 @@ impl MultiSpan { replacements_occurred } - pub fn pop_span_label(&mut self) -> Option<(Span, DiagnosticMessage)> { + pub fn pop_span_label(&mut self) -> Option<(Span, DiagMessage)> { self.span_labels.pop() } diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index e6668769b95..b71b93cc67c 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -9,8 +9,8 @@ use crate::emitter::FileWithAnnotatedLines; use crate::snippet::Line; use crate::translation::{to_fluent_args, Translate}; use crate::{ - CodeSuggestion, DiagInner, DiagnosticMessage, Emitter, ErrCode, FluentBundle, - LazyFallbackBundle, Level, MultiSpan, Style, Subdiag, + CodeSuggestion, DiagInner, DiagMessage, Emitter, ErrCode, FluentBundle, LazyFallbackBundle, + Level, MultiSpan, Style, Subdiag, }; use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; use rustc_data_structures::sync::Lrc; @@ -125,7 +125,7 @@ impl AnnotateSnippetEmitter { fn emit_messages_default( &mut self, level: &Level, - messages: &[(DiagnosticMessage, Style)], + messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, code: &Option, msp: &MultiSpan, diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 1c820bfd01f..eb3fdd0b01b 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -1,7 +1,7 @@ use crate::snippet::Style; use crate::{ - CodeSuggestion, DiagCtxt, DiagnosticMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, - MultiSpan, StashKey, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle, + CodeSuggestion, DiagCtxt, DiagMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, MultiSpan, + StashKey, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle, }; use rustc_data_structures::fx::FxIndexMap; use rustc_error_messages::fluent_value_from_str_list_sep_by_and; @@ -199,7 +199,7 @@ pub trait DecorateLint<'a, G: EmissionGuarantee> { /// Decorate and emit a lint. fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>); - fn msg(&self) -> DiagnosticMessage; + fn msg(&self) -> DiagMessage; } #[derive(Clone, Debug, Encodable, Decodable)] @@ -291,7 +291,7 @@ pub struct DiagInner { // outside of what methods in this crate themselves allow. pub(crate) level: Level, - pub messages: Vec<(DiagnosticMessage, Style)>, + pub messages: Vec<(DiagMessage, Style)>, pub code: Option, pub span: MultiSpan, pub children: Vec, @@ -312,12 +312,12 @@ pub struct DiagInner { impl DiagInner { #[track_caller] - pub fn new>(level: Level, message: M) -> Self { + pub fn new>(level: Level, message: M) -> Self { DiagInner::new_with_messages(level, vec![(message.into(), Style::NoStyle)]) } #[track_caller] - pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self { + pub fn new_with_messages(level: Level, messages: Vec<(DiagMessage, Style)>) -> Self { DiagInner { level, messages, @@ -397,7 +397,7 @@ impl DiagInner { pub(crate) fn subdiagnostic_message_to_diagnostic_message( &self, attr: impl Into, - ) -> DiagnosticMessage { + ) -> DiagMessage { let msg = self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages"); msg.with_subdiagnostic_message(attr.into()) @@ -429,7 +429,7 @@ impl DiagInner { &self, ) -> ( &Level, - &[(DiagnosticMessage, Style)], + &[(DiagMessage, Style)], &Option, &MultiSpan, &[Subdiag], @@ -472,7 +472,7 @@ impl PartialEq for DiagInner { #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct Subdiag { pub level: Level, - pub messages: Vec<(DiagnosticMessage, Style)>, + pub messages: Vec<(DiagMessage, Style)>, pub span: MultiSpan, } @@ -578,7 +578,7 @@ macro_rules! with_fn { impl<'a, G: EmissionGuarantee> Diag<'a, G> { #[rustc_lint_diagnostics] #[track_caller] - pub fn new>(dcx: &'a DiagCtxt, level: Level, message: M) -> Self { + pub fn new>(dcx: &'a DiagCtxt, level: Level, message: M) -> Self { Self::new_diagnostic(dcx, DiagInner::new(level, message)) } @@ -1203,7 +1203,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_primary_message, /// Add a primary message. - pub fn primary_message(&mut self, msg: impl Into) -> &mut Self { + pub fn primary_message(&mut self, msg: impl Into) -> &mut Self { self.messages[0] = (msg.into(), Style::NoStyle); self } } @@ -1219,13 +1219,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { self } } - /// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by + /// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagMessage` by /// combining it with the primary message of the diagnostic (if translatable, otherwise it just /// passes the user's string along). pub(crate) fn subdiagnostic_message_to_diagnostic_message( &self, attr: impl Into, - ) -> DiagnosticMessage { + ) -> DiagMessage { self.deref().subdiagnostic_message_to_diagnostic_message(attr) } @@ -1338,7 +1338,7 @@ impl Drop for Diag<'_, G> { Some(diag) if !panicking() => { self.dcx.emit_diagnostic(DiagInner::new( Level::Bug, - DiagnosticMessage::from("the following error was constructed but not emitted"), + DiagMessage::from("the following error was constructed but not emitted"), )); self.dcx.emit_diagnostic(*diag); panic!("error was constructed but not emitted"); diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 5637c05d04c..293d8f01e67 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -17,7 +17,7 @@ use crate::snippet::{ use crate::styled_buffer::StyledBuffer; use crate::translation::{to_fluent_args, Translate}; use crate::{ - diagnostic::DiagLocation, CodeSuggestion, DiagCtxt, DiagInner, DiagnosticMessage, ErrCode, + diagnostic::DiagLocation, CodeSuggestion, DiagCtxt, DiagInner, DiagMessage, ErrCode, FluentBundle, LazyFallbackBundle, Level, MultiSpan, Subdiag, SubstitutionHighlight, SuggestionStyle, TerminalUrl, }; @@ -339,7 +339,7 @@ pub trait Emitter: Translate { children.push(Subdiag { level: Level::Note, - messages: vec![(DiagnosticMessage::from(msg), Style::NoStyle)], + messages: vec![(DiagMessage::from(msg), Style::NoStyle)], span: MultiSpan::new(), }); } @@ -543,12 +543,10 @@ pub struct SilentEmitter { pub fatal_note: String, } -pub fn silent_translate<'a>( - message: &'a DiagnosticMessage, -) -> Result, TranslateError<'_>> { +pub fn silent_translate<'a>(message: &'a DiagMessage) -> Result, TranslateError<'_>> { match message { - DiagnosticMessage::Str(msg) | DiagnosticMessage::Translated(msg) => Ok(Cow::Borrowed(msg)), - DiagnosticMessage::FluentIdentifier(identifier, _) => { + DiagMessage::Str(msg) | DiagMessage::Translated(msg) => Ok(Cow::Borrowed(msg)), + DiagMessage::FluentIdentifier(identifier, _) => { // Any value works here. Ok(identifier.clone()) } @@ -568,7 +566,7 @@ impl Translate for SilentEmitter { // subdiagnostics result in a call to this. fn translate_message<'a>( &'a self, - message: &'a DiagnosticMessage, + message: &'a DiagMessage, _: &'a FluentArgs<'_>, ) -> Result, TranslateError<'_>> { silent_translate(message) @@ -1216,7 +1214,7 @@ impl HumanEmitter { fn msgs_to_buffer( &self, buffer: &mut StyledBuffer, - msgs: &[(DiagnosticMessage, Style)], + msgs: &[(DiagMessage, Style)], args: &FluentArgs<'_>, padding: usize, label: &str, @@ -1291,7 +1289,7 @@ impl HumanEmitter { fn emit_messages_default_inner( &mut self, msp: &MultiSpan, - msgs: &[(DiagnosticMessage, Style)], + msgs: &[(DiagMessage, Style)], args: &FluentArgs<'_>, code: &Option, level: &Level, @@ -2060,7 +2058,7 @@ impl HumanEmitter { fn emit_messages_default( &mut self, level: &Level, - messages: &[(DiagnosticMessage, Style)], + messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, code: &Option, span: &MultiSpan, diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 6b1ccbc5f7c..504a2dfbd6f 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -47,8 +47,8 @@ pub use diagnostic_impls::{ }; pub use emitter::ColorConfig; pub use rustc_error_messages::{ - fallback_fluent_bundle, fluent_bundle, DelayDm, DiagnosticMessage, FluentBundle, - LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage, + fallback_fluent_bundle, fluent_bundle, DelayDm, DiagMessage, FluentBundle, LanguageIdentifier, + LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage, }; pub use rustc_lint_defs::{pluralize, Applicability}; pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker}; @@ -154,7 +154,7 @@ pub struct CodeSuggestion { /// ] /// ``` pub substitutions: Vec, - pub msg: DiagnosticMessage, + pub msg: DiagMessage, /// Visual representation of this suggestion. pub style: SuggestionStyle, /// Whether or not the suggestion is approximate @@ -634,7 +634,7 @@ impl DiagCtxt { /// Translate `message` eagerly with `args` to `SubdiagnosticMessage::Eager`. pub fn eagerly_translate<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator>, ) -> SubdiagnosticMessage { let inner = self.inner.borrow(); @@ -644,7 +644,7 @@ impl DiagCtxt { /// Translate `message` eagerly with `args` to `String`. pub fn eagerly_translate_to_string<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator>, ) -> String { let inner = self.inner.borrow(); @@ -904,7 +904,7 @@ impl DiagCtxt { // configuration like `--cap-lints allow --force-warn bare_trait_objects`. inner.emit_diagnostic(DiagInner::new( ForceWarning(None), - DiagnosticMessage::Str(warnings), + DiagMessage::Str(warnings), )); } (_, 0) => { @@ -1078,13 +1078,13 @@ impl DiagCtxt { impl DiagCtxt { // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn struct_bug(&self, msg: impl Into) -> Diag<'_, BugAbort> { + pub fn struct_bug(&self, msg: impl Into) -> Diag<'_, BugAbort> { Diag::new(self, Bug, msg) } // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn bug(&self, msg: impl Into) -> ! { + pub fn bug(&self, msg: impl Into) -> ! { self.struct_bug(msg).emit() } @@ -1093,14 +1093,14 @@ impl DiagCtxt { pub fn struct_span_bug( &self, span: impl Into, - msg: impl Into, + msg: impl Into, ) -> Diag<'_, BugAbort> { self.struct_bug(msg).with_span(span) } // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn span_bug(&self, span: impl Into, msg: impl Into) -> ! { + pub fn span_bug(&self, span: impl Into, msg: impl Into) -> ! { self.struct_span_bug(span, msg).emit() } @@ -1116,13 +1116,13 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_fatal(&self, msg: impl Into) -> Diag<'_, FatalAbort> { + pub fn struct_fatal(&self, msg: impl Into) -> Diag<'_, FatalAbort> { Diag::new(self, Fatal, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn fatal(&self, msg: impl Into) -> ! { + pub fn fatal(&self, msg: impl Into) -> ! { self.struct_fatal(msg).emit() } @@ -1131,14 +1131,14 @@ impl DiagCtxt { pub fn struct_span_fatal( &self, span: impl Into, - msg: impl Into, + msg: impl Into, ) -> Diag<'_, FatalAbort> { self.struct_fatal(msg).with_span(span) } #[rustc_lint_diagnostics] #[track_caller] - pub fn span_fatal(&self, span: impl Into, msg: impl Into) -> ! { + pub fn span_fatal(&self, span: impl Into, msg: impl Into) -> ! { self.struct_span_fatal(span, msg).emit() } @@ -1174,13 +1174,13 @@ impl DiagCtxt { // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_err(&self, msg: impl Into) -> Diag<'_> { + pub fn struct_err(&self, msg: impl Into) -> Diag<'_> { Diag::new(self, Error, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn err(&self, msg: impl Into) -> ErrorGuaranteed { + pub fn err(&self, msg: impl Into) -> ErrorGuaranteed { self.struct_err(msg).emit() } @@ -1189,7 +1189,7 @@ impl DiagCtxt { pub fn struct_span_err( &self, span: impl Into, - msg: impl Into, + msg: impl Into, ) -> Diag<'_> { self.struct_err(msg).with_span(span) } @@ -1199,7 +1199,7 @@ impl DiagCtxt { pub fn span_err( &self, span: impl Into, - msg: impl Into, + msg: impl Into, ) -> ErrorGuaranteed { self.struct_span_err(span, msg).emit() } @@ -1217,7 +1217,7 @@ impl DiagCtxt { /// Ensures that an error is printed. See `Level::DelayedBug`. // No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing. #[track_caller] - pub fn delayed_bug(&self, msg: impl Into) -> ErrorGuaranteed { + pub fn delayed_bug(&self, msg: impl Into) -> ErrorGuaranteed { Diag::::new(self, DelayedBug, msg).emit() } @@ -1230,20 +1230,20 @@ impl DiagCtxt { pub fn span_delayed_bug( &self, sp: impl Into, - msg: impl Into, + msg: impl Into, ) -> ErrorGuaranteed { Diag::::new(self, DelayedBug, msg).with_span(sp).emit() } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_warn(&self, msg: impl Into) -> Diag<'_, ()> { + pub fn struct_warn(&self, msg: impl Into) -> Diag<'_, ()> { Diag::new(self, Warning, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn warn(&self, msg: impl Into) { + pub fn warn(&self, msg: impl Into) { self.struct_warn(msg).emit() } @@ -1252,14 +1252,14 @@ impl DiagCtxt { pub fn struct_span_warn( &self, span: impl Into, - msg: impl Into, + msg: impl Into, ) -> Diag<'_, ()> { self.struct_warn(msg).with_span(span) } #[rustc_lint_diagnostics] #[track_caller] - pub fn span_warn(&self, span: impl Into, msg: impl Into) { + pub fn span_warn(&self, span: impl Into, msg: impl Into) { self.struct_span_warn(span, msg).emit() } @@ -1275,13 +1275,13 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_note(&self, msg: impl Into) -> Diag<'_, ()> { + pub fn struct_note(&self, msg: impl Into) -> Diag<'_, ()> { Diag::new(self, Note, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn note(&self, msg: impl Into) { + pub fn note(&self, msg: impl Into) { self.struct_note(msg).emit() } @@ -1290,14 +1290,14 @@ impl DiagCtxt { pub fn struct_span_note( &self, span: impl Into, - msg: impl Into, + msg: impl Into, ) -> Diag<'_, ()> { self.struct_note(msg).with_span(span) } #[rustc_lint_diagnostics] #[track_caller] - pub fn span_note(&self, span: impl Into, msg: impl Into) { + pub fn span_note(&self, span: impl Into, msg: impl Into) { self.struct_span_note(span, msg).emit() } @@ -1313,19 +1313,19 @@ impl DiagCtxt { #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_help(&self, msg: impl Into) -> Diag<'_, ()> { + pub fn struct_help(&self, msg: impl Into) -> Diag<'_, ()> { Diag::new(self, Help, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_failure_note(&self, msg: impl Into) -> Diag<'_, ()> { + pub fn struct_failure_note(&self, msg: impl Into) -> Diag<'_, ()> { Diag::new(self, FailureNote, msg) } #[rustc_lint_diagnostics] #[track_caller] - pub fn struct_allow(&self, msg: impl Into) -> Diag<'_, ()> { + pub fn struct_allow(&self, msg: impl Into) -> Diag<'_, ()> { Diag::new(self, Allow, msg) } @@ -1333,7 +1333,7 @@ impl DiagCtxt { #[track_caller] pub fn struct_expect( &self, - msg: impl Into, + msg: impl Into, id: LintExpectationId, ) -> Diag<'_, ()> { Diag::new(self, Expect(id), msg) @@ -1556,7 +1556,7 @@ impl DiagCtxtInner { /// Translate `message` eagerly with `args` to `SubdiagnosticMessage::Eager`. pub fn eagerly_translate<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator>, ) -> SubdiagnosticMessage { SubdiagnosticMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args))) @@ -1565,7 +1565,7 @@ impl DiagCtxtInner { /// Translate `message` eagerly with `args` to `String`. pub fn eagerly_translate_to_string<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator>, ) -> String { let args = crate::translation::to_fluent_args(args); diff --git a/compiler/rustc_errors/src/tests.rs b/compiler/rustc_errors/src/tests.rs index 79a2af7f38f..50d58aec36a 100644 --- a/compiler/rustc_errors/src/tests.rs +++ b/compiler/rustc_errors/src/tests.rs @@ -5,7 +5,7 @@ use crate::FluentBundle; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_error_messages::fluent_bundle::resolver::errors::{ReferenceKind, ResolverError}; use rustc_error_messages::langid; -use rustc_error_messages::DiagnosticMessage; +use rustc_error_messages::DiagMessage; struct Dummy { bundle: FluentBundle, @@ -53,7 +53,7 @@ fn wellformed_fluent() { args.set("name", "Foo"); args.set("ty", "std::string::String"); { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("suggestion".into()), ); @@ -65,7 +65,7 @@ fn wellformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("value_borrowed_label".into()), ); @@ -77,7 +77,7 @@ fn wellformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("occurs_because_label".into()), ); @@ -88,7 +88,7 @@ fn wellformed_fluent() { ); { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("label".into()), ); @@ -112,7 +112,7 @@ fn misformed_fluent() { args.set("name", "Foo"); args.set("ty", "std::string::String"); { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("value_borrowed_label".into()), ); @@ -141,7 +141,7 @@ fn misformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("label".into()), ); @@ -168,7 +168,7 @@ fn misformed_fluent() { } { - let message = DiagnosticMessage::FluentIdentifier( + let message = DiagMessage::FluentIdentifier( "mir_build_borrow_of_moved_value".into(), Some("occurs_because_label".into()), ); diff --git a/compiler/rustc_errors/src/translation.rs b/compiler/rustc_errors/src/translation.rs index 1f98ba4c3b9..bf0026568ce 100644 --- a/compiler/rustc_errors/src/translation.rs +++ b/compiler/rustc_errors/src/translation.rs @@ -1,6 +1,6 @@ use crate::error::{TranslateError, TranslateErrorKind}; use crate::snippet::Style; -use crate::{DiagArg, DiagnosticMessage, FluentBundle}; +use crate::{DiagArg, DiagMessage, FluentBundle}; use rustc_data_structures::sync::Lrc; pub use rustc_error_messages::FluentArgs; use std::borrow::Cow; @@ -37,10 +37,10 @@ pub trait Translate { /// unavailable for the requested locale. fn fallback_fluent_bundle(&self) -> &FluentBundle; - /// Convert `DiagnosticMessage`s to a string, performing translation if necessary. + /// Convert `DiagMessage`s to a string, performing translation if necessary. fn translate_messages( &self, - messages: &[(DiagnosticMessage, Style)], + messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, ) -> Cow<'_, str> { Cow::Owned( @@ -51,18 +51,18 @@ pub trait Translate { ) } - /// Convert a `DiagnosticMessage` to a string, performing translation if necessary. + /// Convert a `DiagMessage` to a string, performing translation if necessary. fn translate_message<'a>( &'a self, - message: &'a DiagnosticMessage, + message: &'a DiagMessage, args: &'a FluentArgs<'_>, ) -> Result, TranslateError<'_>> { trace!(?message, ?args); let (identifier, attr) = match message { - DiagnosticMessage::Str(msg) | DiagnosticMessage::Translated(msg) => { + DiagMessage::Str(msg) | DiagMessage::Translated(msg) => { return Ok(Cow::Borrowed(msg)); } - DiagnosticMessage::FluentIdentifier(identifier, attr) => (identifier, attr), + DiagMessage::FluentIdentifier(identifier, attr) => (identifier, attr), }; let translate_with_bundle = |bundle: &'a FluentBundle| -> Result, TranslateError<'_>> { diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index d8b8a0fa96a..15193298cca 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -7,7 +7,7 @@ use crate::mbe::{ use rustc_ast::token::{self, Token, TokenKind}; use rustc_ast::tokenstream::TokenStream; use rustc_ast_pretty::pprust; -use rustc_errors::{Applicability, Diag, DiagCtxt, DiagnosticMessage}; +use rustc_errors::{Applicability, Diag, DiagCtxt, DiagMessage}; use rustc_parse::parser::{Parser, Recovery}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::Ident; @@ -227,12 +227,12 @@ pub(super) fn emit_frag_parse_err( ) -> ErrorGuaranteed { // FIXME(davidtwco): avoid depending on the error message text if parser.token == token::Eof - && let DiagnosticMessage::Str(message) = &e.messages[0].0 + && let DiagMessage::Str(message) = &e.messages[0].0 && message.ends_with(", found ``") { let msg = &e.messages[0]; e.messages[0] = ( - DiagnosticMessage::from(format!( + DiagMessage::from(format!( "macro expansion ends with an incomplete expression: {}", message.replace(", found ``", ""), )), diff --git a/compiler/rustc_expand/src/mbe/macro_check.rs b/compiler/rustc_expand/src/mbe/macro_check.rs index 19405dcfd6c..dce8e0c36ed 100644 --- a/compiler/rustc_expand/src/mbe/macro_check.rs +++ b/compiler/rustc_expand/src/mbe/macro_check.rs @@ -110,7 +110,7 @@ use crate::mbe::{KleeneToken, TokenTree}; use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind}; use rustc_ast::{NodeId, DUMMY_NODE_ID}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{DiagnosticMessage, MultiSpan}; +use rustc_errors::{DiagMessage, MultiSpan}; use rustc_session::lint::builtin::{META_VARIABLE_MISUSE, MISSING_FRAGMENT_SPECIFIER}; use rustc_session::parse::ParseSess; use rustc_span::symbol::kw; @@ -648,7 +648,7 @@ fn buffer_lint( psess: &ParseSess, span: MultiSpan, node_id: NodeId, - message: impl Into, + message: impl Into, ) { // Macros loaded from other crates have dummy node ids. if node_id != DUMMY_NODE_ID { diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index efe35c252d8..32a083a72f0 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -512,7 +512,7 @@ impl server::FreeFunctions for Rustc<'_, '_> { } fn emit_diagnostic(&mut self, diagnostic: Diagnostic) { - let message = rustc_errors::DiagnosticMessage::from(diagnostic.message); + let message = rustc_errors::DiagMessage::from(diagnostic.message); let mut diag: Diag<'_, ()> = Diag::new(&self.psess().dcx, diagnostic.level.to_internal(), message); diag.span(MultiSpan::from_spans(diagnostic.spans)); diff --git a/compiler/rustc_fluent_macro/src/fluent.rs b/compiler/rustc_fluent_macro/src/fluent.rs index 520a64aaf5e..cbbec34fadb 100644 --- a/compiler/rustc_fluent_macro/src/fluent.rs +++ b/compiler/rustc_fluent_macro/src/fluent.rs @@ -244,8 +244,11 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok format!("Constant referring to Fluent message `{name}` from `{crate_name}`"); constants.extend(quote! { #[doc = #docstr] - pub const #snake_name: rustc_errors::DiagnosticMessage = - rustc_errors::DiagnosticMessage::FluentIdentifier(std::borrow::Cow::Borrowed(#name), None); + pub const #snake_name: rustc_errors::DiagMessage = + rustc_errors::DiagMessage::FluentIdentifier( + std::borrow::Cow::Borrowed(#name), + None + ); }); for Attribute { id: Identifier { name: attr_name }, .. } in attributes { diff --git a/compiler/rustc_fluent_macro/src/lib.rs b/compiler/rustc_fluent_macro/src/lib.rs index e3784409af8..2303785f94e 100644 --- a/compiler/rustc_fluent_macro/src/lib.rs +++ b/compiler/rustc_fluent_macro/src/lib.rs @@ -35,10 +35,10 @@ mod fluent; /// /// mod fluent_generated { /// mod typeck { -/// pub const field_multiply_specified_in_initializer: DiagnosticMessage = -/// DiagnosticMessage::fluent("typeck_field_multiply_specified_in_initializer"); -/// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage = -/// DiagnosticMessage::fluent_attr( +/// pub const field_multiply_specified_in_initializer: DiagMessage = +/// DiagMessage::fluent("typeck_field_multiply_specified_in_initializer"); +/// pub const field_multiply_specified_in_initializer_label_previous_use: DiagMessage = +/// DiagMessage::fluent_attr( /// "typeck_field_multiply_specified_in_initializer", /// "previous_use_label" /// ); diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 9d8eb6ad60b..64137f298d6 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -7,7 +7,7 @@ use crate::errors::{ WrongNumberOfGenericArgumentsToIntrinsic, }; -use rustc_errors::{codes::*, struct_span_code_err, DiagnosticMessage}; +use rustc_errors::{codes::*, struct_span_code_err, DiagMessage}; use rustc_hir as hir; use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -139,7 +139,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) - if has_safe_attr != is_in_list { tcx.dcx().struct_span_err( tcx.def_span(intrinsic_id), - DiagnosticMessage::from(format!( + DiagMessage::from(format!( "intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `{}`", tcx.item_name(intrinsic_id.into()) ) diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index cecc52c8326..f2cb1eb2f98 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -1,6 +1,6 @@ use hir::GenericParamKind; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, Diag, DiagStyledString, DiagnosticMessage, + codes::*, AddToDiagnostic, Applicability, Diag, DiagMessage, DiagStyledString, EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp, }; use rustc_hir as hir; @@ -209,11 +209,11 @@ impl<'a> SourceKindMultiSuggestion<'a> { pub enum RegionOriginNote<'a> { Plain { span: Span, - msg: DiagnosticMessage, + msg: DiagMessage, }, WithName { span: Span, - msg: DiagnosticMessage, + msg: DiagMessage, name: &'a str, continues: bool, }, @@ -230,7 +230,7 @@ impl AddToDiagnostic for RegionOriginNote<'_> { diag: &mut Diag<'_, G>, _f: F, ) { - let mut label_or_note = |span, msg: DiagnosticMessage| { + let mut label_or_note = |span, msg: DiagMessage| { let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count(); let expanded_sub_count = diag.children.iter().filter(|d| !d.span.is_dummy()).count(); let span_is_primary = diag.span.primary_spans().iter().all(|&sp| sp == span); @@ -766,7 +766,7 @@ impl AddToDiagnostic for ConsiderBorrowingParamHelp { ) { let mut type_param_span: MultiSpan = self.spans.clone().into(); for &span in &self.spans { - // Seems like we can't call f() here as Into is required + // Seems like we can't call f() here as Into is required type_param_span.push_span_label(span, fluent::infer_tid_consider_borrowing); } let msg = f(diag, fluent::infer_tid_param_help.into()); diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index ab76da36ee3..d1825577d9a 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -21,7 +21,7 @@ use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync; use rustc_data_structures::unord::UnordMap; -use rustc_errors::{DecorateLint, Diag, DiagnosticMessage, MultiSpan}; +use rustc_errors::{DecorateLint, Diag, DiagMessage, MultiSpan}; use rustc_feature::Features; use rustc_hir as hir; use rustc_hir::def::Res; @@ -536,7 +536,7 @@ pub trait LintContext { &self, lint: &'static Lint, span: Option>, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), diagnostic: BuiltinLintDiagnostics, ) { @@ -559,7 +559,7 @@ pub trait LintContext { &self, lint: &'static Lint, span: Option, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ); @@ -584,7 +584,7 @@ pub trait LintContext { &self, lint: &'static Lint, span: S, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { self.opt_span_lint(lint, Some(span), msg, decorate); @@ -605,7 +605,7 @@ pub trait LintContext { fn lint( &self, lint: &'static Lint, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { self.opt_span_lint(lint, None as Option, msg, decorate); @@ -670,7 +670,7 @@ impl<'tcx> LintContext for LateContext<'tcx> { &self, lint: &'static Lint, span: Option, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let hir_id = self.last_node_with_lint_attrs; @@ -697,7 +697,7 @@ impl LintContext for EarlyContext<'_> { &self, lint: &'static Lint, span: Option, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { self.builder.opt_span_lint(lint, span.map(|s| s.into()), msg, decorate) diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index a071fa488bc..85d78374881 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -403,7 +403,7 @@ impl LateLintPass<'_> for Diagnostics { debug!(?ty); if let Some(adt_def) = ty.ty_adt_def() && let Some(name) = cx.tcx.get_diagnostic_name(adt_def.did()) - && matches!(name, sym::DiagnosticMessage | sym::SubdiagnosticMessage) + && matches!(name, sym::DiagMessage | sym::SubdiagnosticMessage) { found_diagnostic_message = true; break; diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index ad4a0fc47db..906cd1d1283 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -16,7 +16,7 @@ use crate::{ use rustc_ast as ast; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxIndexMap; -use rustc_errors::{DecorateLint, Diag, DiagnosticMessage, MultiSpan}; +use rustc_errors::{DecorateLint, Diag, DiagMessage, MultiSpan}; use rustc_feature::{Features, GateIssue}; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; @@ -1106,7 +1106,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { &self, lint: &'static Lint, span: Option, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let (level, src) = self.lint_level(lint); diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index a9a2592ac7a..4243c009632 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -5,8 +5,8 @@ use std::num::NonZero; use crate::errors::RequestedLevel; use crate::fluent_generated as fluent; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, DecorateLint, Diag, DiagStyledString, - DiagnosticMessage, EmissionGuarantee, SubdiagnosticMessageOp, SuggestionStyle, + codes::*, AddToDiagnostic, Applicability, DecorateLint, Diag, DiagMessage, DiagStyledString, + EmissionGuarantee, SubdiagnosticMessageOp, SuggestionStyle, }; use rustc_hir::def_id::DefId; use rustc_macros::{LintDiagnostic, Subdiagnostic}; @@ -141,7 +141,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> { diag.arg("debug", self.tcx.def_path_str(self.def_id)); } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_builtin_missing_debug_impl } } @@ -251,7 +251,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> { ); } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_ungated_async_fn_track_caller } } @@ -416,7 +416,7 @@ pub struct BuiltinFeatureIssueNote { } pub struct BuiltinUnpermittedTypeInit<'a> { - pub msg: DiagnosticMessage, + pub msg: DiagMessage, pub ty: Ty<'a>, pub label: Span, pub sub: BuiltinUnpermittedTypeInitSub, @@ -437,7 +437,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> { self.sub.add_to_diagnostic(diag); } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { self.msg.clone() } } @@ -1179,7 +1179,7 @@ impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused { } } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_non_fmt_panic_unused } } @@ -1403,7 +1403,7 @@ impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> { diag.arg("needs_drop", self.tcx.def_path_str(self.def_id)); } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_drop_trait_constraints } } @@ -1419,7 +1419,7 @@ impl<'a> DecorateLint<'a, ()> for DropGlue<'_> { diag.arg("needs_drop", self.tcx.def_path_str(self.def_id)); } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_drop_glue } } @@ -1683,12 +1683,12 @@ pub struct ImproperCTypes<'a> { pub ty: Ty<'a>, pub desc: &'a str, pub label: Span, - pub help: Option, - pub note: DiagnosticMessage, + pub help: Option, + pub note: DiagMessage, pub span_note: Option, } -// Used because of the complexity of Option, DiagnosticMessage, and Option +// Used because of the complexity of Option, DiagMessage, and Option impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { diag.arg("ty", self.ty); @@ -1703,7 +1703,7 @@ impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> { } } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_improper_ctypes } } @@ -1846,7 +1846,7 @@ impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> { } } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_unused_def } } @@ -1923,7 +1923,7 @@ impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag { } } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_async_fn_in_trait } } diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index a87e2410b3d..71f330b5bf7 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -14,7 +14,7 @@ use crate::{LateContext, LateLintPass, LintContext}; use rustc_ast as ast; use rustc_attr as attr; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::DiagnosticMessage; +use rustc_errors::DiagMessage; use rustc_hir as hir; use rustc_hir::{is_range_literal, Expr, ExprKind, Node}; use rustc_middle::ty::layout::{IntegerExt, LayoutOf, SizeSkeleton}; @@ -959,7 +959,7 @@ struct ImproperCTypesVisitor<'a, 'tcx> { enum FfiResult<'tcx> { FfiSafe, FfiPhantom(Ty<'tcx>), - FfiUnsafe { ty: Ty<'tcx>, reason: DiagnosticMessage, help: Option }, + FfiUnsafe { ty: Ty<'tcx>, reason: DiagMessage, help: Option }, } pub(crate) fn nonnull_optimization_guaranteed<'tcx>( @@ -1446,8 +1446,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { &mut self, ty: Ty<'tcx>, sp: Span, - note: DiagnosticMessage, - help: Option, + note: DiagMessage, + help: Option, ) { let lint = match self.mode { CItemKind::Declaration => IMPROPER_CTYPES, diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 198008d4d0d..9bc5b2f005a 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::stable_hasher::{ HashStable, StableCompare, StableHasher, ToStableHashKey, }; -use rustc_error_messages::{DiagnosticMessage, MultiSpan}; +use rustc_error_messages::{DiagMessage, MultiSpan}; use rustc_hir::HashStableContext; use rustc_hir::HirId; use rustc_span::edition::Edition; @@ -674,7 +674,7 @@ pub struct BufferedEarlyLint { pub span: MultiSpan, /// The lint message. - pub msg: DiagnosticMessage, + pub msg: DiagMessage, /// The `NodeId` of the AST node that generated the lint. pub node_id: NodeId, @@ -703,7 +703,7 @@ impl LintBuffer { lint: &'static Lint, node_id: NodeId, span: MultiSpan, - msg: impl Into, + msg: impl Into, diagnostic: BuiltinLintDiagnostics, ) { let lint_id = LintId::of(lint); @@ -721,7 +721,7 @@ impl LintBuffer { lint: &'static Lint, id: NodeId, sp: impl Into, - msg: impl Into, + msg: impl Into, ) { self.add_lint(lint, id, sp.into(), msg, BuiltinLintDiagnostics::Normal) } @@ -731,7 +731,7 @@ impl LintBuffer { lint: &'static Lint, id: NodeId, sp: impl Into, - msg: impl Into, + msg: impl Into, diagnostic: BuiltinLintDiagnostics, ) { self.add_lint(lint, id, sp.into(), msg, diagnostic) diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index 5659569c645..a1a7b19642b 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -165,7 +165,7 @@ impl<'a> LintDiagnosticDerive<'a> { #implementation; } - fn msg(&self) -> rustc_errors::DiagnosticMessage { + fn msg(&self) -> rustc_errors::DiagMessage { #msg } } diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 0f6ec656932..0d3cffd2047 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -1,6 +1,6 @@ use std::fmt; -use rustc_errors::{codes::*, DiagArgName, DiagArgValue, DiagnosticMessage}; +use rustc_errors::{codes::*, DiagArgName, DiagArgValue, DiagMessage}; use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; @@ -93,16 +93,16 @@ pub(super) struct ConstNotUsedTraitAlias { } pub struct CustomSubdiagnostic<'a> { - pub msg: fn() -> DiagnosticMessage, + pub msg: fn() -> DiagMessage, pub add_args: Box, } impl<'a> CustomSubdiagnostic<'a> { - pub fn label(x: fn() -> DiagnosticMessage) -> Self { + pub fn label(x: fn() -> DiagMessage) -> Self { Self::label_and_then(x, |_| {}) } pub fn label_and_then( - msg: fn() -> DiagnosticMessage, + msg: fn() -> DiagMessage, f: F, ) -> Self { Self { msg, add_args: Box::new(move |x| f(x)) } diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 6a3522553c4..d8d6899f057 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -2,7 +2,7 @@ use std::cmp; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sorted_map::SortedMap; -use rustc_errors::{Diag, DiagnosticMessage, MultiSpan}; +use rustc_errors::{Diag, DiagMessage, MultiSpan}; use rustc_hir::{HirId, ItemLocalId}; use rustc_session::lint::{ builtin::{self, FORBIDDEN_LINT_GROUPS}, @@ -268,7 +268,7 @@ pub fn lint_level( level: Level, src: LintLevelSource, span: Option, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { // Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to @@ -280,7 +280,7 @@ pub fn lint_level( level: Level, src: LintLevelSource, span: Option, - msg: impl Into, + msg: impl Into, decorate: Box FnOnce(&'b mut Diag<'a, ()>)>, ) { // Check for future incompatibility lints and issue a stronger warning. diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index b85354e10f9..aea88c4588b 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -6,9 +6,7 @@ use crate::ty::{layout, tls, Ty, TyCtxt, ValTree}; use rustc_ast_ir::Mutability; use rustc_data_structures::sync::Lock; -use rustc_errors::{ - DiagArgName, DiagArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, -}; +use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_macros::HashStable; use rustc_session::CtfeBacktrace; use rustc_span::{def_id::DefId, Span, DUMMY_SP}; @@ -489,7 +487,7 @@ pub enum ResourceExhaustionInfo { /// A trait for machine-specific errors (or other "machine stop" conditions). pub trait MachineStopType: Any + fmt::Debug + Send { /// The diagnostic message for this error - fn diagnostic_message(&self) -> DiagnosticMessage; + fn diagnostic_message(&self) -> DiagMessage; /// Add diagnostic arguments by passing name and value pairs to `adder`, which are passed to /// fluent for formatting the translated diagnostic message. fn add_args(self: Box, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)); diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 5ce2e26a0bc..4b97c25f610 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -14,9 +14,7 @@ use crate::ty::{AdtDef, InstanceDef, UserTypeAnnotationIndex}; use crate::ty::{GenericArg, GenericArgsRef}; use rustc_data_structures::captures::Captures; -use rustc_errors::{ - DiagArgName, DiagArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, -}; +use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind}; diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index 4c7df0a7ae2..6c92dfa3cd8 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -251,7 +251,7 @@ impl AssertKind { /// `AssertKind::description` and the lang items mentioned in its docs). /// Note that we deliberately show more details here than we do at runtime, such as the actual /// numbers that overflowed -- it is much easier to do so here than at runtime. - pub fn diagnostic_message(&self) -> DiagnosticMessage { + pub fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; use AssertKind::*; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 96b4797f4fa..4eec93532a2 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -43,7 +43,7 @@ use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, WorkerLocal}; #[cfg(parallel_compiler)] use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::unord::UnordSet; -use rustc_errors::{DecorateLint, Diag, DiagCtxt, DiagnosticMessage, ErrorGuaranteed, MultiSpan}; +use rustc_errors::{DecorateLint, Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; @@ -2097,7 +2097,7 @@ impl<'tcx> TyCtxt<'tcx> { lint: &'static Lint, hir_id: HirId, span: impl Into, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let (level, src) = self.lint_level_at_node(lint, hir_id); @@ -2127,7 +2127,7 @@ impl<'tcx> TyCtxt<'tcx> { self, lint: &'static Lint, id: HirId, - msg: impl Into, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { let (level, src) = self.lint_level_at_node(lint, id); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 529d847bfb0..5a0e2aa691d 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -3,7 +3,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::query::TyCtxtAt; use crate::ty::normalize_erasing_regions::NormalizationError; use crate::ty::{self, ConstKind, Ty, TyCtxt, TypeVisitableExt}; -use rustc_error_messages::DiagnosticMessage; +use rustc_error_messages::DiagMessage; use rustc_errors::{ Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level, }; @@ -205,7 +205,7 @@ pub enum LayoutError<'tcx> { } impl<'tcx> LayoutError<'tcx> { - pub fn diagnostic_message(&self) -> DiagnosticMessage { + pub fn diagnostic_message(&self) -> DiagMessage { use crate::fluent_generated::*; use LayoutError::*; match self { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 03c61803572..17659ac2330 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -13,9 +13,7 @@ use crate::ty::{GenericArg, GenericArgs, GenericArgsRef}; use crate::ty::{List, ParamEnv}; use hir::def::DefKind; use rustc_data_structures::captures::Captures; -use rustc_errors::{ - DiagArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan, -}; +use rustc_errors::{DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::LangItem; @@ -1545,7 +1543,7 @@ impl<'tcx> Ty<'tcx> { pub fn new_error_with_message>( tcx: TyCtxt<'tcx>, span: S, - msg: impl Into, + msg: impl Into, ) -> Ty<'tcx> { let reported = tcx.dcx().span_delayed_bug(span, msg); Ty::new(tcx, Error(reported)) diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 6e635529d96..14d9b0b0350 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -36,7 +36,7 @@ pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{ } impl rustc_middle::mir::interpret::MachineStopType for Zst { - fn diagnostic_message(&self) -> rustc_errors::DiagnosticMessage { + fn diagnostic_message(&self) -> rustc_errors::DiagMessage { self.to_string().into() } diff --git a/compiler/rustc_mir_transform/src/errors.rs b/compiler/rustc_mir_transform/src/errors.rs index f3eff247bc7..80e9172bbe1 100644 --- a/compiler/rustc_mir_transform/src/errors.rs +++ b/compiler/rustc_mir_transform/src/errors.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use rustc_errors::{ - codes::*, Applicability, DecorateLint, Diag, DiagArgValue, DiagCtxt, DiagnosticMessage, + codes::*, Applicability, DecorateLint, Diag, DiagArgValue, DiagCtxt, DiagMessage, EmissionGuarantee, IntoDiagnostic, Level, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; @@ -149,7 +149,7 @@ impl RequiresUnsafeDetail { } } - fn label(&self) -> DiagnosticMessage { + fn label(&self) -> DiagMessage { use UnsafetyViolationDetails::*; match self.violation { CallToUnsafeFunction => fluent::mir_transform_call_to_unsafe_label, @@ -199,7 +199,7 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn { } } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::mir_transform_unsafe_op_in_unsafe_fn } } @@ -224,7 +224,7 @@ impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint

{ diag.span_label(self.span, message); } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { match self.lint_kind { AssertLintKind::ArithmeticOverflow => fluent::mir_transform_arithmetic_overflow, AssertLintKind::UnconditionalPanic => fluent::mir_transform_operation_will_panic, @@ -281,7 +281,7 @@ impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> { diag.arg("post", self.post); } - fn msg(&self) -> rustc_errors::DiagnosticMessage { + fn msg(&self) -> rustc_errors::DiagMessage { fluent::mir_transform_must_not_suspend } } diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 1ea29227e4a..3c8ad27c07c 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, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, - IntoDiagnostic, Level, MultiSpan, + codes::*, Diag, DiagCtxt, DiagMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, + Level, MultiSpan, }; use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; @@ -14,7 +14,7 @@ use crate::parse::ParseSess; pub struct FeatureGateError { pub span: MultiSpan, - pub explain: DiagnosticMessage, + pub explain: DiagMessage, } impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for FeatureGateError { diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index e30e8cd9f62..6af951c1aa7 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, 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, - explain: impl Into, + explain: impl Into, ) -> Diag<'_> { feature_err_issue(sess, feature, span, GateIssue::Language, explain) } @@ -100,7 +100,7 @@ pub fn feature_err_issue( feature: Symbol, span: impl Into, issue: GateIssue, - explain: impl Into, + explain: impl Into, ) -> Diag<'_> { let span = span.into(); @@ -290,7 +290,7 @@ impl ParseSess { lint: &'static Lint, span: impl Into, node_id: NodeId, - msg: impl Into, + msg: impl Into, ) { self.buffered_lints.with_lock(|buffered_lints| { buffered_lints.push(BufferedEarlyLint { @@ -308,7 +308,7 @@ impl ParseSess { lint: &'static Lint, span: impl Into, node_id: NodeId, - msg: impl Into, + msg: impl Into, diagnostic: BuiltinLintDiagnostics, ) { self.buffered_lints.with_lock(|buffered_lints| { diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 9c642b98b01..4f4d8fabb72 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, DiagnosticMessage, ErrorGuaranteed, - FatalAbort, FluentBundle, IntoDiagnostic, LazyFallbackBundle, TerminalUrl, + codes::*, fallback_fluent_bundle, Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, FatalAbort, + FluentBundle, IntoDiagnostic, LazyFallbackBundle, TerminalUrl, }; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; @@ -1419,38 +1419,38 @@ impl EarlyDiagCtxt { #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - pub fn early_note(&self, msg: impl Into) { + pub fn early_note(&self, msg: impl Into) { self.dcx.note(msg) } #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - pub fn early_help(&self, msg: impl Into) { + pub fn early_help(&self, msg: impl Into) { self.dcx.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) -> ErrorGuaranteed { + pub fn early_err(&self, msg: impl Into) -> ErrorGuaranteed { self.dcx.err(msg) } #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - pub fn early_fatal(&self, msg: impl Into) -> ! { + pub fn early_fatal(&self, msg: impl Into) -> ! { self.dcx.fatal(msg) } #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - pub fn early_struct_fatal(&self, msg: impl Into) -> Diag<'_, FatalAbort> { + pub fn early_struct_fatal(&self, msg: impl Into) -> Diag<'_, FatalAbort> { self.dcx.struct_fatal(msg) } #[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::diagnostic_outside_of_impl)] - pub fn early_warn(&self, msg: impl Into) { + pub fn early_warn(&self, msg: impl Into) { self.dcx.warn(msg) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7e31cfc0662..eab3ec77315 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -187,7 +187,7 @@ symbols! { DecorateLint, Default, Deref, - DiagnosticMessage, + DiagMessage, DirBuilder, Display, DoubleEndedIterator, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index de834b8fb64..1241227a5af 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1266,8 +1266,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if has_custom_message { err.note(msg); } else { - err.messages = - vec![(rustc_errors::DiagnosticMessage::from(msg), Style::NoStyle)]; + err.messages = vec![(rustc_errors::DiagMessage::from(msg), Style::NoStyle)]; } let mut file = None; err.span_label( diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index e8b250648bc..64f0e096cd0 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -27,7 +27,7 @@ //! ``` use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{Diag, DiagnosticMessage}; +use rustc_errors::{Diag, DiagMessage}; use rustc_hir::def_id::DefId; use rustc_middle::ty::TyCtxt; pub(crate) use rustc_resolve::rustdoc::main_body_opts; @@ -828,7 +828,7 @@ impl<'tcx> ExtraInfo<'tcx> { ExtraInfo { def_id, sp, tcx } } - fn error_invalid_codeblock_attr(&self, msg: impl Into) { + fn error_invalid_codeblock_attr(&self, msg: impl Into) { if let Some(def_id) = self.def_id.as_local() { self.tcx.node_span_lint( crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, @@ -842,7 +842,7 @@ impl<'tcx> ExtraInfo<'tcx> { fn error_invalid_codeblock_attr_with_help( &self, - msg: impl Into, + msg: impl Into, f: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), ) { if let Some(def_id) = self.def_id.as_local() { @@ -952,7 +952,7 @@ impl<'a, 'tcx> TagIterator<'a, 'tcx> { Self { inner: data.char_indices().peekable(), data, is_in_attribute_block: false, extra } } - fn emit_error(&self, err: impl Into) { + fn emit_error(&self, err: impl Into) { if let Some(extra) = self.extra { extra.error_invalid_codeblock_attr(err); } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 33bdbbe1b94..a5f5fca3d15 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -8,7 +8,7 @@ use rustc_data_structures::{ fx::{FxHashMap, FxHashSet}, intern::Interned, }; -use rustc_errors::{Applicability, Diag, DiagnosticMessage}; +use rustc_errors::{Applicability, Diag, DiagMessage}; use rustc_hir::def::Namespace::*; use rustc_hir::def::{DefKind, Namespace, PerNS}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; @@ -1674,7 +1674,7 @@ impl Suggestion { fn report_diagnostic( tcx: TyCtxt<'_>, lint: &'static Lint, - msg: impl Into + Display, + msg: impl Into + Display, DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>, decorate: impl FnOnce(&mut Diag<'_, ()>, Option, MarkdownLinkRange), ) { @@ -2010,7 +2010,7 @@ fn disambiguator_error( cx: &DocContext<'_>, mut diag_info: DiagnosticInfo<'_>, disambiguator_range: MarkdownLinkRange, - msg: impl Into + Display, + msg: impl Into + Display, ) { diag_info.link_range = disambiguator_range; report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp, _link_range| { diff --git a/src/tools/clippy/tests/ui-internal/disallow_span_lint.rs b/src/tools/clippy/tests/ui-internal/disallow_span_lint.rs index b9b4a07d29d..c5029bbd9a4 100644 --- a/src/tools/clippy/tests/ui-internal/disallow_span_lint.rs +++ b/src/tools/clippy/tests/ui-internal/disallow_span_lint.rs @@ -5,12 +5,17 @@ extern crate rustc_hir; extern crate rustc_lint; extern crate rustc_middle; -use rustc_errors::{DiagnosticMessage, MultiSpan}; +use rustc_errors::{DiagMessage, MultiSpan}; use rustc_hir::hir_id::HirId; use rustc_lint::{Lint, LintContext}; use rustc_middle::ty::TyCtxt; -pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into, msg: impl Into) { +pub fn a( + cx: impl LintContext, + lint: &'static Lint, + span: impl Into, + msg: impl Into) +{ cx.span_lint(lint, span, msg, |_| {}); } @@ -19,7 +24,7 @@ pub fn b( lint: &'static Lint, hir_id: HirId, span: impl Into, - msg: impl Into, + msg: impl Into, ) { tcx.node_span_lint(lint, hir_id, span, msg, |_| {}); } diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index de0ed879b36..4683965159d 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Write}; use std::num::NonZero; -use rustc_errors::{Diag, DiagnosticMessage, Level}; +use rustc_errors::{Diag, DiagMessage, Level}; use rustc_span::{SpanData, Symbol, DUMMY_SP}; use rustc_target::abi::{Align, Size}; @@ -95,7 +95,7 @@ impl fmt::Debug for TerminationInfo { } impl MachineStopType for TerminationInfo { - fn diagnostic_message(&self) -> DiagnosticMessage { + fn diagnostic_message(&self) -> DiagMessage { self.to_string().into() } fn add_args( diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs index 356410f5596..11af9860513 100644 --- a/src/tools/rustfmt/src/parse/session.rs +++ b/src/tools/rustfmt/src/parse/session.rs @@ -44,7 +44,7 @@ impl Translate for SilentEmitter { // subdiagnostics result in a call to this. fn translate_message<'a>( &'a self, - message: &'a rustc_errors::DiagnosticMessage, + message: &'a rustc_errors::DiagMessage, _: &'a rustc_errors::translation::FluentArgs<'_>, ) -> Result, rustc_errors::error::TranslateError<'_>> { rustc_errors::emitter::silent_translate(message) diff --git a/tests/ui-fulldeps/fluent-messages/test.rs b/tests/ui-fulldeps/fluent-messages/test.rs index 2316a533469..cf6747fb37f 100644 --- a/tests/ui-fulldeps/fluent-messages/test.rs +++ b/tests/ui-fulldeps/fluent-messages/test.rs @@ -5,9 +5,9 @@ extern crate rustc_errors; extern crate rustc_fluent_macro; -/// Copy of the relevant `DiagnosticMessage` variant constructed by `fluent_messages` as it -/// expects `crate::DiagnosticMessage` to exist. -pub enum DiagnosticMessage { +/// Copy of the relevant `DiagMessage` variant constructed by `fluent_messages` as it +/// expects `crate::DiagMessage` to exist. +pub enum DiagMessage { FluentIdentifier(std::borrow::Cow<'static, str>, Option>), } diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs index 90bea03ffd5..c7d9d8d88aa 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.rs @@ -19,7 +19,7 @@ extern crate rustc_macros; extern crate rustc_session; extern crate rustc_span; -use rustc_errors::{Applicability, DiagnosticMessage, SubdiagnosticMessage}; +use rustc_errors::{Applicability, DiagMessage, SubdiagnosticMessage}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index f2f42f05481..34c0dc905e5 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -25,7 +25,7 @@ extern crate rustc_middle; use rustc_middle::ty::Ty; extern crate rustc_errors; -use rustc_errors::{Applicability, DiagnosticMessage, ErrCode, MultiSpan, SubdiagnosticMessage}; +use rustc_errors::{Applicability, DiagMessage, ErrCode, MultiSpan, SubdiagnosticMessage}; extern crate rustc_session; diff --git a/tests/ui-fulldeps/session-diagnostic/invalid-variable.rs b/tests/ui-fulldeps/session-diagnostic/invalid-variable.rs index ba529e42e78..c115166f309 100644 --- a/tests/ui-fulldeps/session-diagnostic/invalid-variable.rs +++ b/tests/ui-fulldeps/session-diagnostic/invalid-variable.rs @@ -10,7 +10,7 @@ extern crate rustc_fluent_macro; extern crate rustc_macros; extern crate rustc_errors; use rustc_macros::Diagnostic; -use rustc_errors::{SubdiagnosticMessage, DiagnosticMessage}; +use rustc_errors::{DiagMessage, SubdiagnosticMessage}; extern crate rustc_session; rustc_fluent_macro::fluent_messages! { "./example.ftl" } diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs index 15e3b212d90..788dfa2a4ad 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs @@ -17,7 +17,7 @@ extern crate rustc_macros; extern crate rustc_session; extern crate rustc_span; -use rustc_errors::{Applicability, DiagnosticMessage, SubdiagnosticMessage}; +use rustc_errors::{Applicability, DiagMessage, SubdiagnosticMessage}; use rustc_macros::Subdiagnostic; use rustc_span::Span;