UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
This commit is contained in:
parent
a3396b2070
commit
5f91719f75
24 changed files with 130 additions and 128 deletions
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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]
|
||||
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
@ -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",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
let mut builder = SessionSubdiagnosticDeriveBuilder {
|
||||
let mut builder = SubdiagnosticDeriveBuilder {
|
||||
diag: &diag,
|
||||
variant,
|
||||
span,
|
||||
|
@ -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,
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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![];
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ decl_derive!(
|
|||
suggestion_verbose)] => diagnostics::lint_diagnostic_derive
|
||||
);
|
||||
decl_derive!(
|
||||
[SessionSubdiagnostic, attributes(
|
||||
[Subdiagnostic, attributes(
|
||||
// struct/variant attributes
|
||||
label,
|
||||
help,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue