Skip to main content

DiagnosticDeriveVariantBuilder

Struct DiagnosticDeriveVariantBuilder 

Source
pub(crate) struct DiagnosticDeriveVariantBuilder {
    pub formatting_init: TokenStream,
    pub span: Span,
    pub field_map: IndexMap<String, (Ident, TokenStream)>,
    pub message: Option<Message>,
    pub code: Option<((), Span)>,
    pub used_fields: HashSet<Ident>,
}
Expand description

Tracks persistent information required for a specific variant when building up individual calls to diagnostic methods for generated diagnostic derives.

Fields§

§formatting_init: TokenStream

Initialization of format strings for code suggestions.

§span: Span

Span of the struct or the enum variant.

§field_map: IndexMap<String, (Ident, TokenStream)>

Store a map of field name to its corresponding field. This is built on construction of the derive builder.

§message: Option<Message>

Message 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.

§used_fields: HashSet<Ident>

Implementations§

Source§

impl DiagnosticDeriveVariantBuilder

Source

pub(crate) fn primary_message(&self) -> Option<&Message>

Source

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.

Source

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.

Source

fn is_used_in_message(&self, binding: &BindingInfo<'_>) -> bool

Source

fn parse_subdiag_attribute( &mut self, attr: &Attribute, ) -> Result<Option<(SubdiagnosticKind, Message, bool)>, DiagnosticDeriveError>

Parse a SubdiagnosticKind from an Attribute.

Source

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 message and error code. Generates diagnostic builder calls for setting error code and creating note/help messages.

Source

fn generate_field_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream

Source

fn generate_field_attrs_code( &mut self, binding_info: &BindingInfo<'_>, ) -> TokenStream

Source

fn generate_inner_field_code( &mut self, attr: &Attribute, info: FieldInfo<'_>, binding: TokenStream, ) -> Result<TokenStream, DiagnosticDeriveError>

Source

fn add_spanned_subdiagnostic( &self, field_binding: TokenStream, kind: &Ident, message: Message, ) -> TokenStream

Adds a spanned subdiagnostic by generating a diag.span_$kind call with the current message and fluent_attr_identifier.

Source

fn add_subdiagnostic(&self, kind: &Ident, message: Message) -> TokenStream

Adds a subdiagnostic by generating a diag.span_$kind call with the current message and fluent_attr_identifier.

Source

fn span_and_applicability_of_ty( &self, info: FieldInfo<'_>, ) -> Result<(TokenStream, Option<(TokenStream, Span)>), DiagnosticDeriveError>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.