Auto merge of #122132 - nnethercote:diag-renaming3, r=nnethercote

Diagnostic renaming 3

A sequel to https://github.com/rust-lang/rust/pull/121780.

r? `@davidtwco`
This commit is contained in:
bors 2024-03-11 00:34:44 +00:00
commit cd81f5b27e
78 changed files with 567 additions and 586 deletions

View file

@ -1,10 +1,10 @@
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagMessageOp, codes::*, Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol}; use rustc_span::{symbol::Ident, Span, Symbol};
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_generic_type_with_parentheses, code = E0214)] #[diag(ast_lowering_generic_type_with_parentheses, code = E0214)]
pub struct GenericTypeWithParentheses { pub struct GenericTypeWithParentheses {
#[primary_span] #[primary_span]
@ -14,7 +14,7 @@ pub struct GenericTypeWithParentheses {
pub sub: Option<UseAngleBrackets>, pub sub: Option<UseAngleBrackets>,
} }
#[derive(Clone, Copy, Subdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion(ast_lowering_use_angle_brackets, applicability = "maybe-incorrect")] #[multipart_suggestion(ast_lowering_use_angle_brackets, applicability = "maybe-incorrect")]
pub struct UseAngleBrackets { pub struct UseAngleBrackets {
#[suggestion_part(code = "<")] #[suggestion_part(code = "<")]
@ -40,8 +40,8 @@ pub struct InvalidAbi {
pub struct InvalidAbiReason(pub &'static str); pub struct InvalidAbiReason(pub &'static str);
impl AddToDiagnostic for InvalidAbiReason { impl Subdiagnostic for InvalidAbiReason {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_: F, _: F,
@ -63,7 +63,7 @@ pub struct InvalidAbiSuggestion {
pub suggestion: String, pub suggestion: String,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_assoc_ty_parentheses)] #[diag(ast_lowering_assoc_ty_parentheses)]
pub struct AssocTyParentheses { pub struct AssocTyParentheses {
#[primary_span] #[primary_span]
@ -72,7 +72,7 @@ pub struct AssocTyParentheses {
pub sub: AssocTyParenthesesSub, pub sub: AssocTyParenthesesSub,
} }
#[derive(Clone, Copy, Subdiagnostic)] #[derive(Subdiagnostic)]
pub enum AssocTyParenthesesSub { pub enum AssocTyParenthesesSub {
#[multipart_suggestion(ast_lowering_remove_parentheses)] #[multipart_suggestion(ast_lowering_remove_parentheses)]
Empty { Empty {
@ -106,7 +106,7 @@ pub struct MisplacedAssocTyBinding {
pub suggestion: Option<Span>, pub suggestion: Option<Span>,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_underscore_expr_lhs_assign)] #[diag(ast_lowering_underscore_expr_lhs_assign)]
pub struct UnderscoreExprLhsAssign { pub struct UnderscoreExprLhsAssign {
#[primary_span] #[primary_span]
@ -114,7 +114,7 @@ pub struct UnderscoreExprLhsAssign {
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_base_expression_double_dot, code = E0797)] #[diag(ast_lowering_base_expression_double_dot, code = E0797)]
pub struct BaseExpressionDoubleDot { pub struct BaseExpressionDoubleDot {
#[primary_span] #[primary_span]
@ -122,7 +122,7 @@ pub struct BaseExpressionDoubleDot {
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = E0728)] #[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = E0728)]
pub struct AwaitOnlyInAsyncFnAndBlocks { pub struct AwaitOnlyInAsyncFnAndBlocks {
#[primary_span] #[primary_span]
@ -132,21 +132,21 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
pub item_span: Option<Span>, pub item_span: Option<Span>,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_coroutine_too_many_parameters, code = E0628)] #[diag(ast_lowering_coroutine_too_many_parameters, code = E0628)]
pub struct CoroutineTooManyParameters { pub struct CoroutineTooManyParameters {
#[primary_span] #[primary_span]
pub fn_decl_span: Span, pub fn_decl_span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_closure_cannot_be_static, code = E0697)] #[diag(ast_lowering_closure_cannot_be_static, code = E0697)]
pub struct ClosureCannotBeStatic { pub struct ClosureCannotBeStatic {
#[primary_span] #[primary_span]
pub fn_decl_span: Span, pub fn_decl_span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_functional_record_update_destructuring_assignment)] #[diag(ast_lowering_functional_record_update_destructuring_assignment)]
pub struct FunctionalRecordUpdateDestructuringAssignment { pub struct FunctionalRecordUpdateDestructuringAssignment {
#[primary_span] #[primary_span]
@ -154,28 +154,28 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_async_coroutines_not_supported, code = E0727)] #[diag(ast_lowering_async_coroutines_not_supported, code = E0727)]
pub struct AsyncCoroutinesNotSupported { pub struct AsyncCoroutinesNotSupported {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_inline_asm_unsupported_target, code = E0472)] #[diag(ast_lowering_inline_asm_unsupported_target, code = E0472)]
pub struct InlineAsmUnsupportedTarget { pub struct InlineAsmUnsupportedTarget {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_att_syntax_only_x86)] #[diag(ast_lowering_att_syntax_only_x86)]
pub struct AttSyntaxOnlyX86 { pub struct AttSyntaxOnlyX86 {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_abi_specified_multiple_times)] #[diag(ast_lowering_abi_specified_multiple_times)]
pub struct AbiSpecifiedMultipleTimes { pub struct AbiSpecifiedMultipleTimes {
#[primary_span] #[primary_span]
@ -187,7 +187,7 @@ pub struct AbiSpecifiedMultipleTimes {
pub equivalent: Option<()>, pub equivalent: Option<()>,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_clobber_abi_not_supported)] #[diag(ast_lowering_clobber_abi_not_supported)]
pub struct ClobberAbiNotSupported { pub struct ClobberAbiNotSupported {
#[primary_span] #[primary_span]
@ -203,7 +203,7 @@ pub struct InvalidAbiClobberAbi {
pub supported_abis: String, pub supported_abis: String,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_invalid_register)] #[diag(ast_lowering_invalid_register)]
pub struct InvalidRegister<'a> { pub struct InvalidRegister<'a> {
#[primary_span] #[primary_span]
@ -212,7 +212,7 @@ pub struct InvalidRegister<'a> {
pub error: &'a str, pub error: &'a str,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_invalid_register_class)] #[diag(ast_lowering_invalid_register_class)]
pub struct InvalidRegisterClass<'a> { pub struct InvalidRegisterClass<'a> {
#[primary_span] #[primary_span]
@ -241,7 +241,7 @@ pub enum InvalidAsmTemplateModifierRegClassSub {
DoesNotSupportModifier { class_name: Symbol }, DoesNotSupportModifier { class_name: Symbol },
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_invalid_asm_template_modifier_const)] #[diag(ast_lowering_invalid_asm_template_modifier_const)]
pub struct InvalidAsmTemplateModifierConst { pub struct InvalidAsmTemplateModifierConst {
#[primary_span] #[primary_span]
@ -251,7 +251,7 @@ pub struct InvalidAsmTemplateModifierConst {
pub op_span: Span, pub op_span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_invalid_asm_template_modifier_sym)] #[diag(ast_lowering_invalid_asm_template_modifier_sym)]
pub struct InvalidAsmTemplateModifierSym { pub struct InvalidAsmTemplateModifierSym {
#[primary_span] #[primary_span]
@ -261,7 +261,7 @@ pub struct InvalidAsmTemplateModifierSym {
pub op_span: Span, pub op_span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_invalid_asm_template_modifier_label)] #[diag(ast_lowering_invalid_asm_template_modifier_label)]
pub struct InvalidAsmTemplateModifierLabel { pub struct InvalidAsmTemplateModifierLabel {
#[primary_span] #[primary_span]
@ -271,7 +271,7 @@ pub struct InvalidAsmTemplateModifierLabel {
pub op_span: Span, pub op_span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_register_class_only_clobber)] #[diag(ast_lowering_register_class_only_clobber)]
pub struct RegisterClassOnlyClobber { pub struct RegisterClassOnlyClobber {
#[primary_span] #[primary_span]
@ -279,7 +279,7 @@ pub struct RegisterClassOnlyClobber {
pub reg_class_name: Symbol, pub reg_class_name: Symbol,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_register_conflict)] #[diag(ast_lowering_register_conflict)]
pub struct RegisterConflict<'a> { pub struct RegisterConflict<'a> {
#[primary_span] #[primary_span]
@ -293,7 +293,7 @@ pub struct RegisterConflict<'a> {
pub in_out: Option<Span>, pub in_out: Option<Span>,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[help] #[help]
#[diag(ast_lowering_sub_tuple_binding)] #[diag(ast_lowering_sub_tuple_binding)]
pub struct SubTupleBinding<'a> { pub struct SubTupleBinding<'a> {
@ -311,7 +311,7 @@ pub struct SubTupleBinding<'a> {
pub ctx: &'a str, pub ctx: &'a str,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_extra_double_dot)] #[diag(ast_lowering_extra_double_dot)]
pub struct ExtraDoubleDot<'a> { pub struct ExtraDoubleDot<'a> {
#[primary_span] #[primary_span]
@ -322,7 +322,7 @@ pub struct ExtraDoubleDot<'a> {
pub ctx: &'a str, pub ctx: &'a str,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[note] #[note]
#[diag(ast_lowering_misplaced_double_dot)] #[diag(ast_lowering_misplaced_double_dot)]
pub struct MisplacedDoubleDot { pub struct MisplacedDoubleDot {
@ -330,7 +330,7 @@ pub struct MisplacedDoubleDot {
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_misplaced_relax_trait_bound)] #[diag(ast_lowering_misplaced_relax_trait_bound)]
pub struct MisplacedRelaxTraitBound { pub struct MisplacedRelaxTraitBound {
#[primary_span] #[primary_span]
@ -363,14 +363,14 @@ pub struct NeverPatternWithGuard {
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_arbitrary_expression_in_pattern)] #[diag(ast_lowering_arbitrary_expression_in_pattern)]
pub struct ArbitraryExpressionInPattern { pub struct ArbitraryExpressionInPattern {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
} }
#[derive(Diagnostic, Clone, Copy)] #[derive(Diagnostic)]
#[diag(ast_lowering_inclusive_range_with_no_end)] #[diag(ast_lowering_inclusive_range_with_no_end)]
pub struct InclusiveRangeWithNoEnd { pub struct InclusiveRangeWithNoEnd {
#[primary_span] #[primary_span]

View file

@ -2,7 +2,7 @@
use rustc_ast::ParamKindOrd; use rustc_ast::ParamKindOrd;
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, codes::*, Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol}; use rustc_span::{symbol::Ident, Span, Symbol};
@ -373,8 +373,8 @@ pub struct ArgsBeforeConstraint {
pub struct EmptyLabelManySpans(pub Vec<Span>); pub struct EmptyLabelManySpans(pub Vec<Span>);
// The derive for `Vec<Span>` does multiple calls to `span_label`, adding commas between each // The derive for `Vec<Span>` does multiple calls to `span_label`, adding commas between each
impl AddToDiagnostic for EmptyLabelManySpans { impl Subdiagnostic for EmptyLabelManySpans {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_: F, _: F,
@ -742,8 +742,8 @@ pub struct StableFeature {
pub since: Symbol, pub since: Symbol,
} }
impl AddToDiagnostic for StableFeature { impl Subdiagnostic for StableFeature {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_: F, _: F,

View file

@ -1,9 +1,7 @@
use std::num::IntErrorKind; use std::num::IntErrorKind;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_errors::{ use rustc_errors::{codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
codes::*, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level,
};
use rustc_macros::Diagnostic; use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
@ -50,8 +48,8 @@ pub(crate) struct UnknownMetaItem<'a> {
} }
// Manual implementation to be able to format `expected` items correctly. // Manual implementation to be able to format `expected` items correctly.
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnknownMetaItem<'_> {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>(); let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
Diag::new(dcx, level, fluent::attr_unknown_meta_item) Diag::new(dcx, level, fluent::attr_unknown_meta_item)
.with_span(self.span) .with_span(self.span)
@ -203,8 +201,8 @@ pub(crate) struct UnsupportedLiteral {
pub start_point_span: Span, pub start_point_span: Span,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnsupportedLiteral { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
let mut diag = Diag::new( let mut diag = Diag::new(
dcx, dcx,
level, level,

View file

@ -191,9 +191,9 @@ impl Display for RegionName {
} }
} }
impl rustc_errors::IntoDiagnosticArg for RegionName { impl rustc_errors::IntoDiagArg for RegionName {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }

View file

@ -1,6 +1,6 @@
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, MultiSpan, codes::*, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level, MultiSpan,
SingleLabelManySpans, SubdiagMessageOp, SingleLabelManySpans, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol}; use rustc_span::{symbol::Ident, Span, Symbol};
@ -425,9 +425,9 @@ pub(crate) struct EnvNotDefinedWithUserMessage {
} }
// Hand-written implementation to support custom user messages. // Hand-written implementation to support custom user messages.
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMessage { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for EnvNotDefinedWithUserMessage {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
#[expect( #[expect(
rustc::untranslatable_diagnostic, rustc::untranslatable_diagnostic,
reason = "cannot translate user-provided messages" reason = "cannot translate user-provided messages"
@ -589,8 +589,8 @@ pub(crate) struct FormatUnusedArg {
// Allow the singular form to be a subdiagnostic of the multiple-unused // Allow the singular form to be a subdiagnostic of the multiple-unused
// form of diagnostic. // form of diagnostic.
impl AddToDiagnostic for FormatUnusedArg { impl Subdiagnostic for FormatUnusedArg {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,
@ -785,8 +785,8 @@ pub(crate) struct AsmClobberNoReg {
pub(crate) clobbers: Vec<Span>, pub(crate) clobbers: Vec<Span>,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AsmClobberNoReg {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
// eager translation as `span_labels` takes `AsRef<str>` // eager translation as `span_labels` takes `AsRef<str>`
let lbl1 = dcx.eagerly_translate_to_string( let lbl1 = dcx.eagerly_translate_to_string(
crate::fluent_generated::builtin_macros_asm_clobber_abi, crate::fluent_generated::builtin_macros_asm_clobber_abi,

View file

@ -1,4 +1,4 @@
use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_errors::{Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::Span; use rustc_span::Span;
@ -89,8 +89,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
#[help(codegen_gcc_missing_features)] #[help(codegen_gcc_missing_features)]
pub(crate) struct MissingFeatures; pub(crate) struct MissingFeatures;
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable); let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable);
if let Some(span) = self.span { if let Some(span) = self.span {
diag.span(span); diag.span(span);

View file

@ -4,7 +4,7 @@ use std::path::Path;
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::small_c_str::SmallCStr;
use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_errors::{Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::Span; use rustc_span::Span;
@ -99,9 +99,9 @@ pub(crate) struct DynamicLinkingWithLTO;
pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>); pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> { impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let diag: Diag<'_, G> = self.0.into_diagnostic(dcx, level); let diag: Diag<'_, G> = self.0.into_diag(dcx, level);
let (message, _) = diag.messages.first().expect("`LlvmError` with no message"); let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args.iter()); let message = dcx.eagerly_translate_to_string(message.clone(), diag.args.iter());
Diag::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config) Diag::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
@ -119,8 +119,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
#[help(codegen_llvm_missing_features)] #[help(codegen_llvm_missing_features)]
pub(crate) struct MissingFeatures; pub(crate) struct MissingFeatures;
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::codegen_llvm_target_feature_disable_or_enable); let mut diag = Diag::new(dcx, level, fluent::codegen_llvm_target_feature_disable_or_enable);
if let Some(span) = self.span { if let Some(span) = self.span {
diag.span(span); diag.span(span);
@ -179,8 +179,8 @@ pub enum LlvmError<'a> {
pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String); pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> { impl<G: EmissionGuarantee> Diagnostic<'_, G> for WithLlvmError<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
use LlvmError::*; use LlvmError::*;
let msg_with_llvm_err = match &self.0 { let msg_with_llvm_err = match &self.0 {
WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err, WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err,
@ -198,7 +198,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err, ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
}; };
self.0 self.0
.into_diagnostic(dcx, level) .into_diag(dcx, level)
.with_primary_message(msg_with_llvm_err) .with_primary_message(msg_with_llvm_err)
.with_arg("llvm_err", self.1) .with_arg("llvm_err", self.1)
} }

View file

@ -27,7 +27,7 @@ use crate::errors;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::unord::UnordMap; use rustc_data_structures::unord::UnordMap;
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::mir::mono::CodegenUnitNameBuilder; use rustc_middle::mir::mono::CodegenUnitNameBuilder;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -205,8 +205,8 @@ impl fmt::Display for CguReuse {
} }
} }
impl IntoDiagnosticArg for CguReuse { impl IntoDiagArg for CguReuse {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.to_string())) DiagArgValue::Str(Cow::Owned(self.to_string()))
} }
} }

View file

@ -4,8 +4,7 @@ use crate::assert_module_sources::CguReuse;
use crate::back::command::Command; use crate::back::command::Command;
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::{ use rustc_errors::{
codes::*, Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, codes::*, Diag, DiagArgValue, DiagCtxt, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
Level,
}; };
use rustc_macros::Diagnostic; use rustc_macros::Diagnostic;
use rustc_middle::ty::layout::LayoutError; use rustc_middle::ty::layout::LayoutError;
@ -152,8 +151,8 @@ impl<'a> CopyPath<'a> {
struct DebugArgPath<'a>(pub &'a Path); struct DebugArgPath<'a>(pub &'a Path);
impl IntoDiagnosticArg for DebugArgPath<'_> { impl IntoDiagArg for DebugArgPath<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
DiagArgValue::Str(Cow::Owned(format!("{:?}", self.0))) DiagArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
} }
} }
@ -215,8 +214,8 @@ pub enum LinkRlibError {
pub struct ThorinErrorWrapper(pub thorin::Error); pub struct ThorinErrorWrapper(pub thorin::Error);
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper { impl<G: EmissionGuarantee> Diagnostic<'_, G> for ThorinErrorWrapper {
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
let build = |msg| Diag::new(dcx, level, msg); let build = |msg| Diag::new(dcx, level, msg);
match self.0 { match self.0 {
thorin::Error::ReadInput(_) => build(fluent::codegen_ssa_thorin_read_input_failure), thorin::Error::ReadInput(_) => build(fluent::codegen_ssa_thorin_read_input_failure),
@ -348,8 +347,8 @@ pub struct LinkingFailed<'a> {
pub escaped_output: String, pub escaped_output: String,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for LinkingFailed<'_> { impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_linking_failed); let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_linking_failed);
diag.arg("linker_path", format!("{}", self.linker_path.display())); diag.arg("linker_path", format!("{}", self.linker_path.display()));
diag.arg("exit_status", format!("{}", self.exit_status)); diag.arg("exit_status", format!("{}", self.exit_status));
@ -974,8 +973,8 @@ pub enum ExpectedPointerMutability {
Not, Not,
} }
impl IntoDiagnosticArg for ExpectedPointerMutability { impl IntoDiagArg for ExpectedPointerMutability {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
match self { match self {
ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")), ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")),
ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")), ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")),

View file

@ -1,6 +1,6 @@
use std::mem; use std::mem;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, IntoDiagnostic, IntoDiagnosticArg}; use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagArg};
use rustc_hir::CRATE_HIR_ID; use rustc_hir::CRATE_HIR_ID;
use rustc_middle::mir::AssertKind; use rustc_middle::mir::AssertKind;
use rustc_middle::query::TyCtxtAt; use rustc_middle::query::TyCtxtAt;
@ -40,10 +40,10 @@ impl MachineStopType for ConstEvalErrKind {
RecursiveStatic | ConstAccessesMutGlobal | ModifiedGlobal => {} RecursiveStatic | ConstAccessesMutGlobal | ModifiedGlobal => {}
AssertFailure(kind) => kind.add_args(adder), AssertFailure(kind) => kind.add_args(adder),
Panic { msg, line, col, file } => { Panic { msg, line, col, file } => {
adder("msg".into(), msg.into_diagnostic_arg()); adder("msg".into(), msg.into_diag_arg());
adder("file".into(), file.into_diagnostic_arg()); adder("file".into(), file.into_diag_arg());
adder("line".into(), line.into_diagnostic_arg()); adder("line".into(), line.into_diag_arg());
adder("col".into(), col.into_diagnostic_arg()); adder("col".into(), col.into_diag_arg());
} }
} }
} }
@ -130,7 +130,7 @@ pub(super) fn report<'tcx, C, F, E>(
where where
C: FnOnce() -> (Span, Vec<FrameNote>), C: FnOnce() -> (Span, Vec<FrameNote>),
F: FnOnce(Span, Vec<FrameNote>) -> E, F: FnOnce(Span, Vec<FrameNote>) -> E,
E: IntoDiagnostic<'tcx>, E: Diagnostic<'tcx>,
{ {
// Special handling for certain errors // Special handling for certain errors
match error { match error {
@ -168,7 +168,7 @@ pub(super) fn lint<'tcx, 'mir, L>(
lint: &'static rustc_session::lint::Lint, lint: &'static rustc_session::lint::Lint,
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L, decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
) where ) where
L: for<'a> rustc_errors::DecorateLint<'a, ()>, L: for<'a> rustc_errors::LintDiagnostic<'a, ()>,
{ {
let (span, frames) = get_span_and_frames(tcx, machine); let (span, frames) = get_span_and_frames(tcx, machine);

View file

@ -1,7 +1,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use rustc_errors::{ use rustc_errors::{
codes::*, Diag, DiagArgValue, DiagCtxt, DiagMessage, EmissionGuarantee, IntoDiagnostic, Level, codes::*, Diag, DiagArgValue, DiagCtxt, DiagMessage, Diagnostic, EmissionGuarantee, Level,
}; };
use rustc_hir::ConstContext; use rustc_hir::ConstContext;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@ -239,7 +239,7 @@ pub(crate) struct NonConstImplNote {
pub span: Span, pub span: Span,
} }
#[derive(Subdiagnostic, PartialEq, Eq, Clone)] #[derive(Subdiagnostic, Clone)]
#[note(const_eval_frame_note)] #[note(const_eval_frame_note)]
pub struct FrameNote { pub struct FrameNote {
#[primary_span] #[primary_span]
@ -858,8 +858,7 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
InvalidProgramInfo::Layout(e) => { InvalidProgramInfo::Layout(e) => {
// The level doesn't matter, `dummy_diag` is consumed without it being used. // The level doesn't matter, `dummy_diag` is consumed without it being used.
let dummy_level = Level::Bug; let dummy_level = Level::Bug;
let dummy_diag: Diag<'_, ()> = let dummy_diag: Diag<'_, ()> = e.into_diagnostic().into_diag(diag.dcx, dummy_level);
e.into_diagnostic().into_diagnostic(diag.dcx, dummy_level);
for (name, val) in dummy_diag.args.iter() { for (name, val) in dummy_diag.args.iter() {
diag.arg(name.clone(), val.clone()); diag.arg(name.clone(), val.clone());
} }
@ -887,8 +886,8 @@ impl ReportErrorExt for ResourceExhaustionInfo {
fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {} fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {}
} }
impl rustc_errors::IntoDiagnosticArg for InternKind { impl rustc_errors::IntoDiagArg for InternKind {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(match self { DiagArgValue::Str(Cow::Borrowed(match self {
InternKind::Static(Mutability::Not) => "static", InternKind::Static(Mutability::Not) => "static",
InternKind::Static(Mutability::Mut) => "static_mut", InternKind::Static(Mutability::Mut) => "static_mut",

View file

@ -38,7 +38,7 @@ pub enum DiagArgValue {
Str(Cow<'static, str>), Str(Cow<'static, str>),
// This gets converted to a `FluentNumber`, which is an `f64`. An `i32` // This gets converted to a `FluentNumber`, which is an `f64`. An `i32`
// safely fits in an `f64`. Any integers bigger than that will be converted // safely fits in an `f64`. Any integers bigger than that will be converted
// to strings in `into_diagnostic_arg` and stored using the `Str` variant. // to strings in `into_diag_arg` and stored using the `Str` variant.
Number(i32), Number(i32),
StrListSepByAnd(Vec<Cow<'static, str>>), StrListSepByAnd(Vec<Cow<'static, str>>),
} }
@ -112,48 +112,48 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
/// When implemented manually, it should be generic over the emission /// When implemented manually, it should be generic over the emission
/// guarantee, i.e.: /// guarantee, i.e.:
/// ```ignore (fragment) /// ```ignore (fragment)
/// impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for Foo { ... } /// impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for Foo { ... }
/// ``` /// ```
/// rather than being specific: /// rather than being specific:
/// ```ignore (fragment) /// ```ignore (fragment)
/// impl<'a> IntoDiagnostic<'a> for Bar { ... } // the default type param is `ErrorGuaranteed` /// impl<'a> Diagnostic<'a> for Bar { ... } // the default type param is `ErrorGuaranteed`
/// impl<'a> IntoDiagnostic<'a, ()> for Baz { ... } /// impl<'a> Diagnostic<'a, ()> for Baz { ... }
/// ``` /// ```
/// There are two reasons for this. /// There are two reasons for this.
/// - A diagnostic like `Foo` *could* be emitted at any level -- `level` is /// - A diagnostic like `Foo` *could* be emitted at any level -- `level` is
/// passed in to `into_diagnostic` from outside. Even if in practice it is /// passed in to `into_diag` from outside. Even if in practice it is
/// always emitted at a single level, we let the diagnostic creation/emission /// always emitted at a single level, we let the diagnostic creation/emission
/// site determine the level (by using `create_err`, `emit_warn`, etc.) /// site determine the level (by using `create_err`, `emit_warn`, etc.)
/// rather than the `IntoDiagnostic` impl. /// rather than the `Diagnostic` impl.
/// - Derived impls are always generic, and it's good for the hand-written /// - Derived impls are always generic, and it's good for the hand-written
/// impls to be consistent with them. /// impls to be consistent with them.
#[rustc_diagnostic_item = "IntoDiagnostic"] #[rustc_diagnostic_item = "Diagnostic"]
pub trait IntoDiagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> { pub trait Diagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> {
/// Write out as a diagnostic out of `DiagCtxt`. /// Write out as a diagnostic out of `DiagCtxt`.
#[must_use] #[must_use]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>; fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>;
} }
impl<'a, T, G> IntoDiagnostic<'a, G> for Spanned<T> impl<'a, T, G> Diagnostic<'a, G> for Spanned<T>
where where
T: IntoDiagnostic<'a, G>, T: Diagnostic<'a, G>,
G: EmissionGuarantee, G: EmissionGuarantee,
{ {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
self.node.into_diagnostic(dcx, level).with_span(self.span) self.node.into_diag(dcx, level).with_span(self.span)
} }
} }
/// Converts a value of a type into a `DiagArg` (typically a field of an `IntoDiagnostic` struct). /// Converts a value of a type into a `DiagArg` (typically a field of an `Diag` struct).
/// Implemented as a custom trait rather than `From` so that it is implemented on the type being /// Implemented as a custom trait rather than `From` so that it is implemented on the type being
/// converted rather than on `DiagArgValue`, which enables types from other `rustc_*` crates to /// converted rather than on `DiagArgValue`, which enables types from other `rustc_*` crates to
/// implement this. /// implement this.
pub trait IntoDiagnosticArg { pub trait IntoDiagArg {
fn into_diagnostic_arg(self) -> DiagArgValue; fn into_diag_arg(self) -> DiagArgValue;
} }
impl IntoDiagnosticArg for DiagArgValue { impl IntoDiagArg for DiagArgValue {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self self
} }
} }
@ -170,19 +170,19 @@ impl Into<FluentValue<'static>> for DiagArgValue {
/// Trait implemented by error types. This should not be implemented manually. Instead, use /// Trait implemented by error types. This should not be implemented manually. Instead, use
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic]. /// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
#[rustc_diagnostic_item = "AddToDiagnostic"] #[rustc_diagnostic_item = "Subdiagnostic"]
pub trait AddToDiagnostic pub trait Subdiagnostic
where where
Self: Sized, Self: Sized,
{ {
/// Add a subdiagnostic to an existing diagnostic. /// Add a subdiagnostic to an existing diagnostic.
fn add_to_diagnostic<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) { fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
self.add_to_diagnostic_with(diag, |_, m| m); self.add_to_diag_with(diag, |_, m| m);
} }
/// Add a subdiagnostic to an existing diagnostic where `f` is invoked on every message used /// Add a subdiagnostic to an existing diagnostic where `f` is invoked on every message used
/// (to optionally perform eager translation). /// (to optionally perform eager translation).
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,
@ -193,8 +193,8 @@ pub trait SubdiagMessageOp<G> = Fn(&mut Diag<'_, G>, SubdiagMessage) -> SubdiagM
/// Trait implemented by lint types. This should not be implemented manually. Instead, use /// Trait implemented by lint types. This should not be implemented manually. Instead, use
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic]. /// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
#[rustc_diagnostic_item = "DecorateLint"] #[rustc_diagnostic_item = "LintDiagnostic"]
pub trait DecorateLint<'a, G: EmissionGuarantee> { pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
/// Decorate and emit a lint. /// Decorate and emit a lint.
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>); fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
@ -419,8 +419,8 @@ impl DiagInner {
self.children.push(sub); self.children.push(sub);
} }
pub(crate) fn arg(&mut self, name: impl Into<DiagArgName>, arg: impl IntoDiagnosticArg) { pub(crate) fn arg(&mut self, name: impl Into<DiagArgName>, arg: impl IntoDiagArg) {
self.args.insert(name.into(), arg.into_diagnostic_arg()); self.args.insert(name.into(), arg.into_diag_arg());
} }
/// Fields used for Hash, and PartialEq trait. /// Fields used for Hash, and PartialEq trait.
@ -482,7 +482,7 @@ pub struct Subdiag {
/// - The `EmissionGuarantee`, which determines the type returned from `emit`. /// - The `EmissionGuarantee`, which determines the type returned from `emit`.
/// ///
/// Each constructed `Diag` must be consumed by a function such as `emit`, /// Each constructed `Diag` must be consumed by a function such as `emit`,
/// `cancel`, `delay_as_bug`, or `into_diagnostic`. A panic occurrs if a `Diag` /// `cancel`, `delay_as_bug`, or `into_diag`. A panic occurrs if a `Diag`
/// is dropped without being consumed by one of these functions. /// is dropped without being consumed by one of these functions.
/// ///
/// If there is some state in a downstream crate you would like to access in /// If there is some state in a downstream crate you would like to access in
@ -1194,9 +1194,9 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn subdiagnostic( pub fn subdiagnostic(
&mut self, &mut self,
dcx: &crate::DiagCtxt, dcx: &crate::DiagCtxt,
subdiagnostic: impl AddToDiagnostic, subdiagnostic: impl Subdiagnostic,
) -> &mut Self { ) -> &mut Self {
subdiagnostic.add_to_diagnostic_with(self, |diag, msg| { subdiagnostic.add_to_diag_with(self, |diag, msg| {
let args = diag.args.iter(); let args = diag.args.iter();
let msg = diag.subdiagnostic_message_to_diagnostic_message(msg); let msg = diag.subdiagnostic_message_to_diagnostic_message(msg);
dcx.eagerly_translate(msg, args) dcx.eagerly_translate(msg, args)
@ -1243,7 +1243,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
pub fn arg( pub fn arg(
&mut self, &mut self,
name: impl Into<DiagArgName>, name: impl Into<DiagArgName>,
arg: impl IntoDiagnosticArg, arg: impl IntoDiagArg,
) -> &mut Self { ) -> &mut Self {
self.deref_mut().arg(name, arg); self.deref_mut().arg(name, arg);
self self

View file

@ -1,8 +1,8 @@
use crate::diagnostic::DiagLocation; use crate::diagnostic::DiagLocation;
use crate::{fluent_generated as fluent, AddToDiagnostic}; use crate::{fluent_generated as fluent, Subdiagnostic};
use crate::{ use crate::{
Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, ErrCode, IntoDiagnostic, IntoDiagnosticArg, Diag, DiagArgValue, DiagCtxt, Diagnostic, EmissionGuarantee, ErrCode, IntoDiagArg, Level,
Level, SubdiagMessageOp, SubdiagMessageOp,
}; };
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
@ -22,9 +22,9 @@ use std::process::ExitStatus;
pub struct DiagArgFromDisplay<'a>(pub &'a dyn fmt::Display); pub struct DiagArgFromDisplay<'a>(pub &'a dyn fmt::Display);
impl IntoDiagnosticArg for DiagArgFromDisplay<'_> { impl IntoDiagArg for DiagArgFromDisplay<'_> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.0.to_string().into_diagnostic_arg() self.0.to_string().into_diag_arg()
} }
} }
@ -40,34 +40,34 @@ impl<'a, T: fmt::Display> From<&'a T> for DiagArgFromDisplay<'a> {
} }
} }
impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T { impl<'a, T: Clone + IntoDiagArg> IntoDiagArg for &'a T {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.clone().into_diagnostic_arg() self.clone().into_diag_arg()
} }
} }
macro_rules! into_diagnostic_arg_using_display { macro_rules! into_diag_arg_using_display {
($( $ty:ty ),+ $(,)?) => { ($( $ty:ty ),+ $(,)?) => {
$( $(
impl IntoDiagnosticArg for $ty { impl IntoDiagArg for $ty {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }
)+ )+
} }
} }
macro_rules! into_diagnostic_arg_for_number { macro_rules! into_diag_arg_for_number {
($( $ty:ty ),+ $(,)?) => { ($( $ty:ty ),+ $(,)?) => {
$( $(
impl IntoDiagnosticArg for $ty { impl IntoDiagArg for $ty {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
// Convert to a string if it won't fit into `Number`. // Convert to a string if it won't fit into `Number`.
if let Ok(n) = TryInto::<i32>::try_into(self) { if let Ok(n) = TryInto::<i32>::try_into(self) {
DiagArgValue::Number(n) DiagArgValue::Number(n)
} else { } else {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }
} }
@ -75,7 +75,7 @@ macro_rules! into_diagnostic_arg_for_number {
} }
} }
into_diagnostic_arg_using_display!( into_diag_arg_using_display!(
ast::ParamKindOrd, ast::ParamKindOrd,
std::io::Error, std::io::Error,
Box<dyn std::error::Error>, Box<dyn std::error::Error>,
@ -92,10 +92,10 @@ into_diagnostic_arg_using_display!(
ErrCode, ErrCode,
); );
into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize); into_diag_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
impl IntoDiagnosticArg for bool { impl IntoDiagArg for bool {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
if self { if self {
DiagArgValue::Str(Cow::Borrowed("true")) DiagArgValue::Str(Cow::Borrowed("true"))
} else { } else {
@ -104,64 +104,64 @@ impl IntoDiagnosticArg for bool {
} }
} }
impl IntoDiagnosticArg for char { impl IntoDiagArg for char {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(format!("{self:?}"))) DiagArgValue::Str(Cow::Owned(format!("{self:?}")))
} }
} }
impl IntoDiagnosticArg for Vec<char> { impl IntoDiagArg for Vec<char> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::StrListSepByAnd( DiagArgValue::StrListSepByAnd(
self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(), self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(),
) )
} }
} }
impl IntoDiagnosticArg for Symbol { impl IntoDiagArg for Symbol {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_ident_string().into_diagnostic_arg() self.to_ident_string().into_diag_arg()
} }
} }
impl<'a> IntoDiagnosticArg for &'a str { impl<'a> IntoDiagArg for &'a str {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }
impl IntoDiagnosticArg for String { impl IntoDiagArg for String {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self)) DiagArgValue::Str(Cow::Owned(self))
} }
} }
impl<'a> IntoDiagnosticArg for Cow<'a, str> { impl<'a> IntoDiagArg for Cow<'a, str> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.into_owned())) DiagArgValue::Str(Cow::Owned(self.into_owned()))
} }
} }
impl<'a> IntoDiagnosticArg for &'a Path { impl<'a> IntoDiagArg for &'a Path {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.display().to_string())) DiagArgValue::Str(Cow::Owned(self.display().to_string()))
} }
} }
impl IntoDiagnosticArg for PathBuf { impl IntoDiagArg for PathBuf {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.display().to_string())) DiagArgValue::Str(Cow::Owned(self.display().to_string()))
} }
} }
impl IntoDiagnosticArg for PanicStrategy { impl IntoDiagArg for PanicStrategy {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.desc().to_string())) DiagArgValue::Str(Cow::Owned(self.desc().to_string()))
} }
} }
impl IntoDiagnosticArg for hir::ConstContext { impl IntoDiagArg for hir::ConstContext {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(match self { DiagArgValue::Str(Cow::Borrowed(match self {
hir::ConstContext::ConstFn => "const_fn", hir::ConstContext::ConstFn => "const_fn",
hir::ConstContext::Static(_) => "static", hir::ConstContext::Static(_) => "static",
@ -170,58 +170,58 @@ impl IntoDiagnosticArg for hir::ConstContext {
} }
} }
impl IntoDiagnosticArg for ast::Expr { impl IntoDiagArg for ast::Expr {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(pprust::expr_to_string(&self))) DiagArgValue::Str(Cow::Owned(pprust::expr_to_string(&self)))
} }
} }
impl IntoDiagnosticArg for ast::Path { impl IntoDiagArg for ast::Path {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(pprust::path_to_string(&self))) DiagArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
} }
} }
impl IntoDiagnosticArg for ast::token::Token { impl IntoDiagArg for ast::token::Token {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(pprust::token_to_string(&self)) DiagArgValue::Str(pprust::token_to_string(&self))
} }
} }
impl IntoDiagnosticArg for ast::token::TokenKind { impl IntoDiagArg for ast::token::TokenKind {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(pprust::token_kind_to_string(&self)) DiagArgValue::Str(pprust::token_kind_to_string(&self))
} }
} }
impl IntoDiagnosticArg for type_ir::FloatTy { impl IntoDiagArg for type_ir::FloatTy {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(self.name_str())) DiagArgValue::Str(Cow::Borrowed(self.name_str()))
} }
} }
impl IntoDiagnosticArg for std::ffi::CString { impl IntoDiagArg for std::ffi::CString {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
} }
} }
impl IntoDiagnosticArg for rustc_data_structures::small_c_str::SmallCStr { impl IntoDiagArg for rustc_data_structures::small_c_str::SmallCStr {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
} }
} }
impl IntoDiagnosticArg for ast::Visibility { impl IntoDiagArg for ast::Visibility {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
let s = pprust::vis_to_string(&self); let s = pprust::vis_to_string(&self);
let s = s.trim_end().to_string(); let s = s.trim_end().to_string();
DiagArgValue::Str(Cow::Owned(s)) DiagArgValue::Str(Cow::Owned(s))
} }
} }
impl IntoDiagnosticArg for rustc_lint_defs::Level { impl IntoDiagArg for rustc_lint_defs::Level {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(self.to_cmd_flag())) DiagArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
} }
} }
@ -235,22 +235,22 @@ impl From<Vec<Symbol>> for DiagSymbolList {
} }
} }
impl IntoDiagnosticArg for DiagSymbolList { impl IntoDiagArg for DiagSymbolList {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::StrListSepByAnd( DiagArgValue::StrListSepByAnd(
self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(), self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(),
) )
} }
} }
impl<Id> IntoDiagnosticArg for hir::def::Res<Id> { impl<Id> IntoDiagArg for hir::def::Res<Id> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(self.descr())) DiagArgValue::Str(Cow::Borrowed(self.descr()))
} }
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_> { impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetDataLayoutErrors<'_> {
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
match self { match self {
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
Diag::new(dcx, level, fluent::errors_target_invalid_address_space) Diag::new(dcx, level, fluent::errors_target_invalid_address_space)
@ -297,8 +297,8 @@ pub struct SingleLabelManySpans {
pub spans: Vec<Span>, pub spans: Vec<Span>,
pub label: &'static str, pub label: &'static str,
} }
impl AddToDiagnostic for SingleLabelManySpans { impl Subdiagnostic for SingleLabelManySpans {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_: F, _: F,
@ -315,20 +315,20 @@ pub struct ExpectedLifetimeParameter {
pub count: usize, pub count: usize,
} }
impl IntoDiagnosticArg for DiagLocation { impl IntoDiagArg for DiagLocation {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::from(self.to_string())) DiagArgValue::Str(Cow::from(self.to_string()))
} }
} }
impl IntoDiagnosticArg for Backtrace { impl IntoDiagArg for Backtrace {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::from(self.to_string())) DiagArgValue::Str(Cow::from(self.to_string()))
} }
} }
impl IntoDiagnosticArg for Level { impl IntoDiagArg for Level {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::from(self.to_string())) DiagArgValue::Str(Cow::from(self.to_string()))
} }
} }
@ -342,8 +342,8 @@ pub struct IndicateAnonymousLifetime {
pub suggestion: String, pub suggestion: String,
} }
impl IntoDiagnosticArg for type_ir::ClosureKind { impl IntoDiagArg for type_ir::ClosureKind {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(self.as_str().into()) DiagArgValue::Str(self.as_str().into())
} }
} }

