Skip to content

Commit

Permalink
UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Browse files Browse the repository at this point in the history
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
  • Loading branch information
JhonnyBillM committed Sep 21, 2022
1 parent a3396b2 commit 5f91719
Show file tree
Hide file tree
Showing 24 changed files with 130 additions and 128 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay};
use rustc_macros::{Diagnostic, SessionSubdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};

#[derive(Diagnostic, Clone, Copy)]
Expand Down Expand Up @@ -221,7 +221,7 @@ pub struct InvalidAsmTemplateModifierRegClass {
pub sub: InvalidAsmTemplateModifierRegClassSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum InvalidAsmTemplateModifierRegClassSub {
#[note(ast_lowering::support_modifiers)]
SupportModifier { class_name: Symbol, modifiers: String },
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct InvalidVisibility {
pub note: Option<InvalidVisibilityNote>,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum InvalidVisibilityNote {
#[note(ast_passes::individual_impl_items)]
IndividualImplItems,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) struct InvalidIssueString {

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

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum IncorrectReprFormatGenericCause<'a> {
#[suggestion(attr::suggestion, code = "{name}({int})", applicability = "machine-applicable")]
Int {
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::{IntoDiagnosticArg, MultiSpan};
use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty;
use rustc_span::Span;

Expand All @@ -23,7 +23,7 @@ pub(crate) struct HigherRankedLifetimeError {
pub span: Span,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum HigherRankedErrorCause {
#[note(borrowck::could_not_prove)]
CouldNotProve { predicate: String },
Expand Down Expand Up @@ -72,7 +72,7 @@ pub(crate) struct FnMutError {
pub ty_err: FnMutReturnTypeErr,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum VarHereDenote {
#[label(borrowck::var_here_captured)]
Captured {
Expand All @@ -91,7 +91,7 @@ pub(crate) enum VarHereDenote {
},
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum FnMutReturnTypeErr {
#[label(borrowck::returned_closure_escaped)]
ReturnClosure {
Expand All @@ -117,7 +117,7 @@ pub(crate) struct LifetimeOutliveErr {
pub span: Span,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum LifetimeReturnCategoryErr<'a> {
#[label(borrowck::returned_lifetime_wrong)]
WrongReturn {
Expand Down Expand Up @@ -149,7 +149,7 @@ impl IntoDiagnosticArg for RegionName {
}
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum RequireStaticErr {
#[note(borrowck::used_impl_require_static)]
UsedImpl {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ type FluentId = Cow<'static, str>;
/// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent
/// message so messages of this type must be combined with a `DiagnosticMessage` (using
/// `DiagnosticMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from
/// the `SessionSubdiagnostic` derive refer to Fluent identifiers directly.
/// the `Subdiagnostic` derive refer to Fluent identifiers directly.
#[rustc_diagnostic_item = "SubdiagnosticMessage"]
pub enum SubdiagnosticMessage {
/// Non-translatable diagnostic message.
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
Str(String),
/// Identifier of a Fluent message. Instances of this variant are generated by the
/// `SessionSubdiagnostic` derive.
/// `Subdiagnostic` derive.
FluentIdentifier(FluentId),
/// Attribute of a Fluent message. Needs to be combined with a Fluent identifier to produce an
/// actual translated message. Instances of this variant are generated by the `fluent_messages`
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ impl IntoDiagnosticArg for hir::ConstContext {
}

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

/// Add a subdiagnostic from a type that implements `SessionSubdiagnostic` - see
/// [rustc_macros::SessionSubdiagnostic].
/// Add a subdiagnostic from a type that implements `Subdiagnostic` - see
/// [rustc_macros::Subdiagnostic].
pub fn subdiagnostic(&mut self, subdiagnostic: impl AddToDiagnostic) -> &mut Self {
subdiagnostic.add_to_diagnostic(self);
self
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ pub fn compile_declarative_macro(
(mk_syn_ext(expander), rule_spans)
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
enum ExplainDocComment {
#[label(expand::explain_doc_comment_inner)]
Inner {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler};
use rustc_macros::{Diagnostic, SessionSubdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::lint::Level;
use rustc_span::{Span, Symbol};

Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct MalformedAttribute {
pub sub: MalformedAttributeSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum MalformedAttributeSub {
#[label(lint::bad_attribute_argument)]
BadAttributeArgument(#[primary_span] Span),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics {
let Impl { of_trait: Some(of_trait), .. } = impl_ &&
let Some(def_id) = of_trait.trait_def_id() &&
let Some(name) = cx.tcx.get_diagnostic_name(def_id) &&
matches!(name, sym::Diagnostic | sym::AddSubdiagnostic | sym::DecorateLint)
matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint)
{
found_impl = true;
break;
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_macros/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive};
pub(crate) use fluent::fluent_messages;
use proc_macro2::TokenStream;
use quote::format_ident;
use subdiagnostic::SessionSubdiagnosticDerive;
use subdiagnostic::SubdiagnosticDerive;
use synstructure::Structure;

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

/// Implements `#[derive(SessionSubdiagnostic)]`, which allows for labels, notes, helps and
/// Implements `#[derive(Subdiagnostic)]`, which allows for labels, notes, helps and
/// suggestions to be specified as a structs or enums, independent from the actual diagnostics
/// emitting code or diagnostic derives.
///
/// ```ignore (rust)
/// #[derive(SessionSubdiagnostic)]
/// #[derive(Subdiagnostic)]
/// pub enum ExpectedIdentifierLabel<'tcx> {
/// #[label(parser::expected_identifier)]
/// WithoutFound {
Expand All @@ -128,7 +128,7 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// }
/// }
///
/// #[derive(SessionSubdiagnostic)]
/// #[derive(Subdiagnostic)]
/// #[suggestion_verbose(parser::raw_identifier)]
/// pub struct RawIdentifierSuggestion<'tcx> {
/// #[primary_span]
Expand All @@ -155,5 +155,5 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream {
/// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
/// ```
pub fn session_subdiagnostic_derive(s: Structure<'_>) -> TokenStream {
SessionSubdiagnosticDerive::new(s).into_tokens()
SubdiagnosticDerive::new(s).into_tokens()
}
18 changes: 9 additions & 9 deletions compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ impl quote::IdentFragment for SubdiagnosticKind {
}

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

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

pub(crate) fn into_tokens(self) -> TokenStream {
let SessionSubdiagnosticDerive { mut structure, diag } = self;
let SubdiagnosticDerive { mut structure, diag } = self;
let implementation = {
let ast = structure.ast();
let span = ast.span().unwrap();
Expand All @@ -119,7 +119,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
syn::Data::Union(..) => {
span_err(
span,
"`#[derive(SessionSubdiagnostic)]` can only be used on structs and enums",
"`#[derive(Subdiagnostic)]` can only be used on structs and enums",
);
}
}
Expand All @@ -146,7 +146,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
}
}

let mut builder = SessionSubdiagnosticDeriveBuilder {
let mut builder = SubdiagnosticDeriveBuilder {
diag: &diag,
variant,
span,
Expand Down Expand Up @@ -178,10 +178,10 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
}

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

Expand All @@ -205,7 +205,7 @@ struct SessionSubdiagnosticDeriveBuilder<'a> {
has_suggestion_parts: bool,
}

impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> {
impl<'a> HasFieldMap for SubdiagnosticDeriveBuilder<'a> {
fn get_field_binding(&self, field: &String) -> Option<&TokenStream> {
self.fields.get(field)
}
Expand Down Expand Up @@ -241,7 +241,7 @@ impl<'a> FromIterator<&'a SubdiagnosticKind> for KindsStatistics {
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ decl_derive!(
suggestion_verbose)] => diagnostics::lint_diagnostic_derive
);
decl_derive!(
[SessionSubdiagnostic, attributes(
[Subdiagnostic, attributes(
// struct/variant attributes
label,
help,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct OpaqueHiddenTypeMismatch<'tcx> {
pub sub: TypeMismatchReason,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum TypeMismatchReason {
#[label(middle::conflict_types)]
ConflictType {
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_errors::{
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
};
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed};
use rustc_macros::{Diagnostic, SessionSubdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
Expand Down Expand Up @@ -261,7 +261,7 @@ struct BadTypePlus {
pub sub: BadTypePlusSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum BadTypePlusSub {
#[suggestion(
parser::add_paren,
Expand Down Expand Up @@ -342,7 +342,7 @@ pub struct InvalidVariableDeclaration {
pub sub: InvalidVariableDeclarationSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum InvalidVariableDeclarationSub {
#[suggestion(
parser::switch_mut_let_order,
Expand Down Expand Up @@ -372,7 +372,7 @@ pub(crate) struct InvalidComparisonOperator {
pub sub: InvalidComparisonOperatorSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum InvalidComparisonOperatorSub {
#[suggestion_short(
parser::use_instead,
Expand Down Expand Up @@ -400,7 +400,7 @@ pub(crate) struct InvalidLogicalOperator {
pub sub: InvalidLogicalOperatorSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum InvalidLogicalOperatorSub {
#[suggestion_short(
parser::use_amp_amp_for_conjunction,
Expand Down Expand Up @@ -605,7 +605,7 @@ pub(crate) struct IfExpressionMissingThenBlock {
pub sub: IfExpressionMissingThenBlockSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum IfExpressionMissingThenBlockSub {
#[help(parser::condition_possibly_unfinished)]
UnfinishedCondition(#[primary_span] Span),
Expand Down Expand Up @@ -668,7 +668,7 @@ pub(crate) struct MissingInInForLoop {
pub sub: MissingInInForLoopSub,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub(crate) enum MissingInInForLoopSub {
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
#[suggestion_short(parser::use_in_not_of, applicability = "maybe-incorrect", code = "in")]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::{Applicability, MultiSpan};
use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};

#[derive(LintDiagnostic)]
Expand Down Expand Up @@ -583,7 +583,7 @@ pub struct MacroExport;
#[diag(passes::plugin_registrar)]
pub struct PluginRegistrar;

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum UnusedNote {
#[note(passes::unused_empty_lints_note)]
EmptyList { name: Symbol },
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_privacy/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::DiagnosticArgFromDisplay;
use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};

#[derive(Diagnostic)]
Expand All @@ -14,7 +14,7 @@ pub struct FieldIsPrivate {
pub label: FieldIsPrivateLabel,
}

#[derive(SessionSubdiagnostic)]
#[derive(Subdiagnostic)]
pub enum FieldIsPrivateLabel {
#[label(privacy::field_is_private_is_update_syntax_label)]
IsUpdateSyntax {
Expand Down
Loading

0 comments on commit 5f91719

Please sign in to comment.