diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index eafbe3462bb54..570449513bf2a 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::{ - codes::*, AddToDiagnostic, Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -41,7 +41,7 @@ pub struct InvalidAbi { pub struct InvalidAbiReason(pub &'static str); impl AddToDiagnostic for InvalidAbiReason { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _: F, diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index f5ce9dedac93c..8921883d94e3a 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -18,7 +18,7 @@ use rustc_parse::validate_attr; use rustc_session::lint::builtin::{ DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY, }; -use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer}; +use rustc_session::lint::{BuiltinLintDiag, LintBuffer}; use rustc_session::Session; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; @@ -750,7 +750,7 @@ impl<'a> AstValidator<'a> { id, span, fluent::ast_passes_extern_without_abi, - BuiltinLintDiagnostics::MissingAbi(span, abi::Abi::FALLBACK), + BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK), ) } } @@ -1408,7 +1408,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { FnCtxt::Foreign => fluent::ast_passes_pattern_in_foreign, _ => fluent::ast_passes_pattern_in_bodiless, }; - let diag = BuiltinLintDiagnostics::PatternsInFnsWithoutBody(span, ident); + let diag = BuiltinLintDiag::PatternsInFnsWithoutBody(span, ident); self.lint_buffer.buffer_lint_with_diagnostic( PATTERNS_IN_FNS_WITHOUT_BODY, id, @@ -1491,7 +1491,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { item.id, err.span, fluent::ast_passes_deprecated_where_clause_location, - BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(sugg), + BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg), ); } diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 19eed07091169..e225401ea379d 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -2,7 +2,7 @@ use rustc_ast::ParamKindOrd; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, Diag, EmissionGuarantee, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -374,7 +374,7 @@ pub struct EmptyLabelManySpans(pub Vec); // The derive for `Vec` does multiple calls to `span_label`, adding commas between each impl AddToDiagnostic for EmptyLabelManySpans { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _: F, @@ -743,7 +743,7 @@ pub struct StableFeature { } impl AddToDiagnostic for StableFeature { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _: F, diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index dd64ae6614fb3..eb25b910c7baf 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -8,7 +8,7 @@ use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; use rustc_macros::HashStable_Generic; use rustc_session::config::ExpectedValues; use rustc_session::lint::builtin::UNEXPECTED_CFGS; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_session::parse::feature_err; use rustc_session::{RustcVersion, Session}; use rustc_span::hygiene::Transparency; @@ -535,7 +535,7 @@ pub fn cfg_matches( } else { format!("unexpected `cfg` condition value: (none)") }, - BuiltinLintDiagnostics::UnexpectedCfgValue( + BuiltinLintDiag::UnexpectedCfgValue( (cfg.name, cfg.name_span), cfg.value.map(|v| (v, cfg.value_span.unwrap())), ), @@ -547,7 +547,7 @@ pub fn cfg_matches( cfg.span, lint_node_id, format!("unexpected `cfg` condition name: `{}`", cfg.name), - BuiltinLintDiagnostics::UnexpectedCfgName( + BuiltinLintDiag::UnexpectedCfgName( (cfg.name, cfg.name_span), cfg.value.map(|v| (v, cfg.value_span.unwrap())), ), diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 0adab6c4322eb..3cb3e30daa72e 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1603,9 +1603,10 @@ impl<'a> TraitDef<'a> { // Once use of `icu4x-0.9.0` has dropped sufficiently, this // exception should be removed. let is_simple_path = |ty: &P, sym| { - if let TyKind::Path(None, ast::Path { segments, .. }) = &ty.kind && - let [seg] = segments.as_slice() && - seg.ident.name == sym && seg.args.is_none() + if let TyKind::Path(None, ast::Path { segments, .. }) = &ty.kind + && let [seg] = segments.as_slice() + && seg.ident.name == sym + && seg.args.is_none() { true } else { @@ -1613,8 +1614,8 @@ impl<'a> TraitDef<'a> { } }; - let exception = if let TyKind::Slice(ty) = &struct_field.ty.kind && - is_simple_path(ty, sym::u8) + let exception = if let TyKind::Slice(ty) = &struct_field.ty.kind + && is_simple_path(ty, sym::u8) { Some("byte") } else if is_simple_path(&struct_field.ty, sym::str) { @@ -1631,7 +1632,7 @@ impl<'a> TraitDef<'a> { format!( "{ty} slice in a packed struct that derives a built-in trait" ), - rustc_lint_defs::BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive + rustc_lint_defs::BuiltinLintDiag::ByteSliceInPackedStructWithDerive, ); } else { // Wrap the expression in `{...}`, causing a copy. diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index 6546a35734c63..a2570e587130e 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -1,6 +1,6 @@ use rustc_errors::{ codes::*, AddToDiagnostic, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, MultiSpan, - SingleLabelManySpans, SubdiagnosticMessageOp, + SingleLabelManySpans, SubdiagMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -590,7 +590,7 @@ pub(crate) struct FormatUnusedArg { // Allow the singular form to be a subdiagnostic of the multiple-unused // form of diagnostic. impl AddToDiagnostic for FormatUnusedArg { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, f: F, diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 0ce9d7ead8217..385c90ff14b2d 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -16,7 +16,7 @@ use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{BytePos, ErrorGuaranteed, InnerSpan, Span}; use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY; -use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, LintId}; +use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, LintId}; // The format_args!() macro is expanded in three steps: // 1. First, `parse_args` will parse the `(literal, arg, arg, name=arg, name=arg)` syntax, @@ -553,7 +553,7 @@ fn make_format_args( msg: format!("named argument `{}` is not used by name", arg_name.name).into(), node_id: rustc_ast::CRATE_NODE_ID, lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY), - diagnostic: BuiltinLintDiagnostics::NamedArgumentUsedPositionally { + diagnostic: BuiltinLintDiag::NamedArgumentUsedPositionally { position_sp_to_replace, position_sp_for_msg, named_arg_sp: arg_name.span, diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 60865d06ab998..bbb04652119fe 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}; @@ -1004,9 +1004,9 @@ pub(crate) enum Message { /// process another codegen unit. pub struct CguMessage; -// A cut-down version of `rustc_errors::Diagnostic` that impls `Send`, which +// A cut-down version of `rustc_errors::DiagInner` that impls `Send`, which // can be used to send diagnostics from codegen threads to the main thread. -// It's missing the following fields from `rustc_errors::Diagnostic`. +// It's missing the following fields from `rustc_errors::DiagInner`. // - `span`: it doesn't impl `Send`. // - `suggestions`: it doesn't impl `Send`, and isn't used for codegen // diagnostics. @@ -1015,18 +1015,18 @@ 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, } -// A cut-down version of `rustc_errors::SubDiagnostic` that impls `Send`. It's -// missing the following fields from `rustc_errors::SubDiagnostic`. +// A cut-down version of `rustc_errors::Subdiag` that impls `Send`. It's +// missing the following fields from `rustc_errors::Subdiag`. // - `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 62bc68b1a20e9..e5b4fc3a574f0 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 c59e0a0df9f7b..afabd9689c694 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 f91b6655f6399..ad82c2d96e7a7 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -253,11 +253,11 @@ 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 { +#[rustc_diagnostic_item = "SubdiagMessage"] +pub enum SubdiagMessage { /// Non-translatable diagnostic message. Str(Cow<'static, str>), /// Translatable message which has already been translated eagerly. @@ -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. @@ -278,19 +278,19 @@ pub enum SubdiagnosticMessage { FluentAttr(FluentId), } -impl From for SubdiagnosticMessage { +impl From for SubdiagMessage { fn from(s: String) -> Self { - SubdiagnosticMessage::Str(Cow::Owned(s)) + SubdiagMessage::Str(Cow::Owned(s)) } } -impl From<&'static str> for SubdiagnosticMessage { +impl From<&'static str> for SubdiagMessage { fn from(s: &'static str) -> Self { - SubdiagnosticMessage::Str(Cow::Borrowed(s)) + SubdiagMessage::Str(Cow::Borrowed(s)) } } -impl From> for SubdiagnosticMessage { +impl From> for SubdiagMessage { fn from(s: Cow<'static, str>) -> Self { - SubdiagnosticMessage::Str(s) + SubdiagMessage::Str(s) } } @@ -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,80 @@ pub enum DiagnosticMessage { FluentIdentifier(FluentId, Option), } -impl DiagnosticMessage { - /// Given a `SubdiagnosticMessage` which may contain a Fluent attribute, create a new - /// `DiagnosticMessage` that combines that attribute with the Fluent identifier of `self`. +impl DiagMessage { + /// Given a `SubdiagMessage` which may contain a Fluent attribute, create a new + /// `DiagMessage` that combines that attribute with the Fluent identifier of `self`. /// - /// - If the `SubdiagnosticMessage` is non-translatable then return the message as a - /// `DiagnosticMessage`. + /// - If the `SubdiagMessage` is non-translatable then return the message as a `DiagMessage`. /// - If `self` is non-translatable then return `self`'s message. - pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self { + pub fn with_subdiagnostic_message(&self, sub: SubdiagMessage) -> Self { let attr = match sub { - SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s), - SubdiagnosticMessage::Translated(s) => return DiagnosticMessage::Translated(s), - SubdiagnosticMessage::FluentIdentifier(id) => { - return DiagnosticMessage::FluentIdentifier(id, None); + SubdiagMessage::Str(s) => return DiagMessage::Str(s), + SubdiagMessage::Translated(s) => return DiagMessage::Translated(s), + SubdiagMessage::FluentIdentifier(id) => { + return DiagMessage::FluentIdentifier(id, None); } - SubdiagnosticMessage::FluentAttr(attr) => attr, + SubdiagMessage::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` +/// the subdiagnostic functions (e.g. `span_label`) take a `SubdiagMessage` and the +/// 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 { - fn into(self) -> SubdiagnosticMessage { +impl Into for DiagMessage { + fn into(self) -> SubdiagMessage { match self { - DiagnosticMessage::Str(s) => SubdiagnosticMessage::Str(s), - DiagnosticMessage::Translated(s) => SubdiagnosticMessage::Translated(s), - DiagnosticMessage::FluentIdentifier(id, None) => { - SubdiagnosticMessage::FluentIdentifier(id) - } + DiagMessage::Str(s) => SubdiagMessage::Str(s), + DiagMessage::Translated(s) => SubdiagMessage::Translated(s), + DiagMessage::FluentIdentifier(id, None) => SubdiagMessage::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)) => SubdiagMessage::FluentAttr(attr), } } } @@ -412,7 +407,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 +421,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 +439,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 +482,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 e6668769b955e..b71b93cc67c16 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 1c820bfd01f91..5390dda9b21ad 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, SubdiagMessage, Substitution, SubstitutionPart, SuggestionStyle, }; use rustc_data_structures::fx::FxIndexMap; use rustc_error_messages::fluent_value_from_str_list_sep_by_and; @@ -182,15 +182,14 @@ where /// Add a subdiagnostic to an existing diagnostic where `f` is invoked on every message used /// (to optionally perform eager translation). - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, f: F, ); } -pub trait SubdiagnosticMessageOp = - Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage; +pub trait SubdiagMessageOp = Fn(&mut Diag<'_, G>, SubdiagMessage) -> SubdiagMessage; /// Trait implemented by lint types. This should not be implemented manually. Instead, use /// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic]. @@ -199,7 +198,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 +290,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 +311,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, @@ -396,8 +395,8 @@ impl DiagInner { // See comment on `Diag::subdiagnostic_message_to_diagnostic_message`. pub(crate) fn subdiagnostic_message_to_diagnostic_message( &self, - attr: impl Into, - ) -> DiagnosticMessage { + attr: impl Into, + ) -> DiagMessage { let msg = self.messages.iter().map(|(msg, _)| msg).next().expect("diagnostic with no messages"); msg.with_subdiagnostic_message(attr.into()) @@ -406,7 +405,7 @@ impl DiagInner { pub(crate) fn sub( &mut self, level: Level, - message: impl Into, + message: impl Into, span: MultiSpan, ) { let sub = Subdiag { @@ -429,7 +428,7 @@ impl DiagInner { &self, ) -> ( &Level, - &[(DiagnosticMessage, Style)], + &[(DiagMessage, Style)], &Option, &MultiSpan, &[Subdiag], @@ -472,7 +471,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 +577,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: impl Into) -> Self { Self::new_diagnostic(dcx, DiagInner::new(level, message)) } @@ -623,7 +622,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// ["primary span"][`MultiSpan`]; only the `Span` supplied when creating the diagnostic is /// primary. #[rustc_lint_diagnostics] - pub fn span_label(&mut self, span: Span, label: impl Into) -> &mut Self { + pub fn span_label(&mut self, span: Span, label: impl Into) -> &mut Self { let msg = self.subdiagnostic_message_to_diagnostic_message(label); self.span.push_span_label(span, msg); self @@ -718,7 +717,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_note, /// Add a note attached to this diagnostic. #[rustc_lint_diagnostics] - pub fn note(&mut self, msg: impl Into) -> &mut Self { + pub fn note(&mut self, msg: impl Into) -> &mut Self { self.sub(Level::Note, msg, MultiSpan::new()); self } } @@ -729,7 +728,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { } /// This is like [`Diag::note()`], but it's only printed once. - pub fn note_once(&mut self, msg: impl Into) -> &mut Self { + pub fn note_once(&mut self, msg: impl Into) -> &mut Self { self.sub(Level::OnceNote, msg, MultiSpan::new()); self } @@ -741,7 +740,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_note( &mut self, sp: impl Into, - msg: impl Into, + msg: impl Into, ) -> &mut Self { self.sub(Level::Note, msg, sp.into()); self @@ -752,7 +751,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_note_once>( &mut self, sp: S, - msg: impl Into, + msg: impl Into, ) -> &mut Self { self.sub(Level::OnceNote, msg, sp.into()); self @@ -761,7 +760,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_warn, /// Add a warning attached to this diagnostic. #[rustc_lint_diagnostics] - pub fn warn(&mut self, msg: impl Into) -> &mut Self { + pub fn warn(&mut self, msg: impl Into) -> &mut Self { self.sub(Level::Warning, msg, MultiSpan::new()); self } } @@ -772,7 +771,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_warn>( &mut self, sp: S, - msg: impl Into, + msg: impl Into, ) -> &mut Self { self.sub(Level::Warning, msg, sp.into()); self @@ -781,13 +780,13 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { with_fn! { with_help, /// Add a help message attached to this diagnostic. #[rustc_lint_diagnostics] - pub fn help(&mut self, msg: impl Into) -> &mut Self { + pub fn help(&mut self, msg: impl Into) -> &mut Self { self.sub(Level::Help, msg, MultiSpan::new()); self } } /// This is like [`Diag::help()`], but it's only printed once. - pub fn help_once(&mut self, msg: impl Into) -> &mut Self { + pub fn help_once(&mut self, msg: impl Into) -> &mut Self { self.sub(Level::OnceHelp, msg, MultiSpan::new()); self } @@ -804,7 +803,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_help>( &mut self, sp: S, - msg: impl Into, + msg: impl Into, ) -> &mut Self { self.sub(Level::Help, msg, sp.into()); self @@ -841,7 +840,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// In other words, multiple changes need to be applied as part of this suggestion. pub fn multipart_suggestion( &mut self, - msg: impl Into, + msg: impl Into, suggestion: Vec<(Span, String)>, applicability: Applicability, ) -> &mut Self { @@ -857,7 +856,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// In other words, multiple changes need to be applied as part of this suggestion. pub fn multipart_suggestion_verbose( &mut self, - msg: impl Into, + msg: impl Into, suggestion: Vec<(Span, String)>, applicability: Applicability, ) -> &mut Self { @@ -872,7 +871,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`]. pub fn multipart_suggestion_with_style( &mut self, - msg: impl Into, + msg: impl Into, mut suggestion: Vec<(Span, String)>, applicability: Applicability, style: SuggestionStyle, @@ -914,7 +913,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// improve understandability. pub fn tool_only_multipart_suggestion( &mut self, - msg: impl Into, + msg: impl Into, suggestion: Vec<(Span, String)>, applicability: Applicability, ) -> &mut Self { @@ -947,7 +946,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -965,7 +964,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_with_style( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestion: impl ToString, applicability: Applicability, style: SuggestionStyle, @@ -990,7 +989,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_verbose( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1010,7 +1009,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestions( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestions: impl IntoIterator, applicability: Applicability, ) -> &mut Self { @@ -1026,7 +1025,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestions_with_style( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestions: impl IntoIterator, applicability: Applicability, style: SuggestionStyle, @@ -1055,7 +1054,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// See also [`Diag::multipart_suggestion()`]. pub fn multipart_suggestions( &mut self, - msg: impl Into, + msg: impl Into, suggestions: impl IntoIterator>, applicability: Applicability, ) -> &mut Self { @@ -1102,7 +1101,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_short( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1125,7 +1124,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn span_suggestion_hidden( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1148,7 +1147,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { pub fn tool_only_span_suggestion( &mut self, sp: Span, - msg: impl Into, + msg: impl Into, suggestion: impl ToString, applicability: Applicability, ) -> &mut Self { @@ -1203,7 +1202,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 +1218,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 `SubdiagMessage` 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 { + attr: impl Into, + ) -> DiagMessage { self.deref().subdiagnostic_message_to_diagnostic_message(attr) } @@ -1233,7 +1232,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { /// public methods above. /// /// Used by `proc_macro_server` for implementing `server::Diagnostic`. - pub fn sub(&mut self, level: Level, message: impl Into, span: MultiSpan) { + pub fn sub(&mut self, level: Level, message: impl Into, span: MultiSpan) { self.deref_mut().sub(level, message, span); } @@ -1338,7 +1337,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/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 70c8d9718681d..839bd65e4a639 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -2,7 +2,7 @@ use crate::diagnostic::DiagLocation; use crate::{fluent_generated as fluent, AddToDiagnostic}; use crate::{ Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, ErrCode, IntoDiagnostic, IntoDiagnosticArg, - Level, SubdiagnosticMessageOp, + Level, SubdiagMessageOp, }; use rustc_ast as ast; use rustc_ast_pretty::pprust; @@ -298,7 +298,7 @@ pub struct SingleLabelManySpans { pub label: &'static str, } impl AddToDiagnostic for SingleLabelManySpans { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _: F, diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 5637c05d04c69..293d8f01e673a 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 6b1ccbc5f7c40..0a6d66f52dad0 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -39,7 +39,7 @@ pub use codes::*; pub use diagnostic::{ AddToDiagnostic, BugAbort, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, DiagInner, DiagStyledString, EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg, - StringPart, Subdiag, SubdiagnosticMessageOp, + StringPart, Subdiag, SubdiagMessageOp, }; pub use diagnostic_impls::{ DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime, @@ -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, SubdiagMessage, }; 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 @@ -631,12 +631,12 @@ impl DiagCtxt { } } - /// Translate `message` eagerly with `args` to `SubdiagnosticMessage::Eager`. + /// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`. pub fn eagerly_translate<'a>( &self, - message: DiagnosticMessage, + message: DiagMessage, args: impl Iterator>, - ) -> SubdiagnosticMessage { + ) -> SubdiagMessage { let inner = self.inner.borrow(); inner.eagerly_translate(message, args) } @@ -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) @@ -1553,19 +1553,19 @@ impl DiagCtxtInner { self.has_errors().or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied()) } - /// Translate `message` eagerly with `args` to `SubdiagnosticMessage::Eager`. + /// Translate `message` eagerly with `args` to `SubdiagMessage::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))) + ) -> SubdiagMessage { + SubdiagMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args))) } /// 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); @@ -1575,8 +1575,8 @@ impl DiagCtxtInner { fn eagerly_translate_for_subdiag( &self, diag: &DiagInner, - msg: impl Into, - ) -> SubdiagnosticMessage { + msg: impl Into, + ) -> SubdiagMessage { let msg = diag.subdiagnostic_message_to_diagnostic_message(msg); self.eagerly_translate(msg, diag.args.iter()) } diff --git a/compiler/rustc_errors/src/tests.rs b/compiler/rustc_errors/src/tests.rs index 79a2af7f38fd7..50d58aec36a89 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 1f98ba4c3b974..bf0026568ce23 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/base.rs b/compiler/rustc_expand/src/base.rs index 6d205a82675c0..550ed078549e2 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -16,7 +16,7 @@ use rustc_data_structures::sync::{self, Lrc}; use rustc_errors::{Applicability, Diag, DiagCtxt, ErrorGuaranteed, PResult}; use rustc_feature::Features; use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT; -use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, RegisteredTools}; +use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, RegisteredTools}; use rustc_parse::{parser, MACRO_ARGUMENTS}; use rustc_session::config::CollapseMacroDebuginfo; use rustc_session::errors::report_lit_error; @@ -1488,7 +1488,7 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool { item.ident.span, ast::CRATE_NODE_ID, "using an old version of `rental`", - BuiltinLintDiagnostics::ProcMacroBackCompat( + BuiltinLintDiag::ProcMacroBackCompat( "older versions of the `rental` crate will stop compiling in future versions of Rust; \ please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string() ) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 8a01704b766eb..9d6daf1f47fbe 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -30,7 +30,7 @@ use rustc_parse::parser::{ }; use rustc_parse::validate_attr; use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS}; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_session::parse::feature_err; use rustc_session::{Limit, Session}; use rustc_span::symbol::{sym, Ident}; @@ -1711,7 +1711,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { current_span, self.cx.current_expansion.lint_node_id, "unused doc comment", - BuiltinLintDiagnostics::UnusedDocComment(attr.span), + BuiltinLintDiag::UnusedDocComment(attr.span), ); } else if rustc_attr::is_builtin_attr(attr) { let attr_name = attr.ident().unwrap().name; @@ -1723,7 +1723,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { attr.span, self.cx.current_expansion.lint_node_id, format!("unused attribute `{attr_name}`"), - BuiltinLintDiagnostics::UnusedBuiltinAttribute { + BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name: pprust::path_to_string(&call.path), invoc_span: call.path.span, diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index d8b8a0fa96ad8..15193298ccaa2 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 19405dcfd6cb2..dce8e0c36edf7 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/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index c8631d9681053..8903fc45defbc 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -21,7 +21,7 @@ use rustc_feature::Features; use rustc_lint_defs::builtin::{ RUST_2021_INCOMPATIBLE_OR_PATTERNS, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, }; -use rustc_lint_defs::BuiltinLintDiagnostics; +use rustc_lint_defs::BuiltinLintDiag; use rustc_parse::parser::{Parser, Recovery}; use rustc_session::parse::ParseSess; use rustc_session::Session; @@ -83,7 +83,7 @@ impl<'a> ParserAnyMacro<'a> { parser.token.span, lint_node_id, "trailing semicolon in macro used in expression position", - BuiltinLintDiagnostics::TrailingMacro(is_trailing_mac, macro_ident), + BuiltinLintDiag::TrailingMacro(is_trailing_mac, macro_ident), ); } parser.bump(); @@ -1154,7 +1154,7 @@ fn check_matcher_core<'tt>( span, ast::CRATE_NODE_ID, "the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro", - BuiltinLintDiagnostics::OrPatternsBackCompat(span, suggestion), + BuiltinLintDiag::OrPatternsBackCompat(span, suggestion), ); } match is_in_follow(next_token, kind) { diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index efe35c252d84a..32a083a72f013 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 520a64aaf5e23..214b6587af3b0 100644 --- a/compiler/rustc_fluent_macro/src/fluent.rs +++ b/compiler/rustc_fluent_macro/src/fluent.rs @@ -54,20 +54,20 @@ fn finish(body: TokenStream, resource: TokenStream) -> proc_macro::TokenStream { /// identifiers for different subdiagnostic kinds. pub mod _subdiag { /// Default for `#[help]` - pub const help: rustc_errors::SubdiagnosticMessage = - rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("help")); + pub const help: rustc_errors::SubdiagMessage = + rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("help")); /// Default for `#[note]` - pub const note: rustc_errors::SubdiagnosticMessage = - rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("note")); + pub const note: rustc_errors::SubdiagMessage = + rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("note")); /// Default for `#[warn]` - pub const warn: rustc_errors::SubdiagnosticMessage = - rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("warn")); + pub const warn: rustc_errors::SubdiagMessage = + rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("warn")); /// Default for `#[label]` - pub const label: rustc_errors::SubdiagnosticMessage = - rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("label")); + pub const label: rustc_errors::SubdiagMessage = + rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("label")); /// Default for `#[suggestion]` - pub const suggestion: rustc_errors::SubdiagnosticMessage = - rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion")); + pub const suggestion: rustc_errors::SubdiagMessage = + rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion")); } } } @@ -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 { @@ -272,8 +275,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok ); constants.extend(quote! { #[doc = #msg] - pub const #snake_name: rustc_errors::SubdiagnosticMessage = - rustc_errors::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed(#attr_name)); + pub const #snake_name: rustc_errors::SubdiagMessage = + rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed(#attr_name)); }); } diff --git a/compiler/rustc_fluent_macro/src/lib.rs b/compiler/rustc_fluent_macro/src/lib.rs index e3784409af8fd..2303785f94e69 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/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index ce4c4609bc85a..63afa4f7e82d2 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -3,7 +3,7 @@ use crate::astconv::{ errors::prohibit_assoc_ty_binding, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition, }; -use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs}; +use crate::structured_errors::{GenericArgsInfo, StructuredDiag, WrongNumberOfGenericArgs}; use rustc_ast::ast::ParamKindOrd; use rustc_errors::{ codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan, diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 9d8eb6ad60b31..64137f298d649 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_hir_analysis/src/structured_errors.rs b/compiler/rustc_hir_analysis/src/structured_errors.rs index 9064ba8693ef5..5abfd25dd95df 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors.rs @@ -9,7 +9,7 @@ pub use self::{ use rustc_errors::{Diag, ErrCode}; use rustc_session::Session; -pub trait StructuredDiagnostic<'tcx> { +pub trait StructuredDiag<'tcx> { fn session(&self) -> &Session; fn code(&self) -> ErrCode; diff --git a/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs b/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs index 921cf37155a2e..0e78acbeae2d4 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/missing_cast_for_variadic_arg.rs @@ -1,4 +1,4 @@ -use crate::{errors, structured_errors::StructuredDiagnostic}; +use crate::{errors, structured_errors::StructuredDiag}; use rustc_errors::{codes::*, Diag}; use rustc_middle::ty::{Ty, TypeVisitableExt}; use rustc_session::Session; @@ -11,7 +11,7 @@ pub struct MissingCastForVariadicArg<'tcx, 's> { pub cast_ty: &'s str, } -impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> { +impl<'tcx> StructuredDiag<'tcx> for MissingCastForVariadicArg<'tcx, '_> { fn session(&self) -> &Session { self.sess } diff --git a/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs b/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs index 1af5e6a9dfc4b..9e871ff9af01b 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/sized_unsized_cast.rs @@ -1,4 +1,4 @@ -use crate::{errors, structured_errors::StructuredDiagnostic}; +use crate::{errors, structured_errors::StructuredDiag}; use rustc_errors::{codes::*, Diag}; use rustc_middle::ty::{Ty, TypeVisitableExt}; use rustc_session::Session; @@ -11,7 +11,7 @@ pub struct SizedUnsizedCast<'tcx> { pub cast_ty: String, } -impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> { +impl<'tcx> StructuredDiag<'tcx> for SizedUnsizedCast<'tcx> { fn session(&self) -> &Session { self.sess } diff --git a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs index 6f4695ec92005..0f5ba26337a15 100644 --- a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs @@ -1,4 +1,4 @@ -use crate::structured_errors::StructuredDiagnostic; +use crate::structured_errors::StructuredDiag; use rustc_errors::{codes::*, pluralize, Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt}; @@ -1097,7 +1097,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } -impl<'tcx> StructuredDiagnostic<'tcx> for WrongNumberOfGenericArgs<'_, 'tcx> { +impl<'tcx> StructuredDiag<'tcx> for WrongNumberOfGenericArgs<'_, 'tcx> { fn session(&self) -> &Session { self.tcx.sess } diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 84d042da138f8..b8d1eaee81260 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -483,9 +483,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { err.emit(); } CastError::SizedUnsizedCast => { - use rustc_hir_analysis::structured_errors::{ - SizedUnsizedCast, StructuredDiagnostic, - }; + use rustc_hir_analysis::structured_errors::{SizedUnsizedCast, StructuredDiag}; SizedUnsizedCast { sess: fcx.tcx.sess, diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index 1d324f128f230..502b9ba6451d3 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use crate::fluent_generated as fluent; use rustc_errors::{ codes::*, AddToDiagnostic, Applicability, Diag, DiagArgValue, EmissionGuarantee, - IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp, + IntoDiagnosticArg, MultiSpan, SubdiagMessageOp, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; @@ -195,7 +195,7 @@ pub struct TypeMismatchFruTypo { } impl AddToDiagnostic for TypeMismatchFruTypo { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -374,7 +374,7 @@ pub struct RemoveSemiForCoerce { } impl AddToDiagnostic for RemoveSemiForCoerce { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -550,7 +550,7 @@ pub enum CastUnknownPointerSub { } impl rustc_errors::AddToDiagnostic for CastUnknownPointerSub { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, f: F, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index fc674520295fe..a08582a67d94c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -27,7 +27,7 @@ use rustc_hir::{ExprKind, Node, QPath}; use rustc_hir_analysis::astconv::AstConv; use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt; use rustc_hir_analysis::check::potentially_plural_count; -use rustc_hir_analysis::structured_errors::StructuredDiagnostic; +use rustc_hir_analysis::structured_errors::StructuredDiag; use rustc_index::IndexVec; use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 441558da60ac3..3b26a791f6577 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -11,7 +11,7 @@ pub use self::suggest::SelfSource; pub use self::MethodError::*; use crate::FnCtxt; -use rustc_errors::{Applicability, Diag, SubdiagnosticMessage}; +use rustc_errors::{Applicability, Diag, SubdiagMessage}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace}; use rustc_hir::def_id::DefId; @@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn suggest_method_call( &self, err: &mut Diag<'_>, - msg: impl Into + std::fmt::Debug, + msg: impl Into + std::fmt::Debug, method_name: Ident, self_ty: Ty<'tcx>, call_expr: &hir::Expr<'tcx>, diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index cecc52c8326ef..af09ac2de960c 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -1,7 +1,7 @@ use hir::GenericParamKind; use rustc_errors::{ - codes::*, AddToDiagnostic, Applicability, Diag, DiagStyledString, DiagnosticMessage, - EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp, + codes::*, AddToDiagnostic, Applicability, Diag, DiagMessage, DiagStyledString, + EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagMessageOp, }; use rustc_hir as hir; use rustc_hir::FnRetTy; @@ -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, }, @@ -225,12 +225,12 @@ pub enum RegionOriginNote<'a> { } impl AddToDiagnostic for RegionOriginNote<'_> { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, 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); @@ -290,7 +290,7 @@ pub enum LifetimeMismatchLabels { } impl AddToDiagnostic for LifetimeMismatchLabels { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -338,7 +338,7 @@ pub struct AddLifetimeParamsSuggestion<'a> { } impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -440,7 +440,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq { } impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( mut self, diag: &mut Diag<'_, G>, _f: F, @@ -759,14 +759,14 @@ pub struct ConsiderBorrowingParamHelp { } impl AddToDiagnostic for ConsiderBorrowingParamHelp { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, f: F, ) { 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()); @@ -804,7 +804,7 @@ pub struct DynTraitConstraintSuggestion { } impl AddToDiagnostic for DynTraitConstraintSuggestion { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, f: F, @@ -851,7 +851,7 @@ pub struct ReqIntroducedLocations { } impl AddToDiagnostic for ReqIntroducedLocations { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( mut self, diag: &mut Diag<'_, G>, f: F, @@ -874,7 +874,7 @@ pub struct MoreTargeted { } impl AddToDiagnostic for MoreTargeted { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -1297,7 +1297,7 @@ pub struct SuggestTuplePatternMany { } impl AddToDiagnostic for SuggestTuplePatternMany { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, f: F, diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index bbcb613b3e4ae..7bb71d47031ab 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -1,8 +1,6 @@ use crate::fluent_generated as fluent; use crate::infer::error_reporting::nice_region_error::find_anon_type; -use rustc_errors::{ - AddToDiagnostic, Diag, EmissionGuarantee, IntoDiagnosticArg, SubdiagnosticMessageOp, -}; +use rustc_errors::{AddToDiagnostic, Diag, EmissionGuarantee, IntoDiagnosticArg, SubdiagMessageOp}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::{symbol::kw, Span}; @@ -162,7 +160,7 @@ impl RegionExplanation<'_> { } impl AddToDiagnostic for RegionExplanation<'_> { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, f: F, diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 7572805f66122..bf3beb677aa6d 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -9,7 +9,7 @@ use rustc_parse::validate_attr; use rustc_session as session; use rustc_session::config::{self, Cfg, CrateType, OutFileName, OutputFilenames, OutputTypes}; use rustc_session::filesearch::sysroot_candidates; -use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer}; +use rustc_session::lint::{self, BuiltinLintDiag, LintBuffer}; use rustc_session::{filesearch, output, Session}; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; @@ -345,7 +345,7 @@ pub(crate) fn check_attr_crate_type( ast::CRATE_NODE_ID, span, "invalid `crate_type` value", - BuiltinLintDiagnostics::UnknownCrateTypes( + BuiltinLintDiag::UnknownCrateTypes( span, "did you mean".to_string(), format!("\"{candidate}\""), diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 65a0ce96a64bd..5f0af6aee6ace 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -58,7 +58,7 @@ use rustc_middle::ty::GenericArgKind; use rustc_middle::ty::ToPredicate; use rustc_middle::ty::TypeVisitableExt; use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef}; -use rustc_session::lint::{BuiltinLintDiagnostics, FutureIncompatibilityReason}; +use rustc_session::lint::{BuiltinLintDiag, FutureIncompatibilityReason}; use rustc_span::edition::Edition; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident, Symbol}; @@ -2831,7 +2831,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels { Some(target_spans), fluent::lint_builtin_asm_labels, |_| {}, - BuiltinLintDiagnostics::NamedAsmLabel( + BuiltinLintDiag::NamedAsmLabel( "only local labels of the form `:` should be used in inline asm" .to_string(), ), diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index ab76da36ee314..f043a312c719c 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; @@ -31,7 +31,7 @@ use rustc_middle::middle::privacy::EffectiveVisibilities; use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::print::{with_no_trimmed_paths, PrintError}; use rustc_middle::ty::{self, print::Printer, GenericArg, RegisteredTools, Ty, TyCtxt}; -use rustc_session::lint::{BuiltinLintDiagnostics, LintExpectationId}; +use rustc_session::lint::{BuiltinLintDiag, LintExpectationId}; use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId}; use rustc_session::{LintStoreMarker, Session}; use rustc_span::edit_distance::find_best_match_for_names; @@ -536,9 +536,9 @@ 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, + diagnostic: BuiltinLintDiag, ) { // We first generate a blank diagnostic. self.opt_span_lint(lint, span, msg, |db| { @@ -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/context/diagnostics.rs b/compiler/rustc_lint/src/context/diagnostics.rs index ad1808b5f803d..a0aa252bcdf2f 100644 --- a/compiler/rustc_lint/src/context/diagnostics.rs +++ b/compiler/rustc_lint/src/context/diagnostics.rs @@ -6,15 +6,15 @@ use rustc_errors::{add_elided_lifetime_in_path_suggestion, Diag}; use rustc_errors::{Applicability, SuggestionStyle}; use rustc_middle::middle::stability; use rustc_session::config::ExpectedValues; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_session::Session; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Symbol}; use rustc_span::BytePos; -pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: &mut Diag<'_, ()>) { +pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) { match diagnostic { - BuiltinLintDiagnostics::UnicodeTextFlow(span, content) => { + BuiltinLintDiag::UnicodeTextFlow(span, content) => { let spans: Vec<_> = content .char_indices() .filter_map(|(i, c)| { @@ -51,8 +51,8 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: ); } } - BuiltinLintDiagnostics::Normal => (), - BuiltinLintDiagnostics::AbsPathWithModule(span) => { + BuiltinLintDiag::Normal => (), + BuiltinLintDiag::AbsPathWithModule(span) => { let (sugg, app) = match sess.source_map().span_to_snippet(span) { Ok(ref s) => { // FIXME(Manishearth) ideally the emitting code @@ -65,21 +65,16 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: }; diag.span_suggestion(span, "use `crate`", sugg, app); } - BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback(span) => { + BuiltinLintDiag::ProcMacroDeriveResolutionFallback(span) => { diag.span_label( span, "names from parent modules are not accessible without an explicit import", ); } - BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => { + BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => { diag.span_note(span_def, "the macro is defined here"); } - BuiltinLintDiagnostics::ElidedLifetimesInPaths( - n, - path_span, - incl_angl_brckt, - insertion_span, - ) => { + BuiltinLintDiag::ElidedLifetimesInPaths(n, path_span, incl_angl_brckt, insertion_span) => { add_elided_lifetime_in_path_suggestion( sess.source_map(), diag, @@ -89,10 +84,10 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: insertion_span, ); } - BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => { + BuiltinLintDiag::UnknownCrateTypes(span, note, sugg) => { diag.span_suggestion(span, note, sugg, Applicability::MaybeIncorrect); } - BuiltinLintDiagnostics::UnusedImports(message, replaces, in_test_module) => { + BuiltinLintDiag::UnusedImports(message, replaces, in_test_module) => { if !replaces.is_empty() { diag.tool_only_multipart_suggestion( message, @@ -108,21 +103,21 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: ); } } - BuiltinLintDiagnostics::RedundantImport(spans, ident) => { + BuiltinLintDiag::RedundantImport(spans, ident) => { for (span, is_imported) in spans { let introduced = if is_imported { "imported" } else { "defined" }; diag.span_label(span, format!("the item `{ident}` is already {introduced} here")); } } - BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => { + BuiltinLintDiag::DeprecatedMacro(suggestion, span) => { stability::deprecation_suggestion(diag, "macro", suggestion, span) } - BuiltinLintDiagnostics::UnusedDocComment(span) => { + BuiltinLintDiag::UnusedDocComment(span) => { diag.span_label(span, "rustdoc does not generate documentation for macro invocations"); diag.help("to document an item produced by a macro, \ the macro must produce the documentation as part of its expansion"); } - BuiltinLintDiagnostics::PatternsInFnsWithoutBody(span, ident) => { + BuiltinLintDiag::PatternsInFnsWithoutBody(span, ident) => { diag.span_suggestion( span, "remove `mut` from the parameter", @@ -130,17 +125,17 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::MissingAbi(span, default_abi) => { + BuiltinLintDiag::MissingAbi(span, default_abi) => { diag.span_label(span, "ABI should be specified here"); diag.help(format!("the default ABI is {}", default_abi.name())); } - BuiltinLintDiagnostics::LegacyDeriveHelpers(span) => { + BuiltinLintDiag::LegacyDeriveHelpers(span) => { diag.span_label(span, "the attribute is introduced here"); } - BuiltinLintDiagnostics::ProcMacroBackCompat(note) => { + BuiltinLintDiag::ProcMacroBackCompat(note) => { diag.note(note); } - BuiltinLintDiagnostics::OrPatternsBackCompat(span, suggestion) => { + BuiltinLintDiag::OrPatternsBackCompat(span, suggestion) => { diag.span_suggestion( span, "use pat_param to preserve semantics", @@ -148,7 +143,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::ReservedPrefix(span) => { + BuiltinLintDiag::ReservedPrefix(span) => { diag.span_label(span, "unknown prefix"); diag.span_suggestion_verbose( span.shrink_to_hi(), @@ -157,19 +152,19 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => { + BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => { diag.span_note( invoc_span, format!("the built-in attribute `{attr_name}` will be ignored, since it's applied to the macro invocation `{macro_name}`") ); } - BuiltinLintDiagnostics::TrailingMacro(is_trailing, name) => { + BuiltinLintDiag::TrailingMacro(is_trailing, name) => { if is_trailing { diag.note("macro invocations at the end of a block are treated as expressions"); diag.note(format!("to ignore the value produced by the macro, add a semicolon after the invocation of `{name}`")); } } - BuiltinLintDiagnostics::BreakWithLabelAndLoop(span) => { + BuiltinLintDiag::BreakWithLabelAndLoop(span) => { diag.multipart_suggestion( "wrap this expression in parentheses", vec![ @@ -179,11 +174,11 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::NamedAsmLabel(help) => { + BuiltinLintDiag::NamedAsmLabel(help) => { diag.help(help); diag.note("see the asm section of Rust By Example for more information"); } - BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => { + BuiltinLintDiag::UnexpectedCfgName((name, name_span), value) => { #[allow(rustc::potential_query_instability)] let possibilities: Vec = sess.psess.check_config.expecteds.keys().copied().collect(); @@ -321,7 +316,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: diag.note("see for more information about checking conditional configuration"); } } - BuiltinLintDiagnostics::UnexpectedCfgValue((name, name_span), value) => { + BuiltinLintDiag::UnexpectedCfgValue((name, name_span), value) => { let Some(ExpectedValues::Some(values)) = &sess.psess.check_config.expecteds.get(&name) else { bug!( @@ -426,7 +421,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: diag.note("see for more information about checking conditional configuration"); } } - BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(sugg) => { + BuiltinLintDiag::DeprecatedWhereclauseLocation(sugg) => { let left_sp = diag.span.primary_span().unwrap(); match sugg { Some((right_sp, sugg)) => diag.multipart_suggestion( @@ -443,7 +438,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: }; diag.note("see issue #89122 for more information"); } - BuiltinLintDiagnostics::SingleUseLifetime { + BuiltinLintDiag::SingleUseLifetime { param_span, use_span: Some((use_span, elide)), deletion_span, @@ -474,11 +469,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: diag.multipart_suggestion(msg, suggestions, Applicability::MachineApplicable); } } - BuiltinLintDiagnostics::SingleUseLifetime { - param_span: _, - use_span: None, - deletion_span, - } => { + BuiltinLintDiag::SingleUseLifetime { param_span: _, use_span: None, deletion_span } => { debug!(?deletion_span); if let Some(deletion_span) = deletion_span { diag.span_suggestion( @@ -489,7 +480,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: ); } } - BuiltinLintDiagnostics::NamedArgumentUsedPositionally { + BuiltinLintDiag::NamedArgumentUsedPositionally { position_sp_to_replace, position_sp_for_msg, named_arg_sp, @@ -525,13 +516,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: ); } } - BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive => { + BuiltinLintDiag::ByteSliceInPackedStructWithDerive => { diag.help("consider implementing the trait by hand, or remove the `packed` attribute"); } - BuiltinLintDiagnostics::UnusedExternCrate { removal_span } => { + BuiltinLintDiag::UnusedExternCrate { removal_span } => { diag.span_suggestion(removal_span, "remove it", "", Applicability::MachineApplicable); } - BuiltinLintDiagnostics::ExternCrateNotIdiomatic { vis_span, ident_span } => { + BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span } => { let suggestion_span = vis_span.between(ident_span); diag.span_suggestion_verbose( suggestion_span, @@ -540,10 +531,10 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::AmbiguousGlobImports { diag: ambiguity } => { + BuiltinLintDiag::AmbiguousGlobImports { diag: ambiguity } => { rustc_errors::report_ambiguity_error(diag, ambiguity); } - BuiltinLintDiagnostics::AmbiguousGlobReexports { + BuiltinLintDiag::AmbiguousGlobReexports { name, namespace, first_reexport_span, @@ -560,7 +551,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: ), ); } - BuiltinLintDiagnostics::HiddenGlobReexports { + BuiltinLintDiag::HiddenGlobReexports { name, namespace, glob_reexport_span, @@ -569,7 +560,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: diag.span_note(glob_reexport_span, format!("the name `{name}` in the {namespace} namespace is supposed to be publicly re-exported here")); diag.span_note(private_item_span, "but the private item here shadows it".to_owned()); } - BuiltinLintDiagnostics::UnusedQualifications { removal_span } => { + BuiltinLintDiag::UnusedQualifications { removal_span } => { diag.span_suggestion_verbose( removal_span, "remove the unnecessary path segments", @@ -577,7 +568,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::AssociatedConstElidedLifetime { elided, span } => { + BuiltinLintDiag::AssociatedConstElidedLifetime { elided, span } => { diag.span_suggestion_verbose( if elided { span.shrink_to_hi() } else { span }, "use the `'static` lifetime", @@ -585,7 +576,7 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiagnostics, diag: Applicability::MachineApplicable, ); } - BuiltinLintDiagnostics::RedundantImportVisibility { max_vis, span } => { + BuiltinLintDiag::RedundantImportVisibility { max_vis, span } => { diag.span_note(span, format!("the most public imported item is `{max_vis}`")); diag.help( "reduce the glob import's visibility or increase visibility of imported items", diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 3be792a9e4f27..d73f9e7a4a1d1 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,5 +1,5 @@ use crate::fluent_generated as fluent; -use rustc_errors::{codes::*, AddToDiagnostic, Diag, EmissionGuarantee, SubdiagnosticMessageOp}; +use rustc_errors::{codes::*, AddToDiagnostic, Diag, EmissionGuarantee, SubdiagMessageOp}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; @@ -24,7 +24,7 @@ pub enum OverruledAttributeSub { } impl AddToDiagnostic for OverruledAttributeSub { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index a071fa488bc47..fdcd0192e6a74 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::SubdiagMessage) { found_diagnostic_message = true; break; diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index ad4a0fc47db4e..906cd1d1283f8 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 a9a2592ac7abf..7e0ac1bfff121 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, SubdiagMessageOp, 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 } } @@ -271,7 +271,7 @@ pub struct SuggestChangingAssocTypes<'a, 'b> { } impl<'a, 'b> AddToDiagnostic for SuggestChangingAssocTypes<'a, 'b> { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -327,7 +327,7 @@ pub struct BuiltinTypeAliasGenericBoundsSuggestion { } impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -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() } } @@ -448,7 +448,7 @@ pub struct BuiltinUnpermittedTypeInitSub { } impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -503,7 +503,7 @@ pub struct BuiltinClashingExternSub<'a> { } impl AddToDiagnostic for BuiltinClashingExternSub<'_> { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -785,7 +785,7 @@ pub struct HiddenUnicodeCodepointsDiagLabels { } impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -803,7 +803,7 @@ pub enum HiddenUnicodeCodepointsDiagSub { // Used because of multiple multipart_suggestion and note impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -951,7 +951,7 @@ pub struct NonBindingLetSub { } impl AddToDiagnostic for NonBindingLetSub { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -1179,7 +1179,7 @@ impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused { } } - fn msg(&self) -> DiagnosticMessage { + fn msg(&self) -> DiagMessage { fluent::lint_non_fmt_panic_unused } } @@ -1237,7 +1237,7 @@ pub enum NonSnakeCaseDiagSub { } impl AddToDiagnostic for NonSnakeCaseDiagSub { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -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 } } @@ -1479,7 +1479,7 @@ pub enum OverflowingBinHexSign { } impl AddToDiagnostic for OverflowingBinHexSign { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -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 a87e2410b3d8e..71f330b5bf799 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 198008d4d0db6..7f200a7b623d6 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; @@ -569,7 +569,7 @@ pub struct AmbiguityErrorDiag { // This could be a closure, but then implementing derive trait // becomes hacky (and it gets allocated). #[derive(Debug)] -pub enum BuiltinLintDiagnostics { +pub enum BuiltinLintDiag { Normal, AbsPathWithModule(Span), ProcMacroDeriveResolutionFallback(Span), @@ -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, @@ -684,7 +684,7 @@ pub struct BufferedEarlyLint { pub lint_id: LintId, /// Customization of the `Diag<'_>` for the lint. - pub diagnostic: BuiltinLintDiagnostics, + pub diagnostic: BuiltinLintDiag, } #[derive(Default, Debug)] @@ -703,8 +703,8 @@ impl LintBuffer { lint: &'static Lint, node_id: NodeId, span: MultiSpan, - msg: impl Into, - diagnostic: BuiltinLintDiagnostics, + msg: impl Into, + diagnostic: BuiltinLintDiag, ) { let lint_id = LintId::of(lint); let msg = msg.into(); @@ -721,9 +721,9 @@ 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) + self.add_lint(lint, id, sp.into(), msg, BuiltinLintDiag::Normal) } pub fn buffer_lint_with_diagnostic( @@ -731,8 +731,8 @@ impl LintBuffer { lint: &'static Lint, id: NodeId, sp: impl Into, - msg: impl Into, - diagnostic: BuiltinLintDiagnostics, + msg: impl Into, + diagnostic: BuiltinLintDiag, ) { 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 5659569c6450c..a1a7b19642b93 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_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 6cbebcc7320d1..ef326106404d5 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -93,7 +93,7 @@ impl SubdiagnosticDeriveBuilder { #f: __F ) where __G: rustc_errors::EmissionGuarantee, - __F: rustc_errors::SubdiagnosticMessageOp<__G>, + __F: rustc_errors::SubdiagMessageOp<__G>, { #implementation } diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 0f6ec656932ce..0d3cffd204770 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 6a3522553c451..d8d6899f05704 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/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 1b09f9fdc492a..c393287da95c9 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -16,7 +16,7 @@ use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; use rustc_hir::{self as hir, HirId}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE}; -use rustc_session::lint::{BuiltinLintDiagnostics, Level, Lint, LintBuffer}; +use rustc_session::lint::{BuiltinLintDiag, Level, Lint, LintBuffer}; use rustc_session::parse::feature_err_issue; use rustc_session::Session; use rustc_span::symbol::{sym, Symbol}; @@ -199,7 +199,7 @@ pub fn early_report_deprecation( return; } - let diag = BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span); + let diag = BuiltinLintDiag::DeprecatedMacro(suggestion, span); lint_buffer.buffer_lint_with_diagnostic(lint, node_id, span, message, diag); } diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index b85354e10f978..aea88c4588be1 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 5ce2e26a0bce3..4b97c25f6105b 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 4c7df0a7ae219..6c92dfa3cd83b 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 96b4797f4fa98..4eec93532a246 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 529d847bfb06a..5a0e2aa691d58 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 03c61803572c6..17659ac23307c 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_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index d889f89f281f3..9a298a13eb665 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -2,7 +2,7 @@ use crate::fluent_generated as fluent; use rustc_errors::DiagArgValue; use rustc_errors::{ codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, - Level, MultiSpan, SubdiagnosticMessageOp, + Level, MultiSpan, SubdiagMessageOp, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; @@ -420,7 +420,7 @@ pub struct UnsafeNotInheritedLintNote { } impl AddToDiagnostic for UnsafeNotInheritedLintNote { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, @@ -868,7 +868,7 @@ pub struct Variant { } impl<'tcx> AddToDiagnostic for AdtDefinedHere<'tcx> { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 6e635529d9667..14d9b0b035080 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 f3eff247bc705..80e9172bbe124 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_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 91dbf0321d2c6..c72b7e2cfa727 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -4,7 +4,7 @@ use rustc_ast::token::Token; use rustc_ast::{Path, Visibility}; use rustc_errors::{ codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, - Level, SubdiagnosticMessageOp, + Level, SubdiagMessageOp, }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::errors::ExprParenthesesNeeded; @@ -1467,7 +1467,7 @@ pub(crate) struct FnTraitMissingParen { } impl AddToDiagnostic for FnTraitMissingParen { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _: F, diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index ca998ccc356fc..f57945a52df37 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -14,7 +14,7 @@ use rustc_lexer::{Cursor, LiteralKind}; use rustc_session::lint::builtin::{ RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX, TEXT_DIRECTION_CODEPOINT_IN_COMMENT, }; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_session::parse::ParseSess; use rustc_span::symbol::Symbol; use rustc_span::{edition::Edition, BytePos, Pos, Span}; @@ -355,7 +355,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> { span, ast::CRATE_NODE_ID, "unicode codepoint changing visible direction of text present in comment", - BuiltinLintDiagnostics::UnicodeTextFlow(span, content.to_string()), + BuiltinLintDiag::UnicodeTextFlow(span, content.to_string()), ); } } @@ -685,7 +685,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> { prefix_span, ast::CRATE_NODE_ID, format!("prefix `{prefix}` is unknown"), - BuiltinLintDiagnostics::ReservedPrefix(prefix_span), + BuiltinLintDiag::ReservedPrefix(prefix_span), ); } } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index eb9a26596183d..6cc358db9fcae 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -31,7 +31,7 @@ use rustc_lexer::unescape::unescape_char; use rustc_macros::Subdiagnostic; use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_span::source_map::{self, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, ErrorGuaranteed, Pos, Span}; @@ -1880,7 +1880,7 @@ impl<'a> Parser<'a> { lo.to(expr.span), ast::CRATE_NODE_ID, "this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression", - BuiltinLintDiagnostics::BreakWithLabelAndLoop(expr.span), + BuiltinLintDiag::BreakWithLabelAndLoop(expr.span), ); } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 5f412bde2eec1..69104a30495bc 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -7,7 +7,7 @@ use crate::fluent_generated as fluent; use rustc_ast::Label; use rustc_errors::{ codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, DiagSymbolList, EmissionGuarantee, - IntoDiagnostic, Level, MultiSpan, SubdiagnosticMessageOp, + IntoDiagnostic, Level, MultiSpan, SubdiagMessageOp, }; use rustc_hir::{self as hir, ExprKind, Target}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; @@ -1752,7 +1752,7 @@ pub struct UnusedVariableStringInterp { } impl AddToDiagnostic for UnusedVariableStringInterp { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _f: F, diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/errors.rs index 2d592b35159dd..d0f56f0268dfa 100644 --- a/compiler/rustc_pattern_analysis/src/errors.rs +++ b/compiler/rustc_pattern_analysis/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{AddToDiagnostic, Diag, EmissionGuarantee, SubdiagnosticMessageOp}; +use rustc_errors::{AddToDiagnostic, Diag, EmissionGuarantee, SubdiagMessageOp}; use rustc_macros::{LintDiagnostic, Subdiagnostic}; use rustc_middle::thir::Pat; use rustc_middle::ty::Ty; @@ -62,7 +62,7 @@ pub struct Overlap<'tcx> { } impl<'tcx> AddToDiagnostic for Overlap<'tcx> { - fn add_to_diagnostic_with>( + fn add_to_diagnostic_with>( self, diag: &mut Diag<'_, G>, _: F, diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs index 37cc50f694385..13fec70e0a7f3 100644 --- a/compiler/rustc_resolve/src/check_unused.rs +++ b/compiler/rustc_resolve/src/check_unused.rs @@ -35,7 +35,7 @@ use rustc_data_structures::unord::UnordSet; use rustc_errors::{pluralize, MultiSpan}; use rustc_hir::def::{DefKind, Res}; use rustc_session::lint::builtin::{MACRO_USE_EXTERN_CRATE, UNUSED_EXTERN_CRATES, UNUSED_IMPORTS}; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_span::symbol::{kw, Ident}; use rustc_span::{Span, DUMMY_SP}; @@ -412,7 +412,7 @@ impl Resolver<'_, '_> { unused.use_tree_id, ms, msg, - BuiltinLintDiagnostics::UnusedImports(fix_msg.into(), fixes, test_module_span), + BuiltinLintDiag::UnusedImports(fix_msg.into(), fixes, test_module_span), ); } @@ -428,7 +428,7 @@ impl Resolver<'_, '_> { extern_crate.id, span, "unused extern crate", - BuiltinLintDiagnostics::UnusedExternCrate { + BuiltinLintDiag::UnusedExternCrate { removal_span: extern_crate.span_with_attributes, }, ); @@ -481,7 +481,7 @@ impl Resolver<'_, '_> { extern_crate.id, extern_crate.span, "`extern crate` is not idiomatic in the new edition", - BuiltinLintDiagnostics::ExternCrateNotIdiomatic { vis_span, ident_span }, + BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span }, ); } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index dc7dfa04d18f2..833ebfa03e5fc 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -19,7 +19,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE; use rustc_session::lint::builtin::AMBIGUOUS_GLOB_IMPORTS; use rustc_session::lint::builtin::MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS; -use rustc_session::lint::{AmbiguityErrorDiag, BuiltinLintDiagnostics}; +use rustc_session::lint::{AmbiguityErrorDiag, BuiltinLintDiag}; use rustc_session::Session; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; @@ -138,7 +138,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { CRATE_NODE_ID, span_use, msg, - BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def), + BuiltinLintDiag::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def), ); } @@ -153,7 +153,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { import.root_id, ambiguity_error.ident.span, diag.msg.to_string(), - BuiltinLintDiagnostics::AmbiguousGlobImports { diag }, + BuiltinLintDiag::AmbiguousGlobImports { diag }, ); } else { let mut err = struct_span_code_err!(self.dcx(), diag.span, E0659, "{}", &diag.msg); @@ -188,7 +188,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &candidates, if instead { Instead::Yes } else { Instead::No }, found_use, - DiagnosticMode::Normal, + DiagMode::Normal, path, "", ); @@ -525,7 +525,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } } - let diag = BuiltinLintDiagnostics::AbsPathWithModule(root_span); + let diag = BuiltinLintDiag::AbsPathWithModule(root_span); self.lint_buffer.buffer_lint_with_diagnostic( ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, node_id, @@ -723,7 +723,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &import_suggestions, Instead::No, FoundUse::Yes, - DiagnosticMode::Pattern, + DiagMode::Pattern, vec![], "", ); @@ -1444,7 +1444,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &import_suggestions, Instead::No, found_use, - DiagnosticMode::Normal, + DiagMode::Normal, vec![], "", ); @@ -1775,7 +1775,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &import_suggestions, Instead::Yes, FoundUse::Yes, - DiagnosticMode::Import, + DiagMode::Import, vec![], "", ); @@ -2696,7 +2696,7 @@ enum FoundUse { } /// Whether a binding is part of a pattern or a use statement. Used for diagnostics. -pub(crate) enum DiagnosticMode { +pub(crate) enum DiagMode { Normal, /// The binding is part of a pattern Pattern, @@ -2710,7 +2710,7 @@ pub(crate) fn import_candidates( // This is `None` if all placement locations are inside expansions use_placement_span: Option, candidates: &[ImportSuggestion], - mode: DiagnosticMode, + mode: DiagMode, append: &str, ) { show_candidates( @@ -2738,7 +2738,7 @@ fn show_candidates( candidates: &[ImportSuggestion], instead: Instead, found_use: FoundUse, - mode: DiagnosticMode, + mode: DiagMode, path: Vec, append: &str, ) -> bool { @@ -2799,7 +2799,7 @@ fn show_candidates( }; let instead = if let Instead::Yes = instead { " instead" } else { "" }; - let mut msg = if let DiagnosticMode::Pattern = mode { + let mut msg = if let DiagMode::Pattern = mode { format!( "if you meant to match on {kind}{instead}{name}, use the full path in the pattern", ) @@ -2813,7 +2813,7 @@ fn show_candidates( if let Some(span) = use_placement_span { let (add_use, trailing) = match mode { - DiagnosticMode::Pattern => { + DiagMode::Pattern => { err.span_suggestions( span, msg, @@ -2822,14 +2822,14 @@ fn show_candidates( ); return true; } - DiagnosticMode::Import => ("", ""), - DiagnosticMode::Normal => ("use ", ";\n"), + DiagMode::Import => ("", ""), + DiagMode::Normal => ("use ", ";\n"), }; for candidate in &mut accessible_path_strings { // produce an additional newline to separate the new use statement // from the directly following item. let additional_newline = if let FoundUse::No = found_use - && let DiagnosticMode::Normal = mode + && let DiagMode::Normal = mode { "\n" } else { @@ -2870,16 +2870,13 @@ fn show_candidates( err.help(msg); } true - } else if !(inaccessible_path_strings.is_empty() || matches!(mode, DiagnosticMode::Import)) { - let prefix = if let DiagnosticMode::Pattern = mode { - "you might have meant to match on " - } else { - "" - }; + } else if !(inaccessible_path_strings.is_empty() || matches!(mode, DiagMode::Import)) { + let prefix = + if let DiagMode::Pattern = mode { "you might have meant to match on " } else { "" }; if let [(name, descr, def_id, note, _)] = &inaccessible_path_strings[..] { let msg = format!( "{prefix}{descr} `{name}`{} exists but is inaccessible", - if let DiagnosticMode::Pattern = mode { ", which" } else { "" } + if let DiagMode::Pattern = mode { ", which" } else { "" } ); if let Some(local_def_id) = def_id.and_then(|did| did.as_local()) { diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index c17ea00ec8094..a9fdddbfab90f 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -4,7 +4,7 @@ use rustc_hir::def::{DefKind, Namespace, NonMacroAttrKind, PartialRes, PerNS}; use rustc_middle::bug; use rustc_middle::ty; use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_span::def_id::LocalDefId; use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext}; use rustc_span::symbol::{kw, Ident}; @@ -530,7 +530,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ns.descr(), ident ), - BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback( + BuiltinLintDiag::ProcMacroDeriveResolutionFallback( orig_ident.span, ), ); diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 9bfca0f179880..0cd925c5ba6ae 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1,6 +1,6 @@ //! A bunch of methods and structures more or less related to resolving imports. -use crate::diagnostics::{import_candidates, DiagnosticMode, Suggestion}; +use crate::diagnostics::{import_candidates, DiagMode, Suggestion}; use crate::errors::{ CannotBeReexportedCratePublic, CannotBeReexportedCratePublicNS, CannotBeReexportedPrivate, CannotBeReexportedPrivateNS, CannotDetermineImportResolution, CannotGlobImportAllCrates, @@ -27,7 +27,7 @@ use rustc_session::lint::builtin::{ AMBIGUOUS_GLOB_REEXPORTS, HIDDEN_GLOB_REEXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS, }; -use rustc_session::lint::BuiltinLintDiagnostics; +use rustc_session::lint::BuiltinLintDiag; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::hygiene::LocalExpnId; use rustc_span::symbol::{kw, Ident, Symbol}; @@ -618,7 +618,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { import.root_id, import.root_span, "ambiguous glob re-exports", - BuiltinLintDiagnostics::AmbiguousGlobReexports { + BuiltinLintDiag::AmbiguousGlobReexports { name: key.ident.to_string(), namespace: key.ns.descr().to_string(), first_reexport_span: import.root_span, @@ -654,7 +654,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { binding_id, binding.span, "private item shadows public glob re-export", - BuiltinLintDiagnostics::HiddenGlobReexports { + BuiltinLintDiag::HiddenGlobReexports { name: key.ident.name.to_string(), namespace: key.ns.descr().to_owned(), glob_reexport_span: glob_binding.span, @@ -716,7 +716,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &mut diag, Some(err.span), candidates, - DiagnosticMode::Import, + DiagMode::Import, (source != target) .then(|| format!(" as {target}")) .as_deref() @@ -728,7 +728,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { &mut diag, None, candidates, - DiagnosticMode::Normal, + DiagMode::Normal, (source != target) .then(|| format!(" as {target}")) .as_deref() @@ -1006,7 +1006,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { id, import.span, msg, - BuiltinLintDiagnostics::RedundantImportVisibility { + BuiltinLintDiag::RedundantImportVisibility { max_vis: max_vis.to_string(def_id, self.tcx), span: import.span, }, @@ -1373,7 +1373,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { id, import.span, format!("the item `{source}` is imported redundantly"), - BuiltinLintDiagnostics::RedundantImport(redundant_spans, source), + BuiltinLintDiag::RedundantImport(redundant_spans, source), ); } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 85db8ba8618e1..de6e121c79bbb 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -581,7 +581,7 @@ impl MaybeExported<'_> { } #[derive(Default)] -struct DiagnosticMetadata<'ast> { +struct DiagMetadata<'ast> { /// The current trait's associated items' ident, used for diagnostic suggestions. current_trait_assoc_items: Option<&'ast [P]>, @@ -674,7 +674,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { current_trait_ref: Option<(Module<'a>, TraitRef)>, /// Fields used to add information to diagnostic errors. - diagnostic_metadata: Box>, + diag_metadata: Box>, /// State used to know whether to ignore resolution errors for function bodies. /// @@ -694,12 +694,12 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, // as they do not correspond to actual code. } fn visit_item(&mut self, item: &'ast Item) { - let prev = replace(&mut self.diagnostic_metadata.current_item, Some(item)); + let prev = replace(&mut self.diag_metadata.current_item, Some(item)); // Always report errors in items we just entered. let old_ignore = replace(&mut self.in_func_body, false); self.with_lifetime_rib(LifetimeRibKind::Item, |this| this.resolve_item(item)); self.in_func_body = old_ignore; - self.diagnostic_metadata.current_item = prev; + self.diag_metadata.current_item = prev; } fn visit_arm(&mut self, arm: &'ast Arm) { self.resolve_arm(arm); @@ -716,10 +716,10 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, self.resolve_expr(expr, None); } fn visit_pat(&mut self, p: &'ast Pat) { - let prev = self.diagnostic_metadata.current_pat; - self.diagnostic_metadata.current_pat = Some(p); + let prev = self.diag_metadata.current_pat; + self.diag_metadata.current_pat = Some(p); visit::walk_pat(self, p); - self.diagnostic_metadata.current_pat = prev; + self.diag_metadata.current_pat = prev; } fn visit_local(&mut self, local: &'ast Local) { let local_spans = match local.pat.kind { @@ -731,13 +731,13 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, local.kind.init().map(|init| init.span), )), }; - let original = replace(&mut self.diagnostic_metadata.current_let_binding, local_spans); + let original = replace(&mut self.diag_metadata.current_let_binding, local_spans); self.resolve_local(local); - self.diagnostic_metadata.current_let_binding = original; + self.diag_metadata.current_let_binding = original; } fn visit_ty(&mut self, ty: &'ast Ty) { - let prev = self.diagnostic_metadata.current_trait_object; - let prev_ty = self.diagnostic_metadata.current_type_path; + let prev = self.diag_metadata.current_trait_object; + let prev_ty = self.diag_metadata.current_type_path; match &ty.kind { TyKind::Ref(None, _) => { // Elided lifetime in reference: we resolve as if there was some lifetime `'_` with @@ -748,7 +748,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, visit::walk_ty(self, ty); } TyKind::Path(qself, path) => { - self.diagnostic_metadata.current_type_path = Some(ty); + self.diag_metadata.current_type_path = Some(ty); self.smart_resolve_path(ty.id, qself, path, PathSource::Type); // Check whether we should interpret this as a bare trait object. @@ -795,7 +795,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, self.lifetime_elision_candidates = candidates; } TyKind::TraitObject(bounds, ..) => { - self.diagnostic_metadata.current_trait_object = Some(&bounds[..]); + self.diag_metadata.current_trait_object = Some(&bounds[..]); visit::walk_ty(self, ty) } TyKind::BareFn(bare_fn) => { @@ -842,8 +842,8 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, } _ => visit::walk_ty(self, ty), } - self.diagnostic_metadata.current_trait_object = prev; - self.diagnostic_metadata.current_type_path = prev_ty; + self.diag_metadata.current_trait_object = prev; + self.diag_metadata.current_type_path = prev_ty; } fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef) { let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo()); @@ -906,7 +906,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, } } fn visit_fn(&mut self, fn_kind: FnKind<'ast>, sp: Span, fn_id: NodeId) { - let previous_value = self.diagnostic_metadata.current_function; + let previous_value = self.diag_metadata.current_function; match fn_kind { // Bail if the function is foreign, and thus cannot validly have // a body, or if there's no body for some other reason. @@ -939,7 +939,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, return; } FnKind::Fn(..) => { - self.diagnostic_metadata.current_function = Some((fn_kind, sp)); + self.diag_metadata.current_function = Some((fn_kind, sp)); } // Do not update `current_function` for closures: it suggests `self` parameters. FnKind::Closure(..) => {} @@ -1040,17 +1040,14 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, } }) }); - self.diagnostic_metadata.current_function = previous_value; + self.diag_metadata.current_function = previous_value; } fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, use_ctxt: visit::LifetimeCtxt) { self.resolve_lifetime(lifetime, use_ctxt) } fn visit_generics(&mut self, generics: &'ast Generics) { - self.visit_generic_params( - &generics.params, - self.diagnostic_metadata.current_self_item.is_some(), - ); + self.visit_generic_params(&generics.params, self.diag_metadata.current_self_item.is_some()); for p in &generics.where_clause.predicates { self.visit_where_predicate(p); } @@ -1062,7 +1059,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, ClosureBinder::For { generic_params, .. } => { self.visit_generic_params( generic_params, - self.diagnostic_metadata.current_self_item.is_some(), + self.diag_metadata.current_self_item.is_some(), ); } } @@ -1070,7 +1067,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, fn visit_generic_arg(&mut self, arg: &'ast GenericArg) { debug!("visit_generic_arg({:?})", arg); - let prev = replace(&mut self.diagnostic_metadata.currently_processing_generic_args, true); + let prev = replace(&mut self.diag_metadata.currently_processing_generic_args, true); match arg { GenericArg::Type(ref ty) => { // We parse const arguments as path types as we cannot distinguish them during @@ -1101,7 +1098,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, }, ); - self.diagnostic_metadata.currently_processing_generic_args = prev; + self.diag_metadata.currently_processing_generic_args = prev; return; } } @@ -1114,7 +1111,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No)) } } - self.diagnostic_metadata.currently_processing_generic_args = prev; + self.diag_metadata.currently_processing_generic_args = prev; } fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) { @@ -1192,8 +1189,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, fn visit_where_predicate(&mut self, p: &'ast WherePredicate) { debug!("visit_where_predicate {:?}", p); - let previous_value = - replace(&mut self.diagnostic_metadata.current_where_predicate, Some(p)); + let previous_value = replace(&mut self.diag_metadata.current_where_predicate, Some(p)); self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| { if let WherePredicate::BoundPredicate(WhereBoundPredicate { ref bounded_ty, @@ -1224,7 +1220,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, visit::walk_where_predicate(this, p); } }); - self.diagnostic_metadata.current_where_predicate = previous_value; + self.diag_metadata.current_where_predicate = previous_value; } fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) { @@ -1297,7 +1293,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { lifetime_ribs: Vec::new(), lifetime_elision_candidates: None, current_trait_ref: None, - diagnostic_metadata: Default::default(), + diag_metadata: Default::default(), // errors at module scope should always be reported in_func_body: false, lifetime_uses: Default::default(), @@ -1660,7 +1656,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { node_id, lifetime.ident.span, msg, - lint::BuiltinLintDiagnostics::AssociatedConstElidedLifetime { + lint::BuiltinLintDiag::AssociatedConstElidedLifetime { elided, span: lifetime.ident.span, }, @@ -1707,7 +1703,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { return; } LifetimeRibKind::ElisionFailure => { - self.diagnostic_metadata.current_elision_failures.push(missing_lifetime); + self.diag_metadata.current_elision_failures.push(missing_lifetime); self.record_lifetime_res(lifetime.id, LifetimeRes::Error, elision_candidate); return; } @@ -1911,7 +1907,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { break; } LifetimeRibKind::ElisionFailure => { - self.diagnostic_metadata.current_elision_failures.push(missing_lifetime); + self.diag_metadata.current_elision_failures.push(missing_lifetime); for id in node_ids { self.record_lifetime_res( id, @@ -1950,7 +1946,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { segment_id, elided_lifetime_span, "hidden lifetime parameters in types are deprecated", - lint::BuiltinLintDiagnostics::ElidedLifetimesInPaths( + lint::BuiltinLintDiag::ElidedLifetimesInPaths( expected_lifetimes, path_span, !segment.has_generic_args, @@ -2003,7 +1999,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { let elision_lifetime = self.resolve_fn_params(has_self, inputs); debug!(?elision_lifetime); - let outer_failures = take(&mut self.diagnostic_metadata.current_elision_failures); + let outer_failures = take(&mut self.diag_metadata.current_elision_failures); let output_rib = if let Ok(res) = elision_lifetime.as_ref() { self.r.lifetime_elision_allowed.insert(fn_id); LifetimeRibKind::Elided(*res) @@ -2012,7 +2008,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { }; self.with_lifetime_rib(output_rib, |this| visit::walk_fn_ret_ty(this, output_ty)); let elision_failures = - replace(&mut self.diagnostic_metadata.current_elision_failures, outer_failures); + replace(&mut self.diag_metadata.current_elision_failures, outer_failures); if !elision_failures.is_empty() { let Err(failure_info) = elision_lifetime else { bug!() }; self.report_missing_lifetime_specifiers(elision_failures, Some(failure_info)); @@ -2187,7 +2183,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { } let impl_self = self - .diagnostic_metadata + .diag_metadata .current_self_type .as_ref() .and_then(|ty| { @@ -2385,7 +2381,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { items: ref impl_items, .. }) => { - self.diagnostic_metadata.current_impl_items = Some(impl_items); + self.diag_metadata.current_impl_items = Some(impl_items); self.resolve_implementation( &item.attrs, generics, @@ -2394,7 +2390,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { item.id, impl_items, ); - self.diagnostic_metadata.current_impl_items = None; + self.diag_metadata.current_impl_items = None; } ItemKind::Trait(box Trait { ref generics, ref bounds, ref items, .. }) => { @@ -2744,24 +2740,23 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { fn with_current_self_type(&mut self, self_type: &Ty, f: impl FnOnce(&mut Self) -> T) -> T { // Handle nested impls (inside fn bodies) let previous_value = - replace(&mut self.diagnostic_metadata.current_self_type, Some(self_type.clone())); + replace(&mut self.diag_metadata.current_self_type, Some(self_type.clone())); let result = f(self); - self.diagnostic_metadata.current_self_type = previous_value; + self.diag_metadata.current_self_type = previous_value; result } fn with_current_self_item(&mut self, self_item: &Item, f: impl FnOnce(&mut Self) -> T) -> T { - let previous_value = - replace(&mut self.diagnostic_metadata.current_self_item, Some(self_item.id)); + let previous_value = replace(&mut self.diag_metadata.current_self_item, Some(self_item.id)); let result = f(self); - self.diagnostic_metadata.current_self_item = previous_value; + self.diag_metadata.current_self_item = previous_value; result } /// When evaluating a `trait` use its associated types' idents for suggestions in E0412. fn resolve_trait_items(&mut self, trait_items: &'ast [P]) { let trait_assoc_items = - replace(&mut self.diagnostic_metadata.current_trait_assoc_items, Some(trait_items)); + replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items)); let walk_assoc_item = |this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| { @@ -2818,7 +2813,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { }; } - self.diagnostic_metadata.current_trait_assoc_items = trait_assoc_items; + self.diag_metadata.current_trait_assoc_items = trait_assoc_items; } /// This is called to resolve a trait reference from an `impl` (i.e., `impl Trait for Foo`). @@ -2832,7 +2827,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { let mut new_id = None; if let Some(trait_ref) = opt_trait_ref { let path: Vec<_> = Segment::from_path(&trait_ref.path); - self.diagnostic_metadata.currently_processing_impl_trait = + self.diag_metadata.currently_processing_impl_trait = Some((trait_ref.clone(), self_type.clone())); let res = self.smart_resolve_path_fragment( &None, @@ -2841,7 +2836,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { Finalize::new(trait_ref.ref_id, trait_ref.path.span), RecordPartialRes::Yes, ); - self.diagnostic_metadata.currently_processing_impl_trait = None; + self.diag_metadata.currently_processing_impl_trait = None; if let Some(def_id) = res.expect_full_res().opt_def_id() { new_id = Some(def_id); new_val = Some((self.r.expect_module(def_id), trait_ref.clone())); @@ -3737,7 +3732,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { let def_id = this.parent_scope.module.nearest_parent_mod(); let instead = res.is_some(); - let suggestion = if let Some((start, end)) = this.diagnostic_metadata.in_range + let suggestion = if let Some((start, end)) = this.diag_metadata.in_range && path[0].ident.span.lo() == end.span.lo() { let mut sugg = "."; @@ -3890,7 +3885,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { ) { Ok(Some(partial_res)) if let Some(res) = partial_res.full_res() => { // if we also have an associated type that matches the ident, stash a suggestion - if let Some(items) = self.diagnostic_metadata.current_trait_assoc_items + if let Some(items) = self.diag_metadata.current_trait_assoc_items && let [Segment { ident, .. }] = path && items.iter().any(|item| { item.ident == *ident && matches!(item.kind, AssocItemKind::Type(_)) @@ -4176,7 +4171,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { finalize.node_id, finalize.path_span, "unnecessary qualification", - lint::BuiltinLintDiagnostics::UnusedQualifications { + lint::BuiltinLintDiag::UnusedQualifications { removal_span: finalize.path_span.until(unqualified.ident.span), }, ); @@ -4189,7 +4184,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { fn with_resolved_label(&mut self, label: Option