View file

@ -37,9 +37,9 @@ extern crate self as rustc_errors;
pub use codes::*; pub use codes::*;
pub use diagnostic::{ pub use diagnostic::{
AddToDiagnostic, BugAbort, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, BugAbort, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, DiagInner, DiagStyledString,
DiagInner, DiagStyledString, EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg, Diagnostic, EmissionGuarantee, FatalAbort, IntoDiagArg, LintDiagnostic, StringPart, Subdiag,
StringPart, Subdiag, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
pub use diagnostic_impls::{ pub use diagnostic_impls::{
DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime, DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime,
@ -1134,12 +1134,12 @@ impl DiagCtxt {
} }
#[track_caller] #[track_caller]
pub fn create_bug<'a>(&'a self, bug: impl IntoDiagnostic<'a, BugAbort>) -> Diag<'a, BugAbort> { pub fn create_bug<'a>(&'a self, bug: impl Diagnostic<'a, BugAbort>) -> Diag<'a, BugAbort> {
bug.into_diagnostic(self, Bug) bug.into_diag(self, Bug)
} }
#[track_caller] #[track_caller]
pub fn emit_bug<'a>(&'a self, bug: impl IntoDiagnostic<'a, BugAbort>) -> ! { pub fn emit_bug<'a>(&'a self, bug: impl Diagnostic<'a, BugAbort>) -> ! {
self.create_bug(bug).emit() self.create_bug(bug).emit()
} }
@ -1174,29 +1174,26 @@ impl DiagCtxt {
#[track_caller] #[track_caller]
pub fn create_fatal<'a>( pub fn create_fatal<'a>(
&'a self, &'a self,
fatal: impl IntoDiagnostic<'a, FatalAbort>, fatal: impl Diagnostic<'a, FatalAbort>,
) -> Diag<'a, FatalAbort> { ) -> Diag<'a, FatalAbort> {
fatal.into_diagnostic(self, Fatal) fatal.into_diag(self, Fatal)
} }
#[track_caller] #[track_caller]
pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, FatalAbort>) -> ! { pub fn emit_fatal<'a>(&'a self, fatal: impl Diagnostic<'a, FatalAbort>) -> ! {
self.create_fatal(fatal).emit() self.create_fatal(fatal).emit()
} }
#[track_caller] #[track_caller]
pub fn create_almost_fatal<'a>( pub fn create_almost_fatal<'a>(
&'a self, &'a self,
fatal: impl IntoDiagnostic<'a, FatalError>, fatal: impl Diagnostic<'a, FatalError>,
) -> Diag<'a, FatalError> { ) -> Diag<'a, FatalError> {
fatal.into_diagnostic(self, Fatal) fatal.into_diag(self, Fatal)
} }
#[track_caller] #[track_caller]
pub fn emit_almost_fatal<'a>( pub fn emit_almost_fatal<'a>(&'a self, fatal: impl Diagnostic<'a, FatalError>) -> FatalError {
&'a self,
fatal: impl IntoDiagnostic<'a, FatalError>,
) -> FatalError {
self.create_almost_fatal(fatal).emit() self.create_almost_fatal(fatal).emit()
} }
@ -1234,12 +1231,12 @@ impl DiagCtxt {
} }
#[track_caller] #[track_caller]
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> Diag<'a> { pub fn create_err<'a>(&'a self, err: impl Diagnostic<'a>) -> Diag<'a> {
err.into_diagnostic(self, Error) err.into_diag(self, Error)
} }
#[track_caller] #[track_caller]
pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed { pub fn emit_err<'a>(&'a self, err: impl Diagnostic<'a>) -> ErrorGuaranteed {
self.create_err(err).emit() self.create_err(err).emit()
} }
@ -1297,12 +1294,12 @@ impl DiagCtxt {
} }
#[track_caller] #[track_caller]
pub fn create_warn<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> { pub fn create_warn<'a>(&'a self, warning: impl Diagnostic<'a, ()>) -> Diag<'a, ()> {
warning.into_diagnostic(self, Warning) warning.into_diag(self, Warning)
} }
#[track_caller] #[track_caller]
pub fn emit_warn<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) { pub fn emit_warn<'a>(&'a self, warning: impl Diagnostic<'a, ()>) {
self.create_warn(warning).emit() self.create_warn(warning).emit()
} }
@ -1335,12 +1332,12 @@ impl DiagCtxt {
} }
#[track_caller] #[track_caller]
pub fn create_note<'a>(&'a self, note: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> { pub fn create_note<'a>(&'a self, note: impl Diagnostic<'a, ()>) -> Diag<'a, ()> {
note.into_diagnostic(self, Note) note.into_diag(self, Note)
} }
#[track_caller] #[track_caller]
pub fn emit_note<'a>(&'a self, note: impl IntoDiagnostic<'a, ()>) { pub fn emit_note<'a>(&'a self, note: impl Diagnostic<'a, ()>) {
self.create_note(note).emit() self.create_note(note).emit()
} }

