Rename AddToDiagnostic as Subdiagnostic.

To match `derive(Subdiagnostic)`.

Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
This commit is contained in:
Nicholas Nethercote 2024-03-06 14:00:16 +11:00
parent 7a294e998b
commit 541d7cc65c
28 changed files with 153 additions and 153 deletions

View File

@ -1,5 +1,5 @@
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};
@ -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,

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,6 +1,6 @@
use rustc_errors::{ use rustc_errors::{
codes::*, AddToDiagnostic, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, 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};
@ -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,

View File

@ -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,
@ -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)

View File

@ -1,5 +1,5 @@
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, Diagnostic, EmissionGuarantee, ErrCode, IntoDiagArg, Level, Diag, DiagArgValue, DiagCtxt, Diagnostic, EmissionGuarantee, ErrCode, IntoDiagArg, Level,
SubdiagMessageOp, SubdiagMessageOp,
@ -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,

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, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue, DiagInner,
DiagInner, DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort, IntoDiagArg, DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort, IntoDiagArg, StringPart, Subdiag,
StringPart, Subdiag, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
pub use diagnostic_impls::{ pub use diagnostic_impls::{
DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime, DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime,

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, IntoDiagArg, codes::*, Applicability, Diag, DiagArgValue, EmissionGuarantee, IntoDiagArg, MultiSpan,
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;
@ -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, IntoDiagArg, 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,
@ -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, IntoDiagArg, 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};
@ -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

@ -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

@ -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 `Diagnostic`/`AddToDiagnostic` impls diagnostics should only be created in `Diagnostic`/`Subdiagnostic` 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

@ -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,7 +351,7 @@ 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 `Diagnostic`, `AddToDiagnostic`, or /// `#[rustc_lint_diagnostics]` that are outside an `Diagnostic`, `Subdiagnostic`, or
/// `DecorateLint` impl, or a `#[derive(Diagnostic)]`, `#[derive(Subdiagnostic)]`, /// `DecorateLint` impl, or a `#[derive(Diagnostic)]`, `#[derive(Subdiagnostic)]`,
/// `#[derive(DecorateLint)]` expansion. /// `#[derive(DecorateLint)]` expansion.
/// ///
@ -359,7 +359,7 @@ declare_tool_lint! {
/// [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 `Diagnostic`/`AddToDiagnostic` impls", "prevent creation of diagnostics outside of `Diagnostic`/`Subdiagnostic` impls",
report_in_external_macro: true report_in_external_macro: true
} }
@ -455,7 +455,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 `Diagnostic`, `AddToDiagnostic`, or `DecorateLint`, or // - inside an impl of `Diagnostic`, `Subdiagnostic`, or `DecorateLint`, 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,7 +467,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!(name, sym::Diagnostic | sym::AddToDiagnostic | sym::DecorateLint) && matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint)
{ {
is_inside_appropriate_impl = true; is_inside_appropriate_impl = true;
break; break;

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, DecorateLint, Diag, DiagMessage, DiagStyledString, EmissionGuarantee,
EmissionGuarantee, SubdiagMessageOp, SuggestionStyle, 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};
@ -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,
@ -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,
@ -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,
@ -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,

View File

@ -16,7 +16,7 @@ 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 SubdiagnosticDeriveBuilder {
diag: syn::Ident, diag: syn::Ident,
f: syn::Ident, f: syn::Ident,
@ -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

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, Diagnostic, EmissionGuarantee, Level, codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level, MultiSpan,
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,
@ -865,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

@ -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, Diagnostic, EmissionGuarantee, Level, codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level,
SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::errors::ExprParenthesesNeeded; use rustc_session::errors::ExprParenthesesNeeded;
@ -1093,17 +1093,17 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'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
@ -1154,7 +1154,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'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;
@ -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

@ -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, Diagnostic, codes::*, Applicability, Diag, DiagCtxt, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
EmissionGuarantee, 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};
@ -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

@ -129,7 +129,6 @@ symbols! {
Abi, Abi,
AcqRel, AcqRel,
Acquire, Acquire,
AddToDiagnostic,
Any, Any,
Arc, Arc,
ArcWeak, ArcWeak,
@ -305,6 +304,7 @@ symbols! {
String, String,
StructuralPartialEq, StructuralPartialEq,
SubdiagMessage, SubdiagMessage,
Subdiagnostic,
Sync, Sync,
T, T,
Target, Target,

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, Diagnostic, EmissionGuarantee, Level, codes::*, Applicability, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, 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};
@ -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, DecorateLint, Diag, DiagCtxt, DiagInner, DiagMessage, Diagnostic, EmissionGuarantee, Level,
Diagnostic, Level, SubdiagMessageOp, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::Span; use rustc_span::Span;
@ -53,10 +53,10 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for TranslatableInDiagnostic {
} }
} }
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,
@ -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 `Diagnostic`/`AddToDiagnostic` impls //~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic` impls
let _diag = dcx.struct_err("untranslatable diagnostic"); let _diag = dcx.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `Diagnostic`/`AddToDiagnostic` impls //~^ ERROR diagnostics should only be created in `Diagnostic`/`Subdiagnostic` 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 `Diagnostic`/`AddToDiagnostic` impls error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic` 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 `Diagnostic`/`AddToDiagnostic` impls error: diagnostics should only be created in `Diagnostic`/`Subdiagnostic` 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");