Skip to main content

Module attributes

Module attributes 

Source
Expand description

Traits for parsing attributes.

This module defines traits for attribute parsers, little state machines that recognize and parse attributes out of a longer list of attributes. The main trait is called AttributeParser. You can find more docs about AttributeParsers on the trait itself. However, for many types of attributes, implementing AttributeParser is not necessary. It allows for a lot of flexibility you might not want.

Specifically, you might not care about managing the state of your AttributeParser state machine yourself. In this case you can choose to implement:

  • NoArgsAttributeParser: used for implementing an attribute that appears only once and accepts no arguments
  • SingleAttributeParser: makes it easy to implement an attribute which should error if it appears more than once in a list of attributes
  • CombineAttributeParser: makes it easy to implement an attribute which should combine the contents of attributes, if an attribute appear multiple times in a list

Attributes should be added to crate::context::ATTRIBUTE_PARSERS to be parsed.

Modulesยง

allow_unstable ๐Ÿ”’
autodiff ๐Ÿ”’
body ๐Ÿ”’
Attributes that can be found in function body.
cfg ๐Ÿ”’
cfg_select ๐Ÿ”’
cfi_encoding ๐Ÿ”’
codegen_attrs ๐Ÿ”’
confusables ๐Ÿ”’
crate_level ๐Ÿ”’
debugger ๐Ÿ”’
deprecation ๐Ÿ”’
diagnostic ๐Ÿ”’
doc ๐Ÿ”’
dummy ๐Ÿ”’
inline ๐Ÿ”’
instruction_set ๐Ÿ”’
link_attrs ๐Ÿ”’
lint_helpers ๐Ÿ”’
loop_match ๐Ÿ”’
macro_attrs ๐Ÿ”’
must_not_suspend ๐Ÿ”’
must_use ๐Ÿ”’
no_implicit_prelude ๐Ÿ”’
no_link ๐Ÿ”’
non_exhaustive ๐Ÿ”’
path ๐Ÿ”’
pin_v2 ๐Ÿ”’
prelude ๐Ÿ”’
All the parsers require roughly the same imports, so this prelude has most of the often-needed ones.
proc_macro_attrs ๐Ÿ”’
prototype ๐Ÿ”’
Attributes that are only used on function prototypes.
repr ๐Ÿ”’
rustc_allocator ๐Ÿ”’
rustc_dump ๐Ÿ”’
rustc_internal ๐Ÿ”’
semantics ๐Ÿ”’
splat ๐Ÿ”’
Attribute parsing for the #[splat] function argument overloading attribute. This attribute modifies typecheck to support overload resolution, then modifies codegen for performance.
stability ๐Ÿ”’
test_attrs ๐Ÿ”’
traits ๐Ÿ”’
transparency ๐Ÿ”’
util ๐Ÿ”’

Structsยง

Combine ๐Ÿ”’
Use in combination with CombineAttributeParser. Combine<T: CombineAttributeParser> implements AttributeParser.
Single ๐Ÿ”’
Use in combination with SingleAttributeParser. Single<T: SingleAttributeParser> implements AttributeParser.
WithoutArgs ๐Ÿ”’

Enumsยง

AttributeSafety
OnDuplicate ๐Ÿ”’

Traitsยง

AttributeParser ๐Ÿ”’
An AttributeParser is a type which searches for syntactic attributes.
CombineAttributeParser ๐Ÿ”’
Alternative to AttributeParser that automatically handles state management. If multiple attributes appear on an element, combines the values of each into a ThinVec. Combine<T> where T: CombineAttributeParser implements AttributeParser.
NoArgsAttributeParser ๐Ÿ”’
An even simpler version of SingleAttributeParser: now automatically check that there are no arguments provided to the attribute.
SingleAttributeParser ๐Ÿ”’
Alternative to AttributeParser that automatically handles state management. A slightly simpler and more restricted way to convert attributes. Assumes that an attribute can only appear a single time on an item, and errors when it sees more.

Type Aliasesยง

AcceptFn ๐Ÿ”’
AcceptMapping ๐Ÿ”’
ConvertFn ๐Ÿ”’