pub(crate) struct DiagnosticDeriveVariantBuilder {
pub kind: DiagnosticDeriveKind,
pub formatting_init: TokenStream,
pub span: Span,
pub field_map: HashMap<String, TokenStream>,
pub slug: Option<(Path, Span)>,
pub code: Option<((), Span)>,
}Expand description
Tracks persistent information required for a specific variant when building up individual calls
to diagnostic methods for generated diagnostic derives - both Diagnostic for
fatal/errors/warnings and LintDiagnostic for lints.
Fields§
§kind: DiagnosticDeriveKindThe kind for the entire type.
formatting_init: TokenStreamInitialization of format strings for code suggestions.
span: SpanSpan of the struct or the enum variant.
field_map: HashMap<String, TokenStream>Store a map of field name to its corresponding field. This is built on construction of the derive builder.
slug: Option<(Path, Span)>Slug is a mandatory part of the struct attribute as corresponds to the Fluent message that has the actual diagnostic message.
code: Option<((), Span)>Error codes are a optional part of the struct attribute - this is only set to detect multiple specifications.
Implementations§
Source§impl DiagnosticDeriveVariantBuilder
impl DiagnosticDeriveVariantBuilder
Sourcepub(crate) fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream
pub(crate) fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream
Generates calls to code and similar functions based on the attributes on the type or
variant.
Sourcepub(crate) fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream
pub(crate) fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream
Generates calls to span_label and similar functions based on the attributes on fields or
calls to arg when no attributes are present.
Sourcefn parse_subdiag_attribute(
&self,
attr: &Attribute,
) -> Result<Option<(SubdiagnosticKind, Path, bool)>, DiagnosticDeriveError>
fn parse_subdiag_attribute( &self, attr: &Attribute, ) -> Result<Option<(SubdiagnosticKind, Path, bool)>, DiagnosticDeriveError>
Parse a SubdiagnosticKind from an Attribute.
Sourcefn generate_structure_code_for_attr(
&mut self,
attr: &Attribute,
) -> Result<TokenStream, DiagnosticDeriveError>
fn generate_structure_code_for_attr( &mut self, attr: &Attribute, ) -> Result<TokenStream, DiagnosticDeriveError>
Establishes state in the DiagnosticDeriveBuilder resulting from the struct
attributes like #[diag(..)], such as the slug and error code. Generates
diagnostic builder calls for setting error code and creating note/help messages.
fn generate_field_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream
fn generate_field_attrs_code( &mut self, binding_info: &BindingInfo<'_>, ) -> TokenStream
fn generate_inner_field_code( &mut self, attr: &Attribute, info: FieldInfo<'_>, binding: TokenStream, ) -> Result<TokenStream, DiagnosticDeriveError>
Sourcefn add_spanned_subdiagnostic(
&self,
field_binding: TokenStream,
kind: &Ident,
fluent_attr_identifier: Path,
) -> TokenStream
fn add_spanned_subdiagnostic( &self, field_binding: TokenStream, kind: &Ident, fluent_attr_identifier: Path, ) -> TokenStream
Adds a spanned subdiagnostic by generating a diag.span_$kind call with the current slug
and fluent_attr_identifier.
Sourcefn add_subdiagnostic(
&self,
kind: &Ident,
fluent_attr_identifier: Path,
) -> TokenStream
fn add_subdiagnostic( &self, kind: &Ident, fluent_attr_identifier: Path, ) -> TokenStream
Adds a subdiagnostic by generating a diag.span_$kind call with the current slug
and fluent_attr_identifier.
fn span_and_applicability_of_ty( &self, info: FieldInfo<'_>, ) -> Result<(TokenStream, Option<(TokenStream, Span)>), DiagnosticDeriveError>
Trait Implementations§
Source§impl HasFieldMap for DiagnosticDeriveVariantBuilder
impl HasFieldMap for DiagnosticDeriveVariantBuilder
Source§fn get_field_binding(&self, field: &String) -> Option<&TokenStream>
fn get_field_binding(&self, field: &String) -> Option<&TokenStream>
Source§fn build_format(&self, input: &str, span: Span) -> TokenStream
fn build_format(&self, input: &str, span: Span) -> TokenStream
Auto Trait Implementations§
impl Freeze for DiagnosticDeriveVariantBuilder
impl RefUnwindSafe for DiagnosticDeriveVariantBuilder
impl !Send for DiagnosticDeriveVariantBuilder
impl !Sync for DiagnosticDeriveVariantBuilder
impl Unpin for DiagnosticDeriveVariantBuilder
impl UnwindSafe for DiagnosticDeriveVariantBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more