Skip to content

Commit 5f91719

Browse files
committed
UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
1 parent a3396b2 commit 5f91719

File tree

24 files changed

+130
-128
lines changed

24 files changed

+130
-128
lines changed

compiler/rustc_ast_lowering/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay};
2-
use rustc_macros::{Diagnostic, SessionSubdiagnostic};
2+
use rustc_macros::{Diagnostic, Subdiagnostic};
33
use rustc_span::{symbol::Ident, Span, Symbol};
44

55
#[derive(Diagnostic, Clone, Copy)]
@@ -221,7 +221,7 @@ pub struct InvalidAsmTemplateModifierRegClass {
221221
pub sub: InvalidAsmTemplateModifierRegClassSub,
222222
}
223223

224-
#[derive(SessionSubdiagnostic)]
224+
#[derive(Subdiagnostic)]
225225
pub enum InvalidAsmTemplateModifierRegClassSub {
226226
#[note(ast_lowering::support_modifiers)]
227227
SupportModifier { class_name: Symbol, modifiers: String },

compiler/rustc_ast_passes/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct InvalidVisibility {
7171
pub note: Option<InvalidVisibilityNote>,
7272
}
7373

74-
#[derive(SessionSubdiagnostic)]
74+
#[derive(Subdiagnostic)]
7575
pub enum InvalidVisibilityNote {
7676
#[note(ast_passes::individual_impl_items)]
7777
IndividualImplItems,

compiler/rustc_attr/src/session_diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) struct InvalidIssueString {
9898

9999
// The error kinds of `IntErrorKind` are duplicated here in order to allow the messages to be
100100
// translatable.
101-
#[derive(SessionSubdiagnostic)]
101+
#[derive(Subdiagnostic)]
102102
pub(crate) enum InvalidIssueStringCause {
103103
#[label(attr::must_not_be_zero)]
104104
MustNotBeZero {
@@ -274,7 +274,7 @@ pub(crate) struct IncorrectReprFormatGeneric<'a> {
274274
pub cause: Option<IncorrectReprFormatGenericCause<'a>>,
275275
}
276276

277-
#[derive(SessionSubdiagnostic)]
277+
#[derive(Subdiagnostic)]
278278
pub(crate) enum IncorrectReprFormatGenericCause<'a> {
279279
#[suggestion(attr::suggestion, code = "{name}({int})", applicability = "machine-applicable")]
280280
Int {

compiler/rustc_borrowck/src/session_diagnostics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::{IntoDiagnosticArg, MultiSpan};
2-
use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic};
2+
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
33
use rustc_middle::ty::Ty;
44
use rustc_span::Span;
55

@@ -23,7 +23,7 @@ pub(crate) struct HigherRankedLifetimeError {
2323
pub span: Span,
2424
}
2525

26-
#[derive(SessionSubdiagnostic)]
26+
#[derive(Subdiagnostic)]
2727
pub(crate) enum HigherRankedErrorCause {
2828
#[note(borrowck::could_not_prove)]
2929
CouldNotProve { predicate: String },
@@ -72,7 +72,7 @@ pub(crate) struct FnMutError {
7272
pub ty_err: FnMutReturnTypeErr,
7373
}
7474

75-
#[derive(SessionSubdiagnostic)]
75+
#[derive(Subdiagnostic)]
7676
pub(crate) enum VarHereDenote {
7777
#[label(borrowck::var_here_captured)]
7878
Captured {
@@ -91,7 +91,7 @@ pub(crate) enum VarHereDenote {
9191
},
9292
}
9393

94-
#[derive(SessionSubdiagnostic)]
94+
#[derive(Subdiagnostic)]
9595
pub(crate) enum FnMutReturnTypeErr {
9696
#[label(borrowck::returned_closure_escaped)]
9797
ReturnClosure {
@@ -117,7 +117,7 @@ pub(crate) struct LifetimeOutliveErr {
117117
pub span: Span,
118118
}
119119

120-
#[derive(SessionSubdiagnostic)]
120+
#[derive(Subdiagnostic)]
121121
pub(crate) enum LifetimeReturnCategoryErr<'a> {
122122
#[label(borrowck::returned_lifetime_wrong)]
123123
WrongReturn {
@@ -149,7 +149,7 @@ impl IntoDiagnosticArg for RegionName {
149149
}
150150
}
151151

152-
#[derive(SessionSubdiagnostic)]
152+
#[derive(Subdiagnostic)]
153153
pub(crate) enum RequireStaticErr {
154154
#[note(borrowck::used_impl_require_static)]
155155
UsedImpl {

compiler/rustc_error_messages/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ type FluentId = Cow<'static, str>;
268268
/// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent
269269
/// message so messages of this type must be combined with a `DiagnosticMessage` (using
270270
/// `DiagnosticMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
271-
/// the `SessionSubdiagnostic` derive refer to Fluent identifiers directly.
271+
/// the `Subdiagnostic` derive refer to Fluent identifiers directly.
272272
#[rustc_diagnostic_item = "SubdiagnosticMessage"]
273273
pub enum SubdiagnosticMessage {
274274
/// Non-translatable diagnostic message.
275275
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
276276
Str(String),
277277
/// Identifier of a Fluent message. Instances of this variant are generated by the
278-
/// `SessionSubdiagnostic` derive.
278+
/// `Subdiagnostic` derive.
279279
FluentIdentifier(FluentId),
280280
/// Attribute of a Fluent message. Needs to be combined with a Fluent identifier to produce an
281281
/// actual translated message. Instances of this variant are generated by the `fluent_messages`

compiler/rustc_errors/src/diagnostic.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ impl IntoDiagnosticArg for hir::ConstContext {
176176
}
177177

178178
/// Trait implemented by error types. This should not be implemented manually. Instead, use
179-
/// `#[derive(SessionSubdiagnostic)]` -- see [rustc_macros::SessionSubdiagnostic].
180-
#[rustc_diagnostic_item = "AddSubdiagnostic"]
179+
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
180+
#[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")]
181+
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Subdiagnostic")]
181182
pub trait AddToDiagnostic {
182183
/// Add a subdiagnostic to an existing diagnostic.
183184
fn add_to_diagnostic(self, diag: &mut Diagnostic);
@@ -891,8 +892,8 @@ impl Diagnostic {
891892
self
892893
}
893894

894-
/// Add a subdiagnostic from a type that implements `SessionSubdiagnostic` - see
895-
/// [rustc_macros::SessionSubdiagnostic].
895+
/// Add a subdiagnostic from a type that implements `Subdiagnostic` - see
896+
/// [rustc_macros::Subdiagnostic].
896897
pub fn subdiagnostic(&mut self, subdiagnostic: impl AddToDiagnostic) -> &mut Self {
897898
subdiagnostic.add_to_diagnostic(self);
898899
self

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ pub fn compile_declarative_macro(
593593
(mk_syn_ext(expander), rule_spans)
594594
}
595595

596-
#[derive(SessionSubdiagnostic)]
596+
#[derive(Subdiagnostic)]
597597
enum ExplainDocComment {
598598
#[label(expand::explain_doc_comment_inner)]
599599
Inner {

compiler/rustc_lint/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler};
2-
use rustc_macros::{Diagnostic, SessionSubdiagnostic};
2+
use rustc_macros::{Diagnostic, Subdiagnostic};
33
use rustc_session::lint::Level;
44
use rustc_span::{Span, Symbol};
55

@@ -51,7 +51,7 @@ pub struct MalformedAttribute {
5151
pub sub: MalformedAttributeSub,
5252
}
5353

54-
#[derive(SessionSubdiagnostic)]
54+
#[derive(Subdiagnostic)]
5555
pub enum MalformedAttributeSub {
5656
#[label(lint::bad_attribute_argument)]
5757
BadAttributeArgument(#[primary_span] Span),

compiler/rustc_lint/src/internal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics {
404404
let Impl { of_trait: Some(of_trait), .. } = impl_ &&
405405
let Some(def_id) = of_trait.trait_def_id() &&
406406
let Some(name) = cx.tcx.get_diagnostic_name(def_id) &&
407-
matches!(name, sym::Diagnostic | sym::AddSubdiagnostic | sym::DecorateLint)
407+
matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint)
408408
{
409409
found_impl = true;
410410
break;

compiler/rustc_macros/src/diagnostics/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive};
99
pub(crate) use fluent::fluent_messages;
1010
use proc_macro2::TokenStream;
1111
use quote::format_ident;
12-
use subdiagnostic::SessionSubdiagnosticDerive;
12+
use subdiagnostic::SubdiagnosticDerive;
1313
use synstructure::Structure;
1414

1515
/// Implements `#[derive(Diagnostic)]`, which allows for errors to be specified as a struct,
@@ -108,12 +108,12 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
108108
LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens()
109109
}
110110

111-
/// Implements `#[derive(SessionSubdiagnostic)]`, which allows for labels, notes, helps and
111+
/// Implements `#[derive(Subdiagnostic)]`, which allows for labels, notes, helps and
112112
/// suggestions to be specified as a structs or enums, independent from the actual diagnostics
113113
/// emitting code or diagnostic derives.
114114
///
115115
/// ```ignore (rust)
116-
/// #[derive(SessionSubdiagnostic)]
116+
/// #[derive(Subdiagnostic)]
117117
/// pub enum ExpectedIdentifierLabel<'tcx> {
118118
/// #[label(parser::expected_identifier)]
119119
/// WithoutFound {
@@ -128,7 +128,7 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
128128
/// }
129129
/// }
130130
///
131-
/// #[derive(SessionSubdiagnostic)]
131+
/// #[derive(Subdiagnostic)]
132132
/// #[suggestion_verbose(parser::raw_identifier)]
133133
/// pub struct RawIdentifierSuggestion<'tcx> {
134134
/// #[primary_span]
@@ -155,5 +155,5 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
155155
/// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
156156
/// ```
157157
pub fn session_subdiagnostic_derive(s: Structure<'_>) -> TokenStream {
158-
SessionSubdiagnosticDerive::new(s).into_tokens()
158+
SubdiagnosticDerive::new(s).into_tokens()
159159
}

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ impl quote::IdentFragment for SubdiagnosticKind {
9898
}
9999

100100
/// The central struct for constructing the `add_to_diagnostic` method from an annotated struct.
101-
pub(crate) struct SessionSubdiagnosticDerive<'a> {
101+
pub(crate) struct SubdiagnosticDerive<'a> {
102102
structure: Structure<'a>,
103103
diag: syn::Ident,
104104
}
105105

106-
impl<'a> SessionSubdiagnosticDerive<'a> {
106+
impl<'a> SubdiagnosticDerive<'a> {
107107
pub(crate) fn new(structure: Structure<'a>) -> Self {
108108
let diag = format_ident!("diag");
109109
Self { structure, diag }
110110
}
111111

112112
pub(crate) fn into_tokens(self) -> TokenStream {
113-
let SessionSubdiagnosticDerive { mut structure, diag } = self;
113+
let SubdiagnosticDerive { mut structure, diag } = self;
114114
let implementation = {
115115
let ast = structure.ast();
116116
let span = ast.span().unwrap();
@@ -119,7 +119,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
119119
syn::Data::Union(..) => {
120120
span_err(
121121
span,
122-
"`#[derive(SessionSubdiagnostic)]` can only be used on structs and enums",
122+
"`#[derive(Subdiagnostic)]` can only be used on structs and enums",
123123
);
124124
}
125125
}
@@ -146,7 +146,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
146146
}
147147
}
148148

149-
let mut builder = SessionSubdiagnosticDeriveBuilder {
149+
let mut builder = SubdiagnosticDeriveBuilder {
150150
diag: &diag,
151151
variant,
152152
span,
@@ -178,10 +178,10 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
178178
}
179179

180180
/// Tracks persistent information required for building up the call to add to the diagnostic
181-
/// for the final generated method. This is a separate struct to `SessionSubdiagnosticDerive`
181+
/// for the final generated method. This is a separate struct to `SubdiagnosticDerive`
182182
/// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a
183183
/// double mut borrow later on.
184-
struct SessionSubdiagnosticDeriveBuilder<'a> {
184+
struct SubdiagnosticDeriveBuilder<'a> {
185185
/// The identifier to use for the generated `DiagnosticBuilder` instance.
186186
diag: &'a syn::Ident,
187187

@@ -205,7 +205,7 @@ struct SessionSubdiagnosticDeriveBuilder<'a> {
205205
has_suggestion_parts: bool,
206206
}
207207

208-
impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> {
208+
impl<'a> HasFieldMap for SubdiagnosticDeriveBuilder<'a> {
209209
fn get_field_binding(&self, field: &String) -> Option<&TokenStream> {
210210
self.fields.get(field)
211211
}
@@ -241,7 +241,7 @@ impl<'a> FromIterator<&'a SubdiagnosticKind> for KindsStatistics {
241241
}
242242
}
243243

244-
impl<'a> SessionSubdiagnosticDeriveBuilder<'a> {
244+
impl<'a> SubdiagnosticDeriveBuilder<'a> {
245245
fn identify_kind(&mut self) -> Result<Vec<(SubdiagnosticKind, Path)>, DiagnosticDeriveError> {
246246
let mut kind_slugs = vec![];
247247

compiler/rustc_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ decl_derive!(
161161
suggestion_verbose)] => diagnostics::lint_diagnostic_derive
162162
);
163163
decl_derive!(
164-
[SessionSubdiagnostic, attributes(
164+
[Subdiagnostic, attributes(
165165
// struct/variant attributes
166166
label,
167167
help,

compiler/rustc_middle/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct OpaqueHiddenTypeMismatch<'tcx> {
2525
pub sub: TypeMismatchReason,
2626
}
2727

28-
#[derive(SessionSubdiagnostic)]
28+
#[derive(Subdiagnostic)]
2929
pub enum TypeMismatchReason {
3030
#[label(middle::conflict_types)]
3131
ConflictType {

compiler/rustc_parse/src/parser/diagnostics.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_errors::{
2020
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
2121
};
2222
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed};
23-
use rustc_macros::{Diagnostic, SessionSubdiagnostic};
23+
use rustc_macros::{Diagnostic, Subdiagnostic};
2424
use rustc_span::source_map::Spanned;
2525
use rustc_span::symbol::{kw, sym, Ident};
2626
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
@@ -261,7 +261,7 @@ struct BadTypePlus {
261261
pub sub: BadTypePlusSub,
262262
}
263263

264-
#[derive(SessionSubdiagnostic)]
264+
#[derive(Subdiagnostic)]
265265
pub enum BadTypePlusSub {
266266
#[suggestion(
267267
parser::add_paren,
@@ -342,7 +342,7 @@ pub struct InvalidVariableDeclaration {
342342
pub sub: InvalidVariableDeclarationSub,
343343
}
344344

345-
#[derive(SessionSubdiagnostic)]
345+
#[derive(Subdiagnostic)]
346346
pub enum InvalidVariableDeclarationSub {
347347
#[suggestion(
348348
parser::switch_mut_let_order,
@@ -372,7 +372,7 @@ pub(crate) struct InvalidComparisonOperator {
372372
pub sub: InvalidComparisonOperatorSub,
373373
}
374374

375-
#[derive(SessionSubdiagnostic)]
375+
#[derive(Subdiagnostic)]
376376
pub(crate) enum InvalidComparisonOperatorSub {
377377
#[suggestion_short(
378378
parser::use_instead,
@@ -400,7 +400,7 @@ pub(crate) struct InvalidLogicalOperator {
400400
pub sub: InvalidLogicalOperatorSub,
401401
}
402402

403-
#[derive(SessionSubdiagnostic)]
403+
#[derive(Subdiagnostic)]
404404
pub(crate) enum InvalidLogicalOperatorSub {
405405
#[suggestion_short(
406406
parser::use_amp_amp_for_conjunction,
@@ -605,7 +605,7 @@ pub(crate) struct IfExpressionMissingThenBlock {
605605
pub sub: IfExpressionMissingThenBlockSub,
606606
}
607607

608-
#[derive(SessionSubdiagnostic)]
608+
#[derive(Subdiagnostic)]
609609
pub(crate) enum IfExpressionMissingThenBlockSub {
610610
#[help(parser::condition_possibly_unfinished)]
611611
UnfinishedCondition(#[primary_span] Span),
@@ -668,7 +668,7 @@ pub(crate) struct MissingInInForLoop {
668668
pub sub: MissingInInForLoopSub,
669669
}
670670

671-
#[derive(SessionSubdiagnostic)]
671+
#[derive(Subdiagnostic)]
672672
pub(crate) enum MissingInInForLoopSub {
673673
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
674674
#[suggestion_short(parser::use_in_not_of, applicability = "maybe-incorrect", code = "in")]

compiler/rustc_passes/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::{Applicability, MultiSpan};
2-
use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic};
2+
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
33
use rustc_span::{Span, Symbol};
44

55
#[derive(LintDiagnostic)]
@@ -583,7 +583,7 @@ pub struct MacroExport;
583583
#[diag(passes::plugin_registrar)]
584584
pub struct PluginRegistrar;
585585

586-
#[derive(SessionSubdiagnostic)]
586+
#[derive(Subdiagnostic)]
587587
pub enum UnusedNote {
588588
#[note(passes::unused_empty_lints_note)]
589589
EmptyList { name: Symbol },

compiler/rustc_privacy/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::DiagnosticArgFromDisplay;
2-
use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic};
2+
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
33
use rustc_span::{Span, Symbol};
44

55
#[derive(Diagnostic)]
@@ -14,7 +14,7 @@ pub struct FieldIsPrivate {
1414
pub label: FieldIsPrivateLabel,
1515
}
1616

17-
#[derive(SessionSubdiagnostic)]
17+
#[derive(Subdiagnostic)]
1818
pub enum FieldIsPrivateLabel {
1919
#[label(privacy::field_is_private_is_update_syntax_label)]
2020
IsUpdateSyntax {

0 commit comments

Comments
 (0)