Skip to main content

AttributeParser

Trait AttributeParser 

Source
pub(crate) trait AttributeParser: Default + 'static {
    const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))];
    const ALLOWED_TARGETS: AllowedTargets<'_>;
    const SAFETY: AttributeSafety = AttributeSafety::Normal;

    // Required method
    fn finalize(self, cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind>;

    // Provided method
    fn deferred_finalize_check(
        &self,
    ) -> Option<(fn(&FinalizeCheckContext<'_, '_>, Span), Span)> { ... }
}
Expand description

An AttributeParser is a type which searches for syntactic attributes.

Parsers are often tiny state machines that gets to see all syntactical attributes on an item. Default::default creates a fresh instance that sits in some kind of initial state, usually that the attribute it is looking for was not yet seen.

Then, it defines what paths this group will accept in AttributeParser::ATTRIBUTES. These are listed as pairs, of symbols and function pointers. The function pointer will be called when that attribute is found on an item, which can influence the state of the little state machine.

Finally, after all attributes on an item have been seen, and possibly been accepted, the finalize functions for all attribute parsers are called. Each can then report whether it has seen the attribute it has been looking for.

The state machine is automatically reset to parse attributes on the next item.

For a simpler attribute parsing interface, consider using SingleAttributeParser or CombineAttributeParser instead.

Required Associated Constants§

Source

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

The symbols for the attributes that this parser is interested in.

If an attribute has this symbol, the accept function will be called on it.

Source

const ALLOWED_TARGETS: AllowedTargets<'_>

Provided Associated Constants§

Source

const SAFETY: AttributeSafety = AttributeSafety::Normal

Required Methods§

Source

fn finalize(self, cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind>

The parser has gotten a chance to accept the attributes on an item, here it can produce an attribute.

All finalize methods of all parsers are unconditionally called. This means you can’t unconditionally return Some here, that’d be equivalent to unconditionally applying an attribute to every single syntax item that could have attributes applied to it. Your accept mappings should determine whether this returns something.

Provided Methods§

Source

fn deferred_finalize_check( &self, ) -> Option<(fn(&FinalizeCheckContext<'_, '_>, Span), Span)>

If this parser produced an attribute, optionally returns a cross-attribute check to run once all attributes on the item have been finalized, together with the span it should be reported at.

Running after finalization means the check can inspect the fully parsed attributes via FinalizeCheckContext::parsed_attrs, which are not yet all available during finalize. This is queried right before finalize consumes the parser state.

Defaults to no check.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl AttributeParser for BodyStabilityParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_> = ALLOWED_TARGETS

Source§

impl AttributeParser for ConfusablesParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for ConstStabilityParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for DocParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for MacroUseParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_> = MACRO_USE_ALLOWED_TARGETS

Source§

impl AttributeParser for NakedParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const SAFETY: AttributeSafety

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for OnConstParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for OnMoveParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for OnTypeErrorParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for OnUnimplementedParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for OnUnknownParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for OnUnmatchedArgsParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for OpaqueParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for RustcAlignParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for RustcAlignStaticParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for RustcCguTestAttributeParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl AttributeParser for StabilityParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_> = ALLOWED_TARGETS

Source§

impl AttributeParser for UsedParser

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_>

Source§

impl<T: CombineAttributeParser> AttributeParser for Combine<T>

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_> = T::ALLOWED_TARGETS

Source§

const SAFETY: AttributeSafety = T::SAFETY

Source§

impl<T: SingleAttributeParser> AttributeParser for Single<T>

Source§

const ATTRIBUTES: &'static [(&'static [Symbol], AttributeTemplate, AttributeStability, for<'sess> fn(&mut Self, &mut AcceptContext<'_, 'sess>, &ArgParser))]

Source§

const ALLOWED_TARGETS: AllowedTargets<'_> = T::ALLOWED_TARGETS

Source§

const SAFETY: AttributeSafety = T::SAFETY