View file

@ -1510,7 +1510,7 @@ impl fmt::Display for ConstContext {
} }
} }
// NOTE: `IntoDiagnosticArg` impl for `ConstContext` lives in `rustc_errors` // NOTE: `IntoDiagArg` impl for `ConstContext` lives in `rustc_errors`
// due to a cyclical dependency between hir that crate. // due to a cyclical dependency between hir that crate.
/// A literal. /// A literal.

View file

@ -2,7 +2,7 @@
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::{ use rustc_errors::{
codes::*, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, MultiSpan, codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level, MultiSpan,
}; };
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
@ -355,10 +355,10 @@ pub struct MissingTypeParams {
pub empty_generic_args: bool, pub empty_generic_args: bool,
} }
// Manual implementation of `IntoDiagnostic` to be able to call `span_to_snippet`. // Manual implementation of `Diagnostic` to be able to call `span_to_snippet`.
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for MissingTypeParams { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingTypeParams {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
let mut err = Diag::new(dcx, level, fluent::hir_analysis_missing_type_params); let mut err = Diag::new(dcx, level, fluent::hir_analysis_missing_type_params);
err.span(self.span); err.span(self.span);
err.code(E0393); err.code(E0393);

View file

@ -3,8 +3,8 @@ use std::borrow::Cow;
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, Diag, DiagArgValue, EmissionGuarantee, codes::*, Applicability, Diag, DiagArgValue, EmissionGuarantee, IntoDiagArg, MultiSpan,
IntoDiagnosticArg, MultiSpan, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
@ -42,8 +42,8 @@ pub enum ReturnLikeStatementKind {
Become, Become,
} }
impl IntoDiagnosticArg for ReturnLikeStatementKind { impl IntoDiagArg for ReturnLikeStatementKind {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
let kind = match self { let kind = match self {
Self::Return => "return", Self::Return => "return",
Self::Become => "become", Self::Become => "become",
@ -194,8 +194,8 @@ pub struct TypeMismatchFruTypo {
pub expr: Option<String>, pub expr: Option<String>,
} }
impl AddToDiagnostic for TypeMismatchFruTypo { impl Subdiagnostic for TypeMismatchFruTypo {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -373,8 +373,8 @@ pub struct RemoveSemiForCoerce {
pub semi: Span, pub semi: Span,
} }
impl AddToDiagnostic for RemoveSemiForCoerce { impl Subdiagnostic for RemoveSemiForCoerce {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -549,8 +549,8 @@ pub enum CastUnknownPointerSub {
From(Span), From(Span),
} }
impl rustc_errors::AddToDiagnostic for CastUnknownPointerSub { impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,

View file

@ -26,8 +26,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::unord::UnordMap; use rustc_data_structures::unord::UnordMap;
use rustc_errors::{ use rustc_errors::{
codes::*, pluralize, struct_span_code_err, AddToDiagnostic, Applicability, Diag, codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, StashKey,
ErrorGuaranteed, StashKey, Subdiagnostic,
}; };
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def::{CtorKind, DefKind, Res};
@ -2600,7 +2600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We know by construction that `<expr>.await` is either on Rust 2015 // We know by construction that `<expr>.await` is either on Rust 2015
// or results in `ExprKind::Await`. Suggest switching the edition to 2018. // or results in `ExprKind::Await`. Suggest switching the edition to 2018.
err.note("to `.await` a `Future`, switch to Rust 2018 or later"); err.note("to `.await` a `Future`, switch to Rust 2018 or later");
HelpUseLatestEdition::new().add_to_diagnostic(&mut err); HelpUseLatestEdition::new().add_to_diag(&mut err);
} }
err.emit() err.emit()

View file

@ -1,7 +1,7 @@
use hir::GenericParamKind; use hir::GenericParamKind;
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, Diag, DiagMessage, DiagStyledString, codes::*, Applicability, Diag, DiagMessage, DiagStyledString, EmissionGuarantee, IntoDiagArg,
EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagMessageOp, MultiSpan, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::FnRetTy; use rustc_hir::FnRetTy;
@ -224,8 +224,8 @@ pub enum RegionOriginNote<'a> {
}, },
} }
impl AddToDiagnostic for RegionOriginNote<'_> { impl Subdiagnostic for RegionOriginNote<'_> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -289,8 +289,8 @@ pub enum LifetimeMismatchLabels {
}, },
} }
impl AddToDiagnostic for LifetimeMismatchLabels { impl Subdiagnostic for LifetimeMismatchLabels {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -337,8 +337,8 @@ pub struct AddLifetimeParamsSuggestion<'a> {
pub add_note: bool, pub add_note: bool,
} }
impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> { impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -439,8 +439,8 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq {
pub binding_span: Span, pub binding_span: Span,
} }
impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { impl Subdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
mut self, mut self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -537,11 +537,11 @@ pub enum TyOrSig<'tcx> {
ClosureSig(Highlighted<'tcx, Binder<'tcx, FnSig<'tcx>>>), ClosureSig(Highlighted<'tcx, Binder<'tcx, FnSig<'tcx>>>),
} }
impl IntoDiagnosticArg for TyOrSig<'_> { impl IntoDiagArg for TyOrSig<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
match self { match self {
TyOrSig::Ty(ty) => ty.into_diagnostic_arg(), TyOrSig::Ty(ty) => ty.into_diag_arg(),
TyOrSig::ClosureSig(sig) => sig.into_diagnostic_arg(), TyOrSig::ClosureSig(sig) => sig.into_diag_arg(),
} }
} }
} }
@ -758,8 +758,8 @@ pub struct ConsiderBorrowingParamHelp {
pub spans: Vec<Span>, pub spans: Vec<Span>,
} }
impl AddToDiagnostic for ConsiderBorrowingParamHelp { impl Subdiagnostic for ConsiderBorrowingParamHelp {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,
@ -803,8 +803,8 @@ pub struct DynTraitConstraintSuggestion {
pub ident: Ident, pub ident: Ident,
} }
impl AddToDiagnostic for DynTraitConstraintSuggestion { impl Subdiagnostic for DynTraitConstraintSuggestion {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,
@ -850,8 +850,8 @@ pub struct ReqIntroducedLocations {
pub add_label: bool, pub add_label: bool,
} }
impl AddToDiagnostic for ReqIntroducedLocations { impl Subdiagnostic for ReqIntroducedLocations {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
mut self, mut self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,
@ -873,8 +873,8 @@ pub struct MoreTargeted {
pub ident: Symbol, pub ident: Symbol,
} }
impl AddToDiagnostic for MoreTargeted { impl Subdiagnostic for MoreTargeted {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -1296,8 +1296,8 @@ pub struct SuggestTuplePatternMany {
pub compatible_variants: Vec<String>, pub compatible_variants: Vec<String>,
} }
impl AddToDiagnostic for SuggestTuplePatternMany { impl Subdiagnostic for SuggestTuplePatternMany {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,

View file

@ -1,6 +1,6 @@
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use crate::infer::error_reporting::nice_region_error::find_anon_type; use crate::infer::error_reporting::nice_region_error::find_anon_type;
use rustc_errors::{AddToDiagnostic, Diag, EmissionGuarantee, IntoDiagnosticArg, SubdiagMessageOp}; use rustc_errors::{Diag, EmissionGuarantee, IntoDiagArg, SubdiagMessageOp, Subdiagnostic};
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{symbol::kw, Span}; use rustc_span::{symbol::kw, Span};
@ -107,8 +107,8 @@ pub enum SuffixKind {
ReqByBinding, ReqByBinding,
} }
impl IntoDiagnosticArg for PrefixKind { impl IntoDiagArg for PrefixKind {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
let kind = match self { let kind = match self {
Self::Empty => "empty", Self::Empty => "empty",
Self::RefValidFor => "ref_valid_for", Self::RefValidFor => "ref_valid_for",
@ -129,8 +129,8 @@ impl IntoDiagnosticArg for PrefixKind {
} }
} }
impl IntoDiagnosticArg for SuffixKind { impl IntoDiagArg for SuffixKind {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
let kind = match self { let kind = match self {
Self::Empty => "empty", Self::Empty => "empty",
Self::Continues => "continues", Self::Continues => "continues",
@ -159,8 +159,8 @@ impl RegionExplanation<'_> {
} }
} }
impl AddToDiagnostic for RegionExplanation<'_> { impl Subdiagnostic for RegionExplanation<'_> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,

View file

@ -61,7 +61,7 @@ use crate::traits::{
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_errors::{ use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString, codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString,
ErrorGuaranteed, IntoDiagnosticArg, ErrorGuaranteed, IntoDiagArg,
}; };
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
@ -2895,11 +2895,11 @@ impl<'tcx> ObligationCause<'tcx> {
} }
} }
/// Newtype to allow implementing IntoDiagnosticArg /// Newtype to allow implementing IntoDiagArg
pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>); pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>);
impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> { impl IntoDiagArg for ObligationCauseAsDiagArg<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
use crate::traits::ObligationCauseCode::*; use crate::traits::ObligationCauseCode::*;
let kind = match self.0.code() { let kind = match self.0.code() {
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat", CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat",

View file

@ -5,7 +5,7 @@ use crate::errors::{
use crate::infer::error_reporting::TypeErrCtxt; use crate::infer::error_reporting::TypeErrCtxt;
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::InferCtxt; use crate::infer::InferCtxt;
use rustc_errors::{codes::*, Diag, IntoDiagnosticArg}; use rustc_errors::{codes::*, Diag, IntoDiagArg};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::def::{CtorOf, DefKind, Namespace}; use rustc_hir::def::{CtorOf, DefKind, Namespace};
@ -133,8 +133,8 @@ impl InferenceDiagnosticsParentData {
} }
} }
impl IntoDiagnosticArg for UnderspecifiedArgKind { impl IntoDiagArg for UnderspecifiedArgKind {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
let kind = match self { let kind = match self {
Self::Type { .. } => "type", Self::Type { .. } => "type",
Self::Const { is_parameter: true } => "const_with_param", Self::Const { is_parameter: true } => "const_with_param",

View file

@ -11,7 +11,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::SubregionOrigin; use crate::infer::SubregionOrigin;
use crate::infer::TyCtxt; use crate::infer::TyCtxt;
use rustc_errors::AddToDiagnostic; use rustc_errors::Subdiagnostic;
use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_errors::{Diag, ErrorGuaranteed};
use rustc_hir::Ty; use rustc_hir::Ty;
use rustc_middle::ty::Region; use rustc_middle::ty::Region;
@ -145,5 +145,5 @@ pub fn suggest_adding_lifetime_params<'tcx>(
err: &mut Diag<'_>, err: &mut Diag<'_>,
) { ) {
let suggestion = AddLifetimeParamsSuggestion { tcx, sub, ty_sup, ty_sub, add_note: false }; let suggestion = AddLifetimeParamsSuggestion { tcx, sub, ty_sup, ty_sub, add_note: false };
suggestion.add_to_diagnostic(err); suggestion.add_to_diag(err);
} }

View file

@ -8,7 +8,7 @@ use crate::infer::ValuePairs;
use crate::infer::{SubregionOrigin, TypeTrace}; use crate::infer::{SubregionOrigin, TypeTrace};
use crate::traits::{ObligationCause, ObligationCauseCode}; use crate::traits::{ObligationCause, ObligationCauseCode};
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_errors::{Diag, IntoDiagnosticArg}; use rustc_errors::{Diag, IntoDiagArg};
use rustc_hir::def::Namespace; use rustc_hir::def::Namespace;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::error::ExpectedFound;
@ -26,11 +26,11 @@ pub struct Highlighted<'tcx, T> {
value: T, value: T,
} }
impl<'tcx, T> IntoDiagnosticArg for Highlighted<'tcx, T> impl<'tcx, T> IntoDiagArg for Highlighted<'tcx, T>
where where
T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>>, T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>>,
{ {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
rustc_errors::DiagArgValue::Str(self.to_string().into()) rustc_errors::DiagArgValue::Str(self.to_string().into())
} }
} }

View file

@ -9,7 +9,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::{SubregionOrigin, TypeTrace}; use crate::infer::{SubregionOrigin, TypeTrace};
use crate::traits::{ObligationCauseCode, UnifyReceiverContext}; use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{AddToDiagnostic, Applicability, Diag, ErrorGuaranteed, MultiSpan}; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, Subdiagnostic};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::intravisit::{walk_ty, Visitor};
use rustc_hir::{ use rustc_hir::{
@ -234,7 +234,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if let (Some(ident), true) = (override_error_code, fn_returns.is_empty()) { if let (Some(ident), true) = (override_error_code, fn_returns.is_empty()) {
// Provide a more targeted error code and description. // Provide a more targeted error code and description.
let retarget_subdiag = MoreTargeted { ident }; let retarget_subdiag = MoreTargeted { ident };
retarget_subdiag.add_to_diagnostic(&mut err); retarget_subdiag.add_to_diag(&mut err);
} }
let arg = match param.param.pat.simple_ident() { let arg = match param.param.pat.simple_ident() {
@ -532,7 +532,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
hir_v.visit_ty(self_ty); hir_v.visit_ty(self_ty);
for &span in &traits { for &span in &traits {
let subdiag = DynTraitConstraintSuggestion { span, ident }; let subdiag = DynTraitConstraintSuggestion { span, ident };
subdiag.add_to_diagnostic(err); subdiag.add_to_diag(err);
suggested = true; suggested = true;
} }
} }

View file

@ -5,7 +5,7 @@ use crate::errors::{
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt}; use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt};
use crate::infer::{self, SubregionOrigin}; use crate::infer::{self, SubregionOrigin};
use rustc_errors::{AddToDiagnostic, Diag}; use rustc_errors::{Diag, Subdiagnostic};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::traits::ObligationCauseCode; use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
@ -22,13 +22,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
requirement: ObligationCauseAsDiagArg(trace.cause.clone()), requirement: ObligationCauseAsDiagArg(trace.cause.clone()),
expected_found: self.values_str(trace.values).map(|(e, f, _)| (e, f)), expected_found: self.values_str(trace.values).map(|(e, f, _)| (e, f)),
} }
.add_to_diagnostic(err), .add_to_diag(err),
infer::Reborrow(span) => { infer::Reborrow(span) => {
RegionOriginNote::Plain { span, msg: fluent::infer_reborrow }.add_to_diagnostic(err) RegionOriginNote::Plain { span, msg: fluent::infer_reborrow }.add_to_diag(err)
} }
infer::RelateObjectBound(span) => { infer::RelateObjectBound(span) => {
RegionOriginNote::Plain { span, msg: fluent::infer_relate_object_bound } RegionOriginNote::Plain { span, msg: fluent::infer_relate_object_bound }
.add_to_diagnostic(err); .add_to_diag(err);
} }
infer::ReferenceOutlivesReferent(ty, span) => { infer::ReferenceOutlivesReferent(ty, span) => {
RegionOriginNote::WithName { RegionOriginNote::WithName {
@ -37,7 +37,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
name: &self.ty_to_string(ty), name: &self.ty_to_string(ty),
continues: false, continues: false,
} }
.add_to_diagnostic(err); .add_to_diag(err);
} }
infer::RelateParamBound(span, ty, opt_span) => { infer::RelateParamBound(span, ty, opt_span) => {
RegionOriginNote::WithName { RegionOriginNote::WithName {
@ -46,19 +46,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
name: &self.ty_to_string(ty), name: &self.ty_to_string(ty),
continues: opt_span.is_some(), continues: opt_span.is_some(),
} }
.add_to_diagnostic(err); .add_to_diag(err);
if let Some(span) = opt_span { if let Some(span) = opt_span {
RegionOriginNote::Plain { span, msg: fluent::infer_relate_param_bound_2 } RegionOriginNote::Plain { span, msg: fluent::infer_relate_param_bound_2 }
.add_to_diagnostic(err); .add_to_diag(err);
} }
} }
infer::RelateRegionParamBound(span) => { infer::RelateRegionParamBound(span) => {
RegionOriginNote::Plain { span, msg: fluent::infer_relate_region_param_bound } RegionOriginNote::Plain { span, msg: fluent::infer_relate_region_param_bound }
.add_to_diagnostic(err); .add_to_diag(err);
} }
infer::CompareImplItemObligation { span, .. } => { infer::CompareImplItemObligation { span, .. } => {
RegionOriginNote::Plain { span, msg: fluent::infer_compare_impl_item_obligation } RegionOriginNote::Plain { span, msg: fluent::infer_compare_impl_item_obligation }
.add_to_diagnostic(err); .add_to_diag(err);
} }
infer::CheckAssociatedTypeBounds { ref parent, .. } => { infer::CheckAssociatedTypeBounds { ref parent, .. } => {
self.note_region_origin(err, parent); self.note_region_origin(err, parent);
@ -68,7 +68,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span, span,
msg: fluent::infer_ascribe_user_type_prove_predicate, msg: fluent::infer_ascribe_user_type_prove_predicate,
} }
.add_to_diagnostic(err); .add_to_diag(err);
} }
} }
} }

View file

@ -186,7 +186,7 @@ lint_deprecated_lint_name =
.help = change it to {$replace} .help = change it to {$replace}
lint_diag_out_of_impl = lint_diag_out_of_impl =
diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
lint_drop_glue = lint_drop_glue =
types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped types that do not implement `Drop` can still have drop glue, consider instead using `{$needs_drop}` to detect whether a type is trivially dropped

View file

@ -44,7 +44,7 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_ast::visit::{FnCtxt, FnKind}; use rustc_ast::visit::{FnCtxt, FnKind};
use rustc_ast::{self as ast, *}; use rustc_ast::{self as ast, *};
use rustc_ast_pretty::pprust::{self, expr_to_string}; use rustc_ast_pretty::pprust::{self, expr_to_string};
use rustc_errors::{Applicability, DecorateLint, MultiSpan}; use rustc_errors::{Applicability, LintDiagnostic, MultiSpan};
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability}; use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
@ -327,7 +327,7 @@ impl UnsafeCode {
&self, &self,
cx: &EarlyContext<'_>, cx: &EarlyContext<'_>,
span: Span, span: Span,
decorate: impl for<'a> DecorateLint<'a, ()>, decorate: impl for<'a> LintDiagnostic<'a, ()>,
) { ) {
// This comes from a macro that has `#[allow_internal_unsafe]`. // This comes from a macro that has `#[allow_internal_unsafe]`.
if span.allows_unsafe() { if span.allows_unsafe() {

View file

@ -21,7 +21,7 @@ use crate::passes::{EarlyLintPassObject, LateLintPassObject};
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync; use rustc_data_structures::sync;
use rustc_data_structures::unord::UnordMap; use rustc_data_structures::unord::UnordMap;
use rustc_errors::{DecorateLint, Diag, DiagMessage, MultiSpan}; use rustc_errors::{Diag, DiagMessage, LintDiagnostic, MultiSpan};
use rustc_feature::Features; use rustc_feature::Features;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Res; use rustc_hir::def::Res;
@ -563,13 +563,13 @@ pub trait LintContext {
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>), decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
); );
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, /// Emit a lint at `span` from a lint struct (some type that implements `LintDiagnostic`,
/// typically generated by `#[derive(LintDiagnostic)]`). /// typically generated by `#[derive(LintDiagnostic)]`).
fn emit_span_lint<S: Into<MultiSpan>>( fn emit_span_lint<S: Into<MultiSpan>>(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: S, span: S,
decorator: impl for<'a> DecorateLint<'a, ()>, decorator: impl for<'a> LintDiagnostic<'a, ()>,
) { ) {
self.opt_span_lint(lint, Some(span), decorator.msg(), |diag| { self.opt_span_lint(lint, Some(span), decorator.msg(), |diag| {
decorator.decorate_lint(diag); decorator.decorate_lint(diag);
@ -590,9 +590,9 @@ pub trait LintContext {
self.opt_span_lint(lint, Some(span), msg, decorate); self.opt_span_lint(lint, Some(span), msg, decorate);
} }
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically /// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
/// generated by `#[derive(LintDiagnostic)]`). /// generated by `#[derive(LintDiagnostic)]`).
fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> DecorateLint<'a, ()>) { fn emit_lint(&self, lint: &'static Lint, decorator: impl for<'a> LintDiagnostic<'a, ()>) {
self.opt_span_lint(lint, None as Option<Span>, decorator.msg(), |diag| { self.opt_span_lint(lint, None as Option<Span>, decorator.msg(), |diag| {
decorator.decorate_lint(diag); decorator.decorate_lint(diag);
}); });

View file

@ -1,5 +1,5 @@
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::{codes::*, AddToDiagnostic, Diag, EmissionGuarantee, SubdiagMessageOp}; use rustc_errors::{codes::*, Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::lint::Level; use rustc_session::lint::Level;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
@ -23,8 +23,8 @@ pub enum OverruledAttributeSub {
CommandLineSource, CommandLineSource,
} }
impl AddToDiagnostic for OverruledAttributeSub { impl Subdiagnostic for OverruledAttributeSub {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,

View file

@ -351,15 +351,14 @@ declare_tool_lint! {
declare_tool_lint! { declare_tool_lint! {
/// The `diagnostic_outside_of_impl` lint detects calls to functions annotated with /// The `diagnostic_outside_of_impl` lint detects calls to functions annotated with
/// `#[rustc_lint_diagnostics]` that are outside an `IntoDiagnostic`, `AddToDiagnostic`, or /// `#[rustc_lint_diagnostics]` that are outside an `Diagnostic`, `Subdiagnostic`, or
/// `DecorateLint` impl, or a `#[derive(Diagnostic)]`, `#[derive(Subdiagnostic)]`, /// `LintDiagnostic` impl (either hand-written or derived).
/// `#[derive(DecorateLint)]` expansion.
/// ///
/// More details on diagnostics implementations can be found /// More details on diagnostics implementations can be found
/// [here](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html). /// [here](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html).
pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL, pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL,
Deny, Deny,
"prevent creation of diagnostics outside of `IntoDiagnostic`/`AddToDiagnostic` impls", "prevent diagnostic creation outside of `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls",
report_in_external_macro: true report_in_external_macro: true
} }
@ -455,7 +454,7 @@ impl LateLintPass<'_> for Diagnostics {
} }
// Calls to `#[rustc_lint_diagnostics]`-marked functions should only occur: // Calls to `#[rustc_lint_diagnostics]`-marked functions should only occur:
// - inside an impl of `IntoDiagnostic`, `AddToDiagnostic`, or `DecorateLint`, or // - inside an impl of `Diagnostic`, `Subdiagnostic`, or `LintDiagnostic`, or
// - inside a parent function that is itself marked with `#[rustc_lint_diagnostics]`. // - inside a parent function that is itself marked with `#[rustc_lint_diagnostics]`.
// //
// Otherwise, emit a `DIAGNOSTIC_OUTSIDE_OF_IMPL` lint. // Otherwise, emit a `DIAGNOSTIC_OUTSIDE_OF_IMPL` lint.
@ -467,10 +466,7 @@ impl LateLintPass<'_> for Diagnostics {
&& let Impl { of_trait: Some(of_trait), .. } = impl_ && let Impl { of_trait: Some(of_trait), .. } = impl_
&& let Some(def_id) = of_trait.trait_def_id() && let Some(def_id) = of_trait.trait_def_id()
&& let Some(name) = cx.tcx.get_diagnostic_name(def_id) && let Some(name) = cx.tcx.get_diagnostic_name(def_id)
&& matches!( && matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::LintDiagnostic)
name,
sym::IntoDiagnostic | sym::AddToDiagnostic | sym::DecorateLint
)
{ {
is_inside_appropriate_impl = true; is_inside_appropriate_impl = true;
break; break;

View file

@ -16,7 +16,7 @@ use crate::{
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::{DecorateLint, Diag, DiagMessage, MultiSpan}; use rustc_errors::{Diag, DiagMessage, LintDiagnostic, MultiSpan};
use rustc_feature::{Features, GateIssue}; use rustc_feature::{Features, GateIssue};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
@ -1119,7 +1119,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
&self, &self,
lint: &'static Lint, lint: &'static Lint,
span: MultiSpan, span: MultiSpan,
decorate: impl for<'a> DecorateLint<'a, ()>, decorate: impl for<'a> LintDiagnostic<'a, ()>,
) { ) {
let (level, src) = self.lint_level(lint); let (level, src) = self.lint_level(lint);
lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| { lint_level(self.sess, lint, level, src, Some(span), decorate.msg(), |lint| {
@ -1128,7 +1128,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
} }
#[track_caller] #[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) { pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> LintDiagnostic<'a, ()>) {
let (level, src) = self.lint_level(lint); let (level, src) = self.lint_level(lint);
lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| { lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {
decorate.decorate_lint(lint); decorate.decorate_lint(lint);

View file

@ -5,8 +5,8 @@ use std::num::NonZero;
use crate::errors::RequestedLevel; use crate::errors::RequestedLevel;
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, DecorateLint, Diag, DiagMessage, DiagStyledString, codes::*, Applicability, Diag, DiagMessage, DiagStyledString, EmissionGuarantee,
EmissionGuarantee, SubdiagMessageOp, SuggestionStyle, LintDiagnostic, SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
}; };
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_macros::{LintDiagnostic, Subdiagnostic}; use rustc_macros::{LintDiagnostic, Subdiagnostic};
@ -136,7 +136,7 @@ pub struct BuiltinMissingDebugImpl<'a> {
} }
// Needed for def_path_str // Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> { impl<'a> LintDiagnostic<'a, ()> for BuiltinMissingDebugImpl<'_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
diag.arg("debug", self.tcx.def_path_str(self.def_id)); diag.arg("debug", self.tcx.def_path_str(self.def_id));
} }
@ -241,7 +241,7 @@ pub struct BuiltinUngatedAsyncFnTrackCaller<'a> {
pub session: &'a Session, pub session: &'a Session,
} }
impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> { impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.span_label(self.label, fluent::lint_label); diag.span_label(self.label, fluent::lint_label);
rustc_session::parse::add_feature_diagnostics( rustc_session::parse::add_feature_diagnostics(
@ -270,8 +270,8 @@ pub struct SuggestChangingAssocTypes<'a, 'b> {
pub ty: &'a rustc_hir::Ty<'b>, pub ty: &'a rustc_hir::Ty<'b>,
} }
impl<'a, 'b> AddToDiagnostic for SuggestChangingAssocTypes<'a, 'b> { impl<'a, 'b> Subdiagnostic for SuggestChangingAssocTypes<'a, 'b> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -326,8 +326,8 @@ pub struct BuiltinTypeAliasGenericBoundsSuggestion {
pub suggestions: Vec<(Span, String)>, pub suggestions: Vec<(Span, String)>,
} }
impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion { impl Subdiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -423,7 +423,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> {
pub tcx: TyCtxt<'a>, pub tcx: TyCtxt<'a>,
} }
impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> { impl<'a> LintDiagnostic<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("ty", self.ty); diag.arg("ty", self.ty);
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label); diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
@ -434,7 +434,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
fluent::lint_builtin_unpermitted_type_init_label_suggestion, fluent::lint_builtin_unpermitted_type_init_label_suggestion,
); );
} }
self.sub.add_to_diagnostic(diag); self.sub.add_to_diag(diag);
} }
fn msg(&self) -> DiagMessage { fn msg(&self) -> DiagMessage {
@ -447,8 +447,8 @@ pub struct BuiltinUnpermittedTypeInitSub {
pub err: InitError, pub err: InitError,
} }
impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub { impl Subdiagnostic for BuiltinUnpermittedTypeInitSub {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -502,8 +502,8 @@ pub struct BuiltinClashingExternSub<'a> {
pub found: Ty<'a>, pub found: Ty<'a>,
} }
impl AddToDiagnostic for BuiltinClashingExternSub<'_> { impl Subdiagnostic for BuiltinClashingExternSub<'_> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -784,8 +784,8 @@ pub struct HiddenUnicodeCodepointsDiagLabels {
pub spans: Vec<(char, Span)>, pub spans: Vec<(char, Span)>,
} }
impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels { impl Subdiagnostic for HiddenUnicodeCodepointsDiagLabels {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -802,8 +802,8 @@ pub enum HiddenUnicodeCodepointsDiagSub {
} }
// Used because of multiple multipart_suggestion and note // Used because of multiple multipart_suggestion and note
impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub { impl Subdiagnostic for HiddenUnicodeCodepointsDiagSub {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -950,8 +950,8 @@ pub struct NonBindingLetSub {
pub is_assign_desugar: bool, pub is_assign_desugar: bool,
} }
impl AddToDiagnostic for NonBindingLetSub { impl Subdiagnostic for NonBindingLetSub {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -1159,7 +1159,7 @@ pub struct NonFmtPanicUnused {
} }
// Used because of two suggestions based on one Option<Span> // Used because of two suggestions based on one Option<Span>
impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused { impl<'a> LintDiagnostic<'a, ()> for NonFmtPanicUnused {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("count", self.count); diag.arg("count", self.count);
diag.note(fluent::lint_note); diag.note(fluent::lint_note);
@ -1236,8 +1236,8 @@ pub enum NonSnakeCaseDiagSub {
SuggestionAndNote { span: Span }, SuggestionAndNote { span: Span },
} }
impl AddToDiagnostic for NonSnakeCaseDiagSub { impl Subdiagnostic for NonSnakeCaseDiagSub {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -1397,7 +1397,7 @@ pub struct DropTraitConstraintsDiag<'a> {
} }
// Needed for def_path_str // Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> { impl<'a> LintDiagnostic<'a, ()> for DropTraitConstraintsDiag<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("predicate", self.predicate); diag.arg("predicate", self.predicate);
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id)); diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
@ -1414,7 +1414,7 @@ pub struct DropGlue<'a> {
} }
// Needed for def_path_str // Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for DropGlue<'_> { impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("needs_drop", self.tcx.def_path_str(self.def_id)); diag.arg("needs_drop", self.tcx.def_path_str(self.def_id));
} }
@ -1478,8 +1478,8 @@ pub enum OverflowingBinHexSign {
Negative, Negative,
} }
impl AddToDiagnostic for OverflowingBinHexSign { impl Subdiagnostic for OverflowingBinHexSign {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -1689,7 +1689,7 @@ pub struct ImproperCTypes<'a> {
} }
// Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span> // Used because of the complexity of Option<DiagMessage>, DiagMessage, and Option<Span>
impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> { impl<'a> LintDiagnostic<'a, ()> for ImproperCTypes<'_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("ty", self.ty); diag.arg("ty", self.ty);
diag.arg("desc", self.desc); diag.arg("desc", self.desc);
@ -1832,7 +1832,7 @@ pub enum UnusedDefSuggestion {
} }
// Needed because of def_path_str // Needed because of def_path_str
impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> { impl<'a> LintDiagnostic<'a, ()> for UnusedDef<'_, '_> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.arg("pre", self.pre); diag.arg("pre", self.pre);
diag.arg("post", self.post); diag.arg("post", self.post);
@ -1915,7 +1915,7 @@ pub struct AsyncFnInTraitDiag {
pub sugg: Option<Vec<(Span, String)>>, pub sugg: Option<Vec<(Span, String)>>,
} }
impl<'a> DecorateLint<'a, ()> for AsyncFnInTraitDiag { impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.note(fluent::lint_note); diag.note(fluent::lint_note);
if let Some(sugg) = self.sugg { if let Some(sugg) = self.sugg {

View file

@ -10,7 +10,7 @@ use quote::quote;
use syn::spanned::Spanned; use syn::spanned::Spanned;
use synstructure::Structure; use synstructure::Structure;
/// The central struct for constructing the `into_diagnostic` method from an annotated struct. /// The central struct for constructing the `into_diag` method from an annotated struct.
pub(crate) struct DiagnosticDerive<'a> { pub(crate) struct DiagnosticDerive<'a> {
structure: Structure<'a>, structure: Structure<'a>,
} }
@ -72,14 +72,11 @@ impl<'a> DiagnosticDerive<'a> {
// A lifetime of `'a` causes conflicts, but `_sess` is fine. // A lifetime of `'a` causes conflicts, but `_sess` is fine.
let mut imp = structure.gen_impl(quote! { let mut imp = structure.gen_impl(quote! {
gen impl<'_sess, G> gen impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for @Self
rustc_errors::IntoDiagnostic<'_sess, G>
for @Self
where G: rustc_errors::EmissionGuarantee where G: rustc_errors::EmissionGuarantee
{ {
#[track_caller] #[track_caller]
fn into_diagnostic( fn into_diag(
self, self,
dcx: &'_sess rustc_errors::DiagCtxt, dcx: &'_sess rustc_errors::DiagCtxt,
level: rustc_errors::Level level: rustc_errors::Level
@ -156,7 +153,7 @@ impl<'a> LintDiagnosticDerive<'a> {
}); });
let mut imp = structure.gen_impl(quote! { let mut imp = structure.gen_impl(quote! {
gen impl<'__a> rustc_errors::DecorateLint<'__a, ()> for @Self { gen impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for @Self {
#[track_caller] #[track_caller]
fn decorate_lint<'__b>( fn decorate_lint<'__b>(
self, self,

View file

@ -6,7 +6,7 @@ mod utils;
use diagnostic::{DiagnosticDerive, LintDiagnosticDerive}; use diagnostic::{DiagnosticDerive, LintDiagnosticDerive};
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use subdiagnostic::SubdiagnosticDeriveBuilder; use subdiagnostic::SubdiagnosticDerive;
use synstructure::Structure; use synstructure::Structure;
/// Implements `#[derive(Diagnostic)]`, which allows for errors to be specified as a struct, /// Implements `#[derive(Diagnostic)]`, which allows for errors to be specified as a struct,
@ -55,7 +55,7 @@ use synstructure::Structure;
/// ///
/// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`: /// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html> /// <https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html>
pub fn session_diagnostic_derive(mut s: Structure<'_>) -> TokenStream { pub fn diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
s.underscore_const(true); s.underscore_const(true);
DiagnosticDerive::new(s).into_tokens() DiagnosticDerive::new(s).into_tokens()
} }
@ -153,7 +153,7 @@ pub fn lint_diagnostic_derive(mut s: Structure<'_>) -> TokenStream {
/// ///
/// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident }); /// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
/// ``` /// ```
pub fn session_subdiagnostic_derive(mut s: Structure<'_>) -> TokenStream { pub fn subdiagnostic_derive(mut s: Structure<'_>) -> TokenStream {
s.underscore_const(true); s.underscore_const(true);
SubdiagnosticDeriveBuilder::new().into_tokens(s) SubdiagnosticDerive::new().into_tokens(s)
} }

View file

@ -16,13 +16,13 @@ use synstructure::{BindingInfo, Structure, VariantInfo};
use super::utils::SubdiagnosticVariant; use super::utils::SubdiagnosticVariant;
/// The central struct for constructing the `add_to_diagnostic` method from an annotated struct. /// The central struct for constructing the `add_to_diag` method from an annotated struct.
pub(crate) struct SubdiagnosticDeriveBuilder { pub(crate) struct SubdiagnosticDerive {
diag: syn::Ident, diag: syn::Ident,
f: syn::Ident, f: syn::Ident,
} }
impl SubdiagnosticDeriveBuilder { impl SubdiagnosticDerive {
pub(crate) fn new() -> Self { pub(crate) fn new() -> Self {
let diag = format_ident!("diag"); let diag = format_ident!("diag");
let f = format_ident!("f"); let f = format_ident!("f");
@ -86,8 +86,8 @@ impl SubdiagnosticDeriveBuilder {
let diag = &self.diag; let diag = &self.diag;
let f = &self.f; let f = &self.f;
let ret = structure.gen_impl(quote! { let ret = structure.gen_impl(quote! {
gen impl rustc_errors::AddToDiagnostic for @Self { gen impl rustc_errors::Subdiagnostic for @Self {
fn add_to_diagnostic_with<__G, __F>( fn add_to_diag_with<__G, __F>(
self, self,
#diag: &mut rustc_errors::Diag<'_, __G>, #diag: &mut rustc_errors::Diag<'_, __G>,
#f: __F #f: __F
@ -109,7 +109,7 @@ impl SubdiagnosticDeriveBuilder {
/// double mut borrow later on. /// double mut borrow later on.
struct SubdiagnosticDeriveVariantBuilder<'parent, 'a> { struct SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
/// The identifier to use for the generated `Diag` instance. /// The identifier to use for the generated `Diag` instance.
parent: &'parent SubdiagnosticDeriveBuilder, parent: &'parent SubdiagnosticDerive,
/// Info for the current variant (or the type if not an enum). /// Info for the current variant (or the type if not an enum).
variant: &'a VariantInfo<'a>, variant: &'a VariantInfo<'a>,

View file

@ -118,7 +118,7 @@ decl_derive!(
suggestion, suggestion,
suggestion_short, suggestion_short,
suggestion_hidden, suggestion_hidden,
suggestion_verbose)] => diagnostics::session_diagnostic_derive suggestion_verbose)] => diagnostics::diagnostic_derive
); );
decl_derive!( decl_derive!(
[LintDiagnostic, attributes( [LintDiagnostic, attributes(
@ -156,5 +156,5 @@ decl_derive!(
skip_arg, skip_arg,
primary_span, primary_span,
suggestion_part, suggestion_part,
applicability)] => diagnostics::session_subdiagnostic_derive applicability)] => diagnostics::subdiagnostic_derive
); );

View file

@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use rustc_errors::{codes::*, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_errors::{codes::*, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
use rustc_macros::Diagnostic; use rustc_macros::Diagnostic;
use rustc_session::config; use rustc_session::config;
use rustc_span::{sym, Span, Symbol}; use rustc_span::{sym, Span, Symbol};
@ -495,8 +495,8 @@ pub(crate) struct MultipleCandidates {
pub candidates: Vec<PathBuf>, pub candidates: Vec<PathBuf>,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for MultipleCandidates { impl<G: EmissionGuarantee> Diagnostic<'_, G> for MultipleCandidates {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::metadata_multiple_candidates); let mut diag = Diag::new(dcx, level, fluent::metadata_multiple_candidates);
diag.arg("crate_name", self.crate_name); diag.arg("crate_name", self.crate_name);
diag.arg("flavor", self.flavor); diag.arg("flavor", self.flavor);
@ -593,9 +593,9 @@ pub struct InvalidMetadataFiles {
pub crate_rejections: Vec<String>, pub crate_rejections: Vec<String>,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for InvalidMetadataFiles { impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidMetadataFiles {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::metadata_invalid_meta_files); let mut diag = Diag::new(dcx, level, fluent::metadata_invalid_meta_files);
diag.arg("crate_name", self.crate_name); diag.arg("crate_name", self.crate_name);
diag.arg("add_info", self.add_info); diag.arg("add_info", self.add_info);
@ -622,9 +622,9 @@ pub struct CannotFindCrate {
pub is_ui_testing: bool, pub is_ui_testing: bool,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for CannotFindCrate { impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::metadata_cannot_find_crate); let mut diag = Diag::new(dcx, level, fluent::metadata_cannot_find_crate);
diag.arg("crate_name", self.crate_name); diag.arg("crate_name", self.crate_name);
diag.arg("current_crate", self.current_crate); diag.arg("current_crate", self.current_crate);

View file

@ -220,7 +220,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::memmap::Mmap; use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::slice_owned; use rustc_data_structures::owned_slice::slice_owned;
use rustc_data_structures::svh::Svh; use rustc_data_structures::svh::Svh;
use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_fs_util::try_canonicalize; use rustc_fs_util::try_canonicalize;
use rustc_session::config; use rustc_session::config;
use rustc_session::cstore::CrateSource; use rustc_session::cstore::CrateSource;
@ -290,8 +290,8 @@ impl fmt::Display for CrateFlavor {
} }
} }
impl IntoDiagnosticArg for CrateFlavor { impl IntoDiagArg for CrateFlavor {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
match self { match self {
CrateFlavor::Rlib => DiagArgValue::Str(Cow::Borrowed("rlib")), CrateFlavor::Rlib => DiagArgValue::Str(Cow::Borrowed("rlib")),
CrateFlavor::Rmeta => DiagArgValue::Str(Cow::Borrowed("rmeta")), CrateFlavor::Rmeta => DiagArgValue::Str(Cow::Borrowed("rmeta")),

View file

@ -6,7 +6,7 @@ use crate::ty::{layout, tls, Ty, TyCtxt, ValTree};
use rustc_ast_ir::Mutability; use rustc_ast_ir::Mutability;
use rustc_data_structures::sync::Lock; use rustc_data_structures::sync::Lock;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagArg};
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace; use rustc_session::CtfeBacktrace;
use rustc_span::{def_id::DefId, Span, DUMMY_SP}; use rustc_span::{def_id::DefId, Span, DUMMY_SP};
@ -234,8 +234,8 @@ pub enum InvalidMetaKind {
TooBig, TooBig,
} }
impl IntoDiagnosticArg for InvalidMetaKind { impl IntoDiagArg for InvalidMetaKind {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(match self { DiagArgValue::Str(Cow::Borrowed(match self {
InvalidMetaKind::SliceTooBig => "slice_too_big", InvalidMetaKind::SliceTooBig => "slice_too_big",
InvalidMetaKind::TooBig => "too_big", InvalidMetaKind::TooBig => "too_big",
@ -266,10 +266,10 @@ pub struct Misalignment {
pub required: Align, pub required: Align,
} }
macro_rules! impl_into_diagnostic_arg_through_debug { macro_rules! impl_into_diag_arg_through_debug {
($($ty:ty),*$(,)?) => {$( ($($ty:ty),*$(,)?) => {$(
impl IntoDiagnosticArg for $ty { impl IntoDiagArg for $ty {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Owned(format!("{self:?}"))) DiagArgValue::Str(Cow::Owned(format!("{self:?}")))
} }
} }
@ -277,7 +277,7 @@ macro_rules! impl_into_diagnostic_arg_through_debug {
} }
// These types have nice `Debug` output so we can just use them in diagnostics. // These types have nice `Debug` output so we can just use them in diagnostics.
impl_into_diagnostic_arg_through_debug! { impl_into_diag_arg_through_debug! {
AllocId, AllocId,
Pointer<AllocId>, Pointer<AllocId>,
AllocRange, AllocRange,
@ -370,8 +370,8 @@ pub enum PointerKind {
Box, Box,
} }
impl IntoDiagnosticArg for PointerKind { impl IntoDiagArg for PointerKind {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str( DiagArgValue::Str(
match self { match self {
Self::Ref(_) => "ref", Self::Ref(_) => "ref",

View file

@ -100,7 +100,7 @@ macro_rules! err_ub_custom {
msg: || $msg, msg: || $msg,
add_args: Box::new(move |mut set_arg| { add_args: Box::new(move |mut set_arg| {
$($( $($(
set_arg(stringify!($name).into(), rustc_errors::IntoDiagnosticArg::into_diagnostic_arg($name)); set_arg(stringify!($name).into(), rustc_errors::IntoDiagArg::into_diag_arg($name));
)*)? )*)?
}) })
} }

View file

@ -14,7 +14,7 @@ use crate::ty::{AdtDef, InstanceDef, UserTypeAnnotationIndex};
use crate::ty::{GenericArg, GenericArgsRef}; use crate::ty::{GenericArg, GenericArgsRef};
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagArg};
use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind}; use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind};

View file

@ -311,7 +311,7 @@ impl<O> AssertKind<O> {
macro_rules! add { macro_rules! add {
($name: expr, $value: expr) => { ($name: expr, $value: expr) => {
adder($name.into(), $value.into_diagnostic_arg()); adder($name.into(), $value.into_diag_arg());
}; };
} }

View file

@ -9,7 +9,7 @@
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/thir.html //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/thir.html
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::RangeEnd; use rustc_hir::RangeEnd;
@ -676,9 +676,9 @@ impl<'tcx> Pat<'tcx> {
} }
} }
impl<'tcx> IntoDiagnosticArg for Pat<'tcx> { impl<'tcx> IntoDiagArg for Pat<'tcx> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
format!("{self}").into_diagnostic_arg() format!("{self}").into_diag_arg()
} }
} }

View file

@ -1,6 +1,6 @@
use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::ieee::{Double, Single};
use rustc_apfloat::Float; use rustc_apfloat::Float;
use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_target::abi::Size; use rustc_target::abi::Size;
use std::fmt; use std::fmt;
@ -114,10 +114,10 @@ impl std::fmt::Debug for ConstInt {
} }
} }
impl IntoDiagnosticArg for ConstInt { impl IntoDiagArg for ConstInt {
// FIXME this simply uses the Debug impl, but we could probably do better by converting both // FIXME this simply uses the Debug impl, but we could probably do better by converting both
// to an inherent method that returns `Cow`. // to an inherent method that returns `Cow`.
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(format!("{self:?}").into()) DiagArgValue::Str(format!("{self:?}").into())
} }
} }

View file

@ -14,9 +14,9 @@ pub struct UnevaluatedConst<'tcx> {
pub args: GenericArgsRef<'tcx>, pub args: GenericArgsRef<'tcx>,
} }
impl rustc_errors::IntoDiagnosticArg for UnevaluatedConst<'_> { impl rustc_errors::IntoDiagArg for UnevaluatedConst<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
format!("{self:?}").into_diagnostic_arg() format!("{self:?}").into_diag_arg()
} }
} }

View file

@ -43,7 +43,7 @@ use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, WorkerLocal}
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]
use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_errors::{DecorateLint, Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, MultiSpan}; use rustc_errors::{Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, LintDiagnostic, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
@ -2129,7 +2129,7 @@ impl<'tcx> TyCtxt<'tcx> {
T::collect_and_apply(iter, |xs| self.mk_bound_variable_kinds(xs)) T::collect_and_apply(iter, |xs| self.mk_bound_variable_kinds(xs))
} }
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, /// Emit a lint at `span` from a lint struct (some type that implements `LintDiagnostic`,
/// typically generated by `#[derive(LintDiagnostic)]`). /// typically generated by `#[derive(LintDiagnostic)]`).
#[track_caller] #[track_caller]
pub fn emit_node_span_lint( pub fn emit_node_span_lint(
@ -2137,7 +2137,7 @@ impl<'tcx> TyCtxt<'tcx> {
lint: &'static Lint, lint: &'static Lint,
hir_id: HirId, hir_id: HirId,
span: impl Into<MultiSpan>, span: impl Into<MultiSpan>,
decorator: impl for<'a> DecorateLint<'a, ()>, decorator: impl for<'a> LintDiagnostic<'a, ()>,
) { ) {
let msg = decorator.msg(); let msg = decorator.msg();
let (level, src) = self.lint_level_at_node(lint, hir_id); let (level, src) = self.lint_level_at_node(lint, hir_id);
@ -2163,14 +2163,14 @@ impl<'tcx> TyCtxt<'tcx> {
lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate); lint_level(self.sess, lint, level, src, Some(span.into()), msg, decorate);
} }
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically /// Emit a lint from a lint struct (some type that implements `LintDiagnostic`, typically
/// generated by `#[derive(LintDiagnostic)]`). /// generated by `#[derive(LintDiagnostic)]`).
#[track_caller] #[track_caller]
pub fn emit_node_lint( pub fn emit_node_lint(
self, self,
lint: &'static Lint, lint: &'static Lint,
id: HirId, id: HirId,
decorator: impl for<'a> DecorateLint<'a, ()>, decorator: impl for<'a> LintDiagnostic<'a, ()>,
) { ) {
self.node_lint(lint, id, decorator.msg(), |diag| { self.node_lint(lint, id, decorator.msg(), |diag| {
decorator.decorate_lint(diag); decorator.decorate_lint(diag);

View file

@ -11,7 +11,7 @@ use crate::ty::{
}; };
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, Diag, DiagArgValue, IntoDiagnosticArg}; use rustc_errors::{Applicability, Diag, DiagArgValue, IntoDiagArg};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -19,9 +19,9 @@ use rustc_hir::{PredicateOrigin, WherePredicate};
use rustc_span::{BytePos, Span}; use rustc_span::{BytePos, Span};
use rustc_type_ir::TyKind::*; use rustc_type_ir::TyKind::*;
impl<'tcx> IntoDiagnosticArg for Ty<'tcx> { impl<'tcx> IntoDiagArg for Ty<'tcx> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }

View file

@ -9,7 +9,7 @@ use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
use rustc_ast_ir::visit::VisitorResult; use rustc_ast_ir::visit::VisitorResult;
use rustc_ast_ir::walk_visitable_list; use rustc_ast_ir::walk_visitable_list;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
@ -57,9 +57,9 @@ unsafe impl<'tcx> Sync for GenericArg<'tcx> where
{ {
} }
impl<'tcx> IntoDiagnosticArg for GenericArg<'tcx> { impl<'tcx> IntoDiagArg for GenericArg<'tcx> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }

View file

@ -5,7 +5,7 @@ use crate::ty::normalize_erasing_regions::NormalizationError;
use crate::ty::{self, ConstKind, Ty, TyCtxt, TypeVisitableExt}; use crate::ty::{self, ConstKind, Ty, TyCtxt, TypeVisitableExt};
use rustc_error_messages::DiagMessage; use rustc_error_messages::DiagMessage;
use rustc_errors::{ use rustc_errors::{
Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level, Diag, DiagArgValue, DiagCtxt, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
}; };
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -254,9 +254,9 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
} }
} }
impl<'tcx> IntoDiagnosticArg for LayoutError<'tcx> { impl<'tcx> IntoDiagArg for LayoutError<'tcx> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }
@ -1267,14 +1267,14 @@ pub enum FnAbiError<'tcx> {
AdjustForForeignAbi(call::AdjustForForeignAbiError), AdjustForForeignAbi(call::AdjustForForeignAbiError),
} }
impl<'a, 'b, G: EmissionGuarantee> IntoDiagnostic<'a, G> for FnAbiError<'b> { impl<'a, 'b, G: EmissionGuarantee> Diagnostic<'a, G> for FnAbiError<'b> {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
match self { match self {
Self::Layout(e) => e.into_diagnostic().into_diagnostic(dcx, level), Self::Layout(e) => e.into_diagnostic().into_diag(dcx, level),
Self::AdjustForForeignAbi(call::AdjustForForeignAbiError::Unsupported { Self::AdjustForForeignAbi(call::AdjustForForeignAbiError::Unsupported {
arch, arch,
abi, abi,
}) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diagnostic(dcx, level), }) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diag(dcx, level),
} }
} }
} }

View file

@ -1,6 +1,6 @@
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_errors::{DiagArgValue, IntoDiagnosticArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::LangItem; use rustc_hir::LangItem;
use rustc_span::Span; use rustc_span::Span;
@ -120,14 +120,14 @@ impl<'tcx> Predicate<'tcx> {
} }
} }
impl rustc_errors::IntoDiagnosticArg for Predicate<'_> { impl rustc_errors::IntoDiagArg for Predicate<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(self.to_string())) rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(self.to_string()))
} }
} }
impl rustc_errors::IntoDiagnosticArg for Clause<'_> { impl rustc_errors::IntoDiagArg for Clause<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(self.to_string())) rustc_errors::DiagArgValue::Str(std::borrow::Cow::Owned(self.to_string()))
} }
} }
@ -407,9 +407,9 @@ impl<'tcx> PolyTraitRef<'tcx> {
} }
} }
impl<'tcx> IntoDiagnosticArg for TraitRef<'tcx> { impl<'tcx> IntoDiagArg for TraitRef<'tcx> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }
@ -453,9 +453,9 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
} }
} }
impl<'tcx> IntoDiagnosticArg for ExistentialTraitRef<'tcx> { impl<'tcx> IntoDiagArg for ExistentialTraitRef<'tcx> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }

View file

@ -2722,9 +2722,9 @@ where
#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift)] #[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift)]
pub struct TraitRefPrintOnlyTraitPath<'tcx>(ty::TraitRef<'tcx>); pub struct TraitRefPrintOnlyTraitPath<'tcx>(ty::TraitRef<'tcx>);
impl<'tcx> rustc_errors::IntoDiagnosticArg for TraitRefPrintOnlyTraitPath<'tcx> { impl<'tcx> rustc_errors::IntoDiagArg for TraitRefPrintOnlyTraitPath<'tcx> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }
@ -2739,9 +2739,9 @@ impl<'tcx> fmt::Debug for TraitRefPrintOnlyTraitPath<'tcx> {
#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift)] #[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift)]
pub struct TraitRefPrintSugared<'tcx>(ty::TraitRef<'tcx>); pub struct TraitRefPrintSugared<'tcx>(ty::TraitRef<'tcx>);
impl<'tcx> rustc_errors::IntoDiagnosticArg for TraitRefPrintSugared<'tcx> { impl<'tcx> rustc_errors::IntoDiagArg for TraitRefPrintSugared<'tcx> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }

View file

@ -13,7 +13,7 @@ use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
use crate::ty::{List, ParamEnv}; use crate::ty::{List, ParamEnv};
use hir::def::DefKind; use hir::def::DefKind;
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_errors::{DiagArgValue, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan}; use rustc_errors::{DiagArgValue, ErrorGuaranteed, IntoDiagArg, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::LangItem; use rustc_hir::LangItem;
@ -1094,12 +1094,12 @@ impl<'tcx, T: IntoIterator> Binder<'tcx, T> {
} }
} }
impl<'tcx, T> IntoDiagnosticArg for Binder<'tcx, T> impl<'tcx, T> IntoDiagArg for Binder<'tcx, T>
where where
T: IntoDiagnosticArg, T: IntoDiagArg,
{ {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.value.into_diagnostic_arg() self.value.into_diag_arg()
} }
} }
@ -1307,9 +1307,9 @@ impl<'tcx> FnSig<'tcx> {
} }
} }
impl<'tcx> IntoDiagnosticArg for FnSig<'tcx> { impl<'tcx> IntoDiagArg for FnSig<'tcx> {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }

View file

@ -1,8 +1,8 @@
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::DiagArgValue; use rustc_errors::DiagArgValue;
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level, MultiSpan,
Level, MultiSpan, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
@ -419,8 +419,8 @@ pub struct UnsafeNotInheritedLintNote {
pub body_span: Span, pub body_span: Span,
} }
impl AddToDiagnostic for UnsafeNotInheritedLintNote { impl Subdiagnostic for UnsafeNotInheritedLintNote {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,
@ -461,10 +461,8 @@ pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
pub ty: Ty<'tcx>, pub ty: Ty<'tcx>,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'_, G> {
{
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = let mut diag =
Diag::new(dcx, level, fluent::mir_build_non_exhaustive_patterns_type_not_empty); Diag::new(dcx, level, fluent::mir_build_non_exhaustive_patterns_type_not_empty);
diag.span(self.span); diag.span(self.span);
@ -867,8 +865,8 @@ pub struct Variant {
pub span: Span, pub span: Span,
} }
impl<'tcx> AddToDiagnostic for AdtDefinedHere<'tcx> { impl<'tcx> Subdiagnostic for AdtDefinedHere<'tcx> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,

View file

@ -1,8 +1,8 @@
use std::borrow::Cow; use std::borrow::Cow;
use rustc_errors::{ use rustc_errors::{
codes::*, Applicability, DecorateLint, Diag, DiagArgValue, DiagCtxt, DiagMessage, codes::*, Applicability, Diag, DiagArgValue, DiagCtxt, DiagMessage, Diagnostic,
EmissionGuarantee, IntoDiagnostic, Level, EmissionGuarantee, Level, LintDiagnostic,
}; };
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails}; use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails};
@ -62,9 +62,9 @@ pub(crate) struct RequiresUnsafe {
// so we need to eagerly translate the label here, which isn't supported by the derive API // so we need to eagerly translate the label here, which isn't supported by the derive API
// We could also exhaustively list out the primary messages for all unsafe violations, // We could also exhaustively list out the primary messages for all unsafe violations,
// but this would result in a lot of duplication. // but this would result in a lot of duplication.
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for RequiresUnsafe { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for RequiresUnsafe {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
let mut diag = Diag::new(dcx, level, fluent::mir_transform_requires_unsafe); let mut diag = Diag::new(dcx, level, fluent::mir_transform_requires_unsafe);
diag.code(E0133); diag.code(E0133);
diag.span(self.span); diag.span(self.span);
@ -181,7 +181,7 @@ pub(crate) struct UnsafeOpInUnsafeFn {
pub suggest_unsafe_block: Option<(Span, Span, Span)>, pub suggest_unsafe_block: Option<(Span, Span, Span)>,
} }
impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn { impl<'a> LintDiagnostic<'a, ()> for UnsafeOpInUnsafeFn {
#[track_caller] #[track_caller]
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
let desc = diag.dcx.eagerly_translate_to_string(self.details.label(), [].into_iter()); let desc = diag.dcx.eagerly_translate_to_string(self.details.label(), [].into_iter());
@ -215,7 +215,7 @@ pub(crate) enum AssertLintKind {
UnconditionalPanic, UnconditionalPanic,
} }
impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint<P> { impl<'a, P: std::fmt::Debug> LintDiagnostic<'a, ()> for AssertLint<P> {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
let message = self.assert_kind.diagnostic_message(); let message = self.assert_kind.diagnostic_message();
self.assert_kind.add_args(&mut |name, value| { self.assert_kind.add_args(&mut |name, value| {
@ -269,7 +269,7 @@ pub(crate) struct MustNotSupend<'tcx, 'a> {
} }
// Needed for def_path_str // Needed for def_path_str
impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> { impl<'a> LintDiagnostic<'a, ()> for MustNotSupend<'_, '_> {
fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut rustc_errors::Diag<'a, ()>) {
diag.span_label(self.yield_sp, fluent::_subdiag::label); diag.span_label(self.yield_sp, fluent::_subdiag::label);
if let Some(reason) = self.reason { if let Some(reason) = self.reason {

View file

@ -1,7 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_errors::{Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
use rustc_macros::{Diagnostic, LintDiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
@ -46,9 +46,9 @@ pub struct UnusedGenericParamsHint {
pub param_names: Vec<String>, pub param_names: Vec<String>,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for UnusedGenericParamsHint { impl<G: EmissionGuarantee> Diagnostic<'_, G> for UnusedGenericParamsHint {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::monomorphize_unused_generic_params); let mut diag = Diag::new(dcx, level, fluent::monomorphize_unused_generic_params);
diag.span(self.span); diag.span(self.span);
for (span, name) in self.param_spans.into_iter().zip(self.param_names) { for (span, name) in self.param_spans.into_iter().zip(self.param_names) {

View file

@ -3,8 +3,8 @@ use std::borrow::Cow;
use rustc_ast::token::Token; use rustc_ast::token::Token;
use rustc_ast::{Path, Visibility}; use rustc_ast::{Path, Visibility};
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level,
Level, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::errors::ExprParenthesesNeeded; use rustc_session::errors::ExprParenthesesNeeded;
@ -1065,9 +1065,9 @@ pub(crate) struct ExpectedIdentifier {
pub help_cannot_start_number: Option<HelpIdentifierStartsWithNumber>, pub help_cannot_start_number: Option<HelpIdentifierStartsWithNumber>,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedIdentifier {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
let token_descr = TokenDescription::from_token(&self.token); let token_descr = TokenDescription::from_token(&self.token);
let mut diag = Diag::new( let mut diag = Diag::new(
@ -1093,17 +1093,17 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
diag.arg("token", self.token); diag.arg("token", self.token);
if let Some(sugg) = self.suggest_raw { if let Some(sugg) = self.suggest_raw {
sugg.add_to_diagnostic(&mut diag); sugg.add_to_diag(&mut diag);
} }
ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag); ExpectedIdentifierFound::new(token_descr, self.span).add_to_diag(&mut diag);
if let Some(sugg) = self.suggest_remove_comma { if let Some(sugg) = self.suggest_remove_comma {
sugg.add_to_diagnostic(&mut diag); sugg.add_to_diag(&mut diag);
} }
if let Some(help) = self.help_cannot_start_number { if let Some(help) = self.help_cannot_start_number {
help.add_to_diagnostic(&mut diag); help.add_to_diag(&mut diag);
} }
diag diag
@ -1125,9 +1125,9 @@ pub(crate) struct ExpectedSemi {
pub sugg: ExpectedSemiSugg, pub sugg: ExpectedSemiSugg,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedSemi {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
let token_descr = TokenDescription::from_token(&self.token); let token_descr = TokenDescription::from_token(&self.token);
let mut diag = Diag::new( let mut diag = Diag::new(
@ -1154,7 +1154,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token); diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);
} }
self.sugg.add_to_diagnostic(&mut diag); self.sugg.add_to_diag(&mut diag);
diag diag
} }
@ -1466,8 +1466,8 @@ pub(crate) struct FnTraitMissingParen {
pub machine_applicable: bool, pub machine_applicable: bool,
} }
impl AddToDiagnostic for FnTraitMissingParen { impl Subdiagnostic for FnTraitMissingParen {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_: F, _: F,

View file

@ -36,8 +36,8 @@ use rustc_ast::{
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{ use rustc_errors::{
pluralize, AddToDiagnostic, Applicability, Diag, DiagCtxt, ErrorGuaranteed, FatalError, PErr, pluralize, Applicability, Diag, DiagCtxt, ErrorGuaranteed, FatalError, PErr, PResult,
PResult, Subdiagnostic,
}; };
use rustc_session::errors::ExprParenthesesNeeded; use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
@ -298,7 +298,7 @@ impl<'a> Parser<'a> {
{ {
recovered_ident = Some((ident, IdentIsRaw::Yes)); recovered_ident = Some((ident, IdentIsRaw::Yes));
// `Symbol::to_string()` is different from `Symbol::into_diagnostic_arg()`, // `Symbol::to_string()` is different from `Symbol::into_diag_arg()`,
// which uses `Symbol::to_ident_string()` and "helpfully" adds an implicit `r#` // which uses `Symbol::to_ident_string()` and "helpfully" adds an implicit `r#`
let ident_name = ident.name.to_string(); let ident_name = ident.name.to_string();
@ -1271,7 +1271,7 @@ impl<'a> Parser<'a> {
Ok(_) => { Ok(_) => {
if self.token == token::Eq { if self.token == token::Eq {
let sugg = SuggAddMissingLetStmt { span: prev_span }; let sugg = SuggAddMissingLetStmt { span: prev_span };
sugg.add_to_diagnostic(err); sugg.add_to_diag(err);
} }
} }
Err(e) => { Err(e) => {

View file

@ -27,7 +27,7 @@ use rustc_ast::{Arm, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLim
use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind}; use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind};
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::{AddToDiagnostic, Applicability, Diag, PResult, StashKey}; use rustc_errors::{Applicability, Diag, PResult, StashKey, Subdiagnostic};
use rustc_lexer::unescape::unescape_char; use rustc_lexer::unescape::unescape_char;
use rustc_macros::Subdiagnostic; use rustc_macros::Subdiagnostic;
use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded};
@ -3451,8 +3451,8 @@ impl<'a> Parser<'a> {
let in_if_guard = self.restrictions.contains(Restrictions::IN_IF_GUARD); let in_if_guard = self.restrictions.contains(Restrictions::IN_IF_GUARD);
let async_block_err = |e: &mut Diag<'_>, span: Span| { let async_block_err = |e: &mut Diag<'_>, span: Span| {
errors::AsyncBlockIn2015 { span }.add_to_diagnostic(e); errors::AsyncBlockIn2015 { span }.add_to_diag(e);
errors::HelpUseLatestEdition::new().add_to_diagnostic(e); errors::HelpUseLatestEdition::new().add_to_diag(e);
}; };
while self.token != token::CloseDelim(close_delim) { while self.token != token::CloseDelim(close_delim) {

View file

@ -9,7 +9,7 @@ use rustc_ast::{ast, AttrKind, AttrStyle, Attribute, LitKind};
use rustc_ast::{MetaItemKind, MetaItemLit, NestedMetaItem}; use rustc_ast::{MetaItemKind, MetaItemLit, NestedMetaItem};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::StashKey; use rustc_errors::StashKey;
use rustc_errors::{Applicability, DiagCtxt, IntoDiagnosticArg, MultiSpan}; use rustc_errors::{Applicability, DiagCtxt, IntoDiagArg, MultiSpan};
use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP}; use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalModDefId; use rustc_hir::def_id::LocalModDefId;
@ -79,14 +79,14 @@ pub(crate) enum ProcMacroKind {
Attribute, Attribute,
} }
impl IntoDiagnosticArg for ProcMacroKind { impl IntoDiagArg for ProcMacroKind {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
match self { match self {
ProcMacroKind::Attribute => "attribute proc macro", ProcMacroKind::Attribute => "attribute proc macro",
ProcMacroKind::Derive => "derive proc macro", ProcMacroKind::Derive => "derive proc macro",
ProcMacroKind::FunctionLike => "function-like proc macro", ProcMacroKind::FunctionLike => "function-like proc macro",
} }
.into_diagnostic_arg() .into_diag_arg()
} }
} }

View file

@ -6,8 +6,8 @@ use std::{
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_ast::Label; use rustc_ast::Label;
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, DiagSymbolList, EmissionGuarantee, codes::*, Applicability, Diag, DiagCtxt, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
IntoDiagnostic, Level, MultiSpan, SubdiagMessageOp, MultiSpan, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_hir::{self as hir, ExprKind, Target}; use rustc_hir::{self as hir, ExprKind, Target};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@ -862,9 +862,9 @@ pub struct ItemFollowingInnerAttr {
pub kind: &'static str, pub kind: &'static str,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for InvalidAttrAtCrateLevel { impl<G: EmissionGuarantee> Diagnostic<'_, G> for InvalidAttrAtCrateLevel {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level); let mut diag = Diag::new(dcx, level, fluent::passes_invalid_attr_at_crate_level);
diag.span(self.span); diag.span(self.span);
diag.arg("name", self.name); diag.arg("name", self.name);
@ -1012,9 +1012,9 @@ pub struct BreakNonLoop<'a> {
pub break_expr_span: Span, pub break_expr_span: Span,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'_, G> for BreakNonLoop<'a> { impl<'a, G: EmissionGuarantee> Diagnostic<'_, G> for BreakNonLoop<'a> {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::passes_break_non_loop); let mut diag = Diag::new(dcx, level, fluent::passes_break_non_loop);
diag.span(self.span); diag.span(self.span);
diag.code(E0571); diag.code(E0571);
@ -1156,9 +1156,9 @@ pub struct NakedFunctionsAsmBlock {
pub non_asms: Vec<Span>, pub non_asms: Vec<Span>,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for NakedFunctionsAsmBlock { impl<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::passes_naked_functions_asm_block); let mut diag = Diag::new(dcx, level, fluent::passes_naked_functions_asm_block);
diag.span(self.span); diag.span(self.span);
diag.code(E0787); diag.code(E0787);
@ -1267,9 +1267,9 @@ pub struct NoMainErr {
pub add_teach_note: bool, pub add_teach_note: bool,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for NoMainErr { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NoMainErr {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function); let mut diag = Diag::new(dcx, level, fluent::passes_no_main_function);
diag.span(DUMMY_SP); diag.span(DUMMY_SP);
diag.code(E0601); diag.code(E0601);
@ -1325,9 +1325,9 @@ pub struct DuplicateLangItem {
pub(crate) duplicate: Duplicate, pub(crate) duplicate: Duplicate,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for DuplicateLangItem { impl<G: EmissionGuarantee> Diagnostic<'_, G> for DuplicateLangItem {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new( let mut diag = Diag::new(
dcx, dcx,
level, level,
@ -1751,8 +1751,8 @@ pub struct UnusedVariableStringInterp {
pub hi: Span, pub hi: Span,
} }
impl AddToDiagnostic for UnusedVariableStringInterp { impl Subdiagnostic for UnusedVariableStringInterp {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,

View file

@ -1,4 +1,4 @@
use rustc_errors::{AddToDiagnostic, Diag, EmissionGuarantee, SubdiagMessageOp}; use rustc_errors::{Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
use rustc_macros::{LintDiagnostic, Subdiagnostic}; use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_middle::thir::Pat; use rustc_middle::thir::Pat;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
@ -61,8 +61,8 @@ pub struct Overlap<'tcx> {
pub range: Pat<'tcx>, pub range: Pat<'tcx>,
} }
impl<'tcx> AddToDiagnostic for Overlap<'tcx> { impl<'tcx> Subdiagnostic for Overlap<'tcx> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_: F, _: F,
@ -109,8 +109,8 @@ pub struct GappedRange<'tcx> {
pub first_range: Pat<'tcx>, pub first_range: Pat<'tcx>,
} }
impl<'tcx> AddToDiagnostic for GappedRange<'tcx> { impl<'tcx> Subdiagnostic for GappedRange<'tcx> {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_: F, _: F,

View file

@ -97,7 +97,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
lint_name: "non_exhaustive_omitted_patterns", lint_name: "non_exhaustive_omitted_patterns",
}; };
use rustc_errors::DecorateLint; use rustc_errors::LintDiagnostic;
let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().unwrap().span, ""); let mut err = rcx.tcx.dcx().struct_span_warn(arm.pat.data().unwrap().span, "");
err.primary_message(decorator.msg()); err.primary_message(decorator.msg());
decorator.decorate_lint(&mut err); decorator.decorate_lint(&mut err);

View file

@ -521,7 +521,7 @@ pub(crate) struct ToolModuleImported {
#[diag(resolve_module_only)] #[diag(resolve_module_only)]
pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span); pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span);
#[derive(Diagnostic, Default)] #[derive(Diagnostic)]
#[diag(resolve_macro_expected_found)] #[diag(resolve_macro_expected_found)]
pub(crate) struct MacroExpectedFound<'a> { pub(crate) struct MacroExpectedFound<'a> {
#[primary_span] #[primary_span]

View file

@ -17,7 +17,7 @@ use rustc_ast::visit::{walk_list, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor}
use rustc_ast::*; use rustc_ast::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_errors::{ use rustc_errors::{
codes::*, struct_span_code_err, Applicability, DiagArgValue, IntoDiagnosticArg, StashKey, codes::*, struct_span_code_err, Applicability, DiagArgValue, IntoDiagArg, StashKey,
}; };
use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS}; use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS};
@ -89,8 +89,8 @@ impl PatternSource {
} }
} }
impl IntoDiagnosticArg for PatternSource { impl IntoDiagArg for PatternSource {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
DiagArgValue::Str(Cow::Borrowed(self.descr())) DiagArgValue::Str(Cow::Borrowed(self.descr()))
} }
} }

View file

@ -562,7 +562,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
expected, expected,
found: res.descr(), found: res.descr(),
macro_path: &path_str, macro_path: &path_str,
..Default::default() // Subdiagnostics default to None remove_surrounding_derive: None,
add_as_non_derive: None,
}; };
// Suggest moving the macro out of the derive() if the macro isn't Derive // Suggest moving the macro out of the derive() if the macro isn't Derive

View file

@ -13,7 +13,7 @@ use crate::{EarlyDiagCtxt, Session};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey}; use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
use rustc_errors::emitter::HumanReadableErrorType; use rustc_errors::emitter::HumanReadableErrorType;
use rustc_errors::{ColorConfig, DiagArgValue, DiagCtxtFlags, IntoDiagnosticArg}; use rustc_errors::{ColorConfig, DiagArgValue, DiagCtxtFlags, IntoDiagArg};
use rustc_feature::UnstableFeatures; use rustc_feature::UnstableFeatures;
use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION}; use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION};
use rustc_span::source_map::FilePathMapping; use rustc_span::source_map::FilePathMapping;
@ -3098,9 +3098,9 @@ impl fmt::Display for CrateType {
} }
} }
impl IntoDiagnosticArg for CrateType { impl IntoDiagArg for CrateType {
fn into_diagnostic_arg(self) -> DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }

View file

@ -3,8 +3,8 @@ use std::num::NonZero;
use rustc_ast::token; use rustc_ast::token;
use rustc_ast::util::literal::LitError; use rustc_ast::util::literal::LitError;
use rustc_errors::{ use rustc_errors::{
codes::*, Diag, DiagCtxt, DiagMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, codes::*, Diag, DiagCtxt, DiagMessage, Diagnostic, EmissionGuarantee, ErrorGuaranteed, Level,
Level, MultiSpan, MultiSpan,
}; };
use rustc_macros::Diagnostic; use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
@ -17,9 +17,9 @@ pub struct FeatureGateError {
pub explain: DiagMessage, pub explain: DiagMessage,
} }
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for FeatureGateError { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for FeatureGateError {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
Diag::new(dcx, level, self.explain).with_span(self.span).with_code(E0658) Diag::new(dcx, level, self.explain).with_span(self.span).with_code(E0658)
} }
} }

View file

@ -22,8 +22,8 @@ use rustc_errors::emitter::{stderr_destination, DynEmitter, HumanEmitter, HumanR
use rustc_errors::json::JsonEmitter; use rustc_errors::json::JsonEmitter;
use rustc_errors::registry::Registry; use rustc_errors::registry::Registry;
use rustc_errors::{ use rustc_errors::{
codes::*, fallback_fluent_bundle, Diag, DiagCtxt, DiagMessage, ErrorGuaranteed, FatalAbort, codes::*, fallback_fluent_bundle, Diag, DiagCtxt, DiagMessage, Diagnostic, ErrorGuaranteed,
FluentBundle, IntoDiagnostic, LazyFallbackBundle, TerminalUrl, FatalAbort, FluentBundle, LazyFallbackBundle, TerminalUrl,
}; };
use rustc_macros::HashStable_Generic; use rustc_macros::HashStable_Generic;
pub use rustc_span::def_id::StableCrateId; pub use rustc_span::def_id::StableCrateId;
@ -111,9 +111,9 @@ impl Mul<usize> for Limit {
} }
} }
impl rustc_errors::IntoDiagnosticArg for Limit { impl rustc_errors::IntoDiagArg for Limit {
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
self.to_string().into_diagnostic_arg() self.to_string().into_diag_arg()
} }
} }
@ -305,11 +305,7 @@ impl Session {
} }
#[track_caller] #[track_caller]
pub fn create_feature_err<'a>( pub fn create_feature_err<'a>(&'a self, err: impl Diagnostic<'a>, feature: Symbol) -> Diag<'a> {
&'a self,
err: impl IntoDiagnostic<'a>,
feature: Symbol,
) -> Diag<'a> {
let mut err = self.dcx().create_err(err); let mut err = self.dcx().create_err(err);
if err.code.is_none() { if err.code.is_none() {
#[allow(rustc::diagnostic_outside_of_impl)] #[allow(rustc::diagnostic_outside_of_impl)]

View file

@ -129,7 +129,6 @@ symbols! {
Abi, Abi,
AcqRel, AcqRel,
Acquire, Acquire,
AddToDiagnostic,
Any, Any,
Arc, Arc,
ArcWeak, ArcWeak,
@ -184,10 +183,10 @@ symbols! {
DebugStruct, DebugStruct,
Decodable, Decodable,
Decoder, Decoder,
DecorateLint,
Default, Default,
Deref, Deref,
DiagMessage, DiagMessage,
Diagnostic,
DirBuilder, DirBuilder,
Display, Display,
DoubleEndedIterator, DoubleEndedIterator,
@ -223,7 +222,6 @@ symbols! {
Input, Input,
Instant, Instant,
Into, Into,
IntoDiagnostic,
IntoFuture, IntoFuture,
IntoIterator, IntoIterator,
IoLines, IoLines,
@ -243,6 +241,7 @@ symbols! {
Layout, Layout,
Left, Left,
LinkedList, LinkedList,
LintDiagnostic,
LintPass, LintPass,
LocalKey, LocalKey,
Mutex, Mutex,
@ -305,6 +304,7 @@ symbols! {
String, String,
StructuralPartialEq, StructuralPartialEq,
SubdiagMessage, SubdiagMessage,
Subdiagnostic,
Sync, Sync,
T, T,
Target, Target,

View file

@ -1,6 +1,6 @@
//! Errors emitted by symbol_mangling. //! Errors emitted by symbol_mangling.
use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level}; use rustc_errors::{Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
use rustc_span::Span; use rustc_span::Span;
use std::fmt; use std::fmt;
@ -13,8 +13,8 @@ pub struct TestOutput {
// This diagnostic doesn't need translation because (a) it doesn't contain any // This diagnostic doesn't need translation because (a) it doesn't contain any
// natural language, and (b) it's only used in tests. So we construct it // natural language, and (b) it's only used in tests. So we construct it
// manually and avoid the fluent machinery. // manually and avoid the fluent machinery.
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TestOutput { impl<G: EmissionGuarantee> Diagnostic<'_, G> for TestOutput {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
let TestOutput { span, kind, content } = self; let TestOutput { span, kind, content } = self;
#[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::untranslatable_diagnostic)]

View file

@ -1,7 +1,7 @@
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level,
Level, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::Diagnostic; use rustc_macros::Diagnostic;
use rustc_middle::ty::{self, ClosureKind, PolyTraitRef, Ty}; use rustc_middle::ty::{self, ClosureKind, PolyTraitRef, Ty};
@ -57,9 +57,9 @@ pub struct NegativePositiveConflict<'tcx> {
pub positive_impl_span: Result<Span, Symbol>, pub positive_impl_span: Result<Span, Symbol>,
} }
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for NegativePositiveConflict<'_> { impl<G: EmissionGuarantee> Diagnostic<'_, G> for NegativePositiveConflict<'_> {
#[track_caller] #[track_caller]
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> { fn into_diag(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
let mut diag = Diag::new(dcx, level, fluent::trait_selection_negative_positive_conflict); let mut diag = Diag::new(dcx, level, fluent::trait_selection_negative_positive_conflict);
diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string()); diag.arg("trait_desc", self.trait_desc.print_only_trait_path().to_string());
diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string())); diag.arg("self_desc", self.self_ty.map_or_else(|| "none".to_string(), |ty| ty.to_string()));
@ -100,8 +100,8 @@ pub enum AdjustSignatureBorrow {
RemoveBorrow { remove_borrow: Vec<(Span, String)> }, RemoveBorrow { remove_borrow: Vec<(Span, String)> },
} }
impl AddToDiagnostic for AdjustSignatureBorrow { impl Subdiagnostic for AdjustSignatureBorrow {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
_f: F, _f: F,

View file

@ -14,8 +14,8 @@ extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
use rustc_errors::{ use rustc_errors::{
AddToDiagnostic, DecorateLint, Diag, DiagCtxt, DiagInner, DiagMessage, EmissionGuarantee, Diag, DiagCtxt, DiagInner, DiagMessage, Diagnostic, EmissionGuarantee, Level, LintDiagnostic,
IntoDiagnostic, Level, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::Span; use rustc_span::Span;
@ -36,27 +36,27 @@ struct Note {
span: Span, span: Span,
} }
pub struct UntranslatableInIntoDiagnostic; pub struct UntranslatableInDiagnostic;
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UntranslatableInIntoDiagnostic { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UntranslatableInDiagnostic {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
Diag::new(dcx, level, "untranslatable diagnostic") Diag::new(dcx, level, "untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages //~^ ERROR diagnostics should be created using translatable messages
} }
} }
pub struct TranslatableInIntoDiagnostic; pub struct TranslatableInDiagnostic;
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for TranslatableInIntoDiagnostic { impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for TranslatableInDiagnostic {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> { fn into_diag(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
Diag::new(dcx, level, crate::fluent_generated::no_crate_example) Diag::new(dcx, level, crate::fluent_generated::no_crate_example)
} }
} }
pub struct UntranslatableInAddToDiagnostic; pub struct UntranslatableInAddtoDiag;
impl AddToDiagnostic for UntranslatableInAddToDiagnostic { impl Subdiagnostic for UntranslatableInAddtoDiag {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,
@ -66,10 +66,10 @@ impl AddToDiagnostic for UntranslatableInAddToDiagnostic {
} }
} }
pub struct TranslatableInAddToDiagnostic; pub struct TranslatableInAddtoDiag;
impl AddToDiagnostic for TranslatableInAddToDiagnostic { impl Subdiagnostic for TranslatableInAddtoDiag {
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self, self,
diag: &mut Diag<'_, G>, diag: &mut Diag<'_, G>,
f: F, f: F,
@ -78,9 +78,9 @@ impl AddToDiagnostic for TranslatableInAddToDiagnostic {
} }
} }
pub struct UntranslatableInDecorateLint; pub struct UntranslatableInLintDiagnostic;
impl<'a> DecorateLint<'a, ()> for UntranslatableInDecorateLint { impl<'a> LintDiagnostic<'a, ()> for UntranslatableInLintDiagnostic {
fn decorate_lint<'b, >(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b, >(self, diag: &'b mut Diag<'a, ()>) {
diag.note("untranslatable diagnostic"); diag.note("untranslatable diagnostic");
//~^ ERROR diagnostics should be created using translatable messages //~^ ERROR diagnostics should be created using translatable messages
@ -91,9 +91,9 @@ impl<'a> DecorateLint<'a, ()> for UntranslatableInDecorateLint {
} }
} }
pub struct TranslatableInDecorateLint; pub struct TranslatableInLintDiagnostic;
impl<'a> DecorateLint<'a, ()> for TranslatableInDecorateLint { impl<'a> LintDiagnostic<'a, ()> for TranslatableInLintDiagnostic {
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
diag.note(crate::fluent_generated::no_crate_note); diag.note(crate::fluent_generated::no_crate_note);
} }
@ -105,10 +105,10 @@ impl<'a> DecorateLint<'a, ()> for TranslatableInDecorateLint {
pub fn make_diagnostics<'a>(dcx: &'a DiagCtxt) { pub fn make_diagnostics<'a>(dcx: &'a DiagCtxt) {
let _diag = dcx.struct_err(crate::fluent_generated::no_crate_example); let _diag = dcx.struct_err(crate::fluent_generated::no_crate_example);
//~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls //~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
let _diag = dcx.struct_err("untranslatable diagnostic"); let _diag = dcx.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls //~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages //~^^ ERROR diagnostics should be created using translatable messages
} }

View file

@ -22,7 +22,7 @@ error: diagnostics should be created using translatable messages
LL | diag.note("untranslatable diagnostic"); LL | diag.note("untranslatable diagnostic");
| ^^^^ | ^^^^
error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
--> $DIR/diagnostics.rs:107:21 --> $DIR/diagnostics.rs:107:21
| |
LL | let _diag = dcx.struct_err(crate::fluent_generated::no_crate_example); LL | let _diag = dcx.struct_err(crate::fluent_generated::no_crate_example);
@ -34,7 +34,7 @@ note: the lint level is defined here
LL | #![deny(rustc::diagnostic_outside_of_impl)] LL | #![deny(rustc::diagnostic_outside_of_impl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
--> $DIR/diagnostics.rs:110:21 --> $DIR/diagnostics.rs:110:21
| |
LL | let _diag = dcx.struct_err("untranslatable diagnostic"); LL | let _diag = dcx.struct_err("untranslatable diagnostic");

View file

@ -1,6 +1,6 @@
//@ check-fail //@ check-fail
// Tests that a doc comment will not preclude a field from being considered a diagnostic argument // Tests that a doc comment will not preclude a field from being considered a diagnostic argument
//@ normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr" //@ normalize-stderr-test "the following other types implement trait `IntoDiagArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr"
//@ normalize-stderr-test "(COMPILER_DIR/.*\.rs):[0-9]+:[0-9]+" -> "$1:LL:CC" //@ normalize-stderr-test "(COMPILER_DIR/.*\.rs):[0-9]+:[0-9]+" -> "$1:LL:CC"
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly, // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
@ -25,7 +25,7 @@ use rustc_span::Span;
rustc_fluent_macro::fluent_messages! { "./example.ftl" } rustc_fluent_macro::fluent_messages! { "./example.ftl" }
struct NotIntoDiagnosticArg; struct NotIntoDiagArg;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(no_crate_example)] #[diag(no_crate_example)]
@ -33,8 +33,8 @@ struct Test {
#[primary_span] #[primary_span]
span: Span, span: Span,
/// A doc comment /// A doc comment
arg: NotIntoDiagnosticArg, arg: NotIntoDiagArg,
//~^ ERROR the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied //~^ ERROR the trait bound `NotIntoDiagArg: IntoDiagArg` is not satisfied
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
@ -43,6 +43,6 @@ struct SubTest {
#[primary_span] #[primary_span]
span: Span, span: Span,
/// A doc comment /// A doc comment
arg: NotIntoDiagnosticArg, arg: NotIntoDiagArg,
//~^ ERROR the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied //~^ ERROR the trait bound `NotIntoDiagArg: IntoDiagArg` is not satisfied
} }

View file

@ -1,25 +1,25 @@
error[E0277]: the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied error[E0277]: the trait bound `NotIntoDiagArg: IntoDiagArg` is not satisfied
--> $DIR/diagnostic-derive-doc-comment-field.rs:36:10 --> $DIR/diagnostic-derive-doc-comment-field.rs:36:10
| |
LL | #[derive(Diagnostic)] LL | #[derive(Diagnostic)]
| ---------- required by a bound introduced by this call | ---------- required by a bound introduced by this call
... ...
LL | arg: NotIntoDiagnosticArg, LL | arg: NotIntoDiagArg,
| ^^^^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg` | ^^^^^^^^^^^^^^ the trait `IntoDiagArg` is not implemented for `NotIntoDiagArg`
| |
= help: normalized in stderr = help: normalized in stderr
note: required by a bound in `Diag::<'a, G>::arg` note: required by a bound in `Diag::<'a, G>::arg`
--> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC
= note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `NotIntoDiagnosticArg: IntoDiagnosticArg` is not satisfied error[E0277]: the trait bound `NotIntoDiagArg: IntoDiagArg` is not satisfied
--> $DIR/diagnostic-derive-doc-comment-field.rs:46:10 --> $DIR/diagnostic-derive-doc-comment-field.rs:46:10
| |
LL | #[derive(Subdiagnostic)] LL | #[derive(Subdiagnostic)]
| ------------- required by a bound introduced by this call | ------------- required by a bound introduced by this call
... ...
LL | arg: NotIntoDiagnosticArg, LL | arg: NotIntoDiagArg,
| ^^^^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `NotIntoDiagnosticArg` | ^^^^^^^^^^^^^^ the trait `IntoDiagArg` is not implemented for `NotIntoDiagArg`
| |
= help: normalized in stderr = help: normalized in stderr
note: required by a bound in `Diag::<'a, G>::arg` note: required by a bound in `Diag::<'a, G>::arg`

View file

@ -1,6 +1,6 @@
//@ check-fail //@ check-fail
// Tests error conditions for specifying diagnostics using #[derive(Diagnostic)] // Tests error conditions for specifying diagnostics using #[derive(Diagnostic)]
//@ normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr" //@ normalize-stderr-test "the following other types implement trait `IntoDiagArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr"
//@ normalize-stderr-test "(COMPILER_DIR/.*\.rs):[0-9]+:[0-9]+" -> "$1:LL:CC" //@ normalize-stderr-test "(COMPILER_DIR/.*\.rs):[0-9]+:[0-9]+" -> "$1:LL:CC"
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly, // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
@ -347,7 +347,7 @@ struct ArgFieldWithoutSkip {
#[primary_span] #[primary_span]
span: Span, span: Span,
other: Hello, other: Hello,
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied //~^ ERROR the trait bound `Hello: IntoDiagArg` is not satisfied
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
@ -355,7 +355,7 @@ struct ArgFieldWithoutSkip {
struct ArgFieldWithSkip { struct ArgFieldWithSkip {
#[primary_span] #[primary_span]
span: Span, span: Span,
// `Hello` does not implement `IntoDiagnosticArg` so this would result in an error if // `Hello` does not implement `IntoDiagArg` so this would result in an error if
// not for `#[skip_arg]`. // not for `#[skip_arg]`.
#[skip_arg] #[skip_arg]
other: Hello, other: Hello,

View file

@ -618,14 +618,14 @@ LL | #[derive(Diagnostic)]
| |
= note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied error[E0277]: the trait bound `Hello: IntoDiagArg` is not satisfied
--> $DIR/diagnostic-derive.rs:349:12 --> $DIR/diagnostic-derive.rs:349:12
| |
LL | #[derive(Diagnostic)] LL | #[derive(Diagnostic)]
| ---------- required by a bound introduced by this call | ---------- required by a bound introduced by this call
... ...
LL | other: Hello, LL | other: Hello,
| ^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | ^^^^^ the trait `IntoDiagArg` is not implemented for `Hello`
| |
= help: normalized in stderr = help: normalized in stderr
note: required by a bound in `Diag::<'a, G>::arg` note: required by a bound in `Diag::<'a, G>::arg`