Enum AttributeKind

Source
pub enum AttributeKind {
Show 25 variants Align { align: Align, span: Span, }, AllowConstFnUnstable(ThinVec<Symbol>), AllowInternalUnstable(ThinVec<(Symbol, Span)>), AsPtr(Span), BodyStability { stability: DefaultBodyStability, span: Span, }, Cold(Span), Confusables { symbols: ThinVec<Symbol>, first_span: Span, }, ConstContinue(Span), ConstStability { stability: PartialConstStability, span: Span, }, ConstStabilityIndirect, Deprecation { deprecation: Deprecation, span: Span, }, DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol, }, Inline(InlineAttr, Span), LoopMatch(Span), MacroTransparency(Transparency), MayDangle(Span), MustUse { span: Span, reason: Option<Symbol>, }, Naked(Span), NoMangle(Span), Optimize(OptimizeAttr, Span), PubTransparent(Span), Repr(ThinVec<(ReprAttr, Span)>), SkipDuringMethodDispatch { array: bool, boxed_slice: bool, span: Span, }, Stability { stability: Stability, span: Span, }, TrackCaller(Span),
}
Expand description

Represents parsed built-in inert attributes.

§Overview

These attributes are markers that guide the compilation process and are never expanded into other code. They persist throughout the compilation phases, from AST to HIR and beyond.

§Attribute Processing

While attributes are initially parsed by rustc_parse into ast::Attribute, they still contain raw token streams because different attributes have different internal structures. This enum represents the final, fully parsed form of these attributes, where each variant contains contains all the information and structure relevant for the specific attribute.

Some attributes can be applied multiple times to the same item, and they are “collapsed” into a single semantic attribute. For example:

#[repr(C)]
#[repr(packed)]
struct S { }

This is equivalent to #[repr(C, packed)] and results in a single AttributeKind::Repr containing both C and packed annotations. This collapsing happens during parsing and is reflected in the data structures defined in this enum.

§Usage

These parsed attributes are used throughout the compiler to:

  • Control code generation (e.g., #[repr])
  • Mark API stability (#[stable], #[unstable])
  • Provide documentation (#[doc])
  • Guide compiler behavior (e.g., #[allow_internal_unstable])

§Note on Attribute Organization

Some attributes like InlineAttr, OptimizeAttr, and InstructionSetAttr are defined separately from this enum because they are used in specific compiler phases (like code generation) and don’t need to persist throughout the entire compilation process. They are typically processed and converted into their final form earlier in the compilation pipeline.

For example:

  • InlineAttr is used during code generation to control function inlining
  • OptimizeAttr is used to control optimization levels
  • InstructionSetAttr is used for target-specific code generation

These attributes are handled by their respective compiler passes in the rustc_codegen_ssa crate and don’t need to be preserved in the same way as the attributes in this enum.

For more details on attribute parsing, see the rustc_attr_parsing crate.

Variants§

§

Align

Represents #[align(N)].

Fields

§align: Align
§span: Span
§

AllowConstFnUnstable(ThinVec<Symbol>)

Represents #[rustc_allow_const_fn_unstable].

§

AllowInternalUnstable(ThinVec<(Symbol, Span)>)

Represents #[allow_internal_unstable].

§

AsPtr(Span)

Represents #[rustc_as_ptr] (used by the dangling_pointers_from_temporaries lint).

§

BodyStability

Represents #[rustc_default_body_unstable].

Fields

§span: Span

Span of the #[rustc_default_body_unstable(...)] attribute

§

Cold(Span)

Represents #[cold].

§

Confusables

Represents #[rustc_confusables].

Fields

§symbols: ThinVec<Symbol>
§first_span: Span
§

ConstContinue(Span)

Represents #[const_continue].

§

ConstStability

Represents #[rustc_const_stable] and #[rustc_const_unstable].

Fields

§span: Span

Span of the #[rustc_const_stable(...)] or #[rustc_const_unstable(...)] attribute

§

ConstStabilityIndirect

Represents #[rustc_const_stable_indirect].

§

Deprecation

Represents #[deprecated].

Fields

§deprecation: Deprecation
§span: Span
§

DocComment

Represents #[doc].

Fields

§span: Span
§comment: Symbol
§

Inline(InlineAttr, Span)

Represents #[inline] and #[rustc_force_inline].

§

LoopMatch(Span)

Represents #[loop_match].

§

MacroTransparency(Transparency)

Represents #[rustc_macro_transparency].

§

MayDangle(Span)

Represents #[may_dangle].

§

MustUse

Represents #[must_use].

Fields

§span: Span
§reason: Option<Symbol>

must_use can optionally have a reason: #[must_use = "reason this must be used"]

§

Naked(Span)

Represents #[naked]

§

NoMangle(Span)

Represents #[no_mangle]

§

Optimize(OptimizeAttr, Span)

Represents #[optimize(size|speed)]

§

PubTransparent(Span)

Represents #[rustc_pub_transparent] (used by the repr_transparent_external_private_fields lint).

§

Repr(ThinVec<(ReprAttr, Span)>)

Represents #[repr].

§

SkipDuringMethodDispatch

Represents #[rustc_skip_during_method_dispatch].

Fields

§array: bool
§boxed_slice: bool
§span: Span
§

Stability

Represents #[stable], #[unstable] and #[rustc_allowed_through_unstable_modules].

Fields

§stability: Stability
§span: Span

Span of the attribute.

§

TrackCaller(Span)

Represents #[track_caller]

Implementations§

Trait Implementations§

Source§

impl Clone for AttributeKind

Source§

fn clone(&self) -> AttributeKind

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AttributeKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<__D: SpanDecoder> Decodable<__D> for AttributeKind

Source§

fn decode(__decoder: &mut __D) -> Self

Source§

impl<__E: SpanEncoder> Encodable<__E> for AttributeKind

Source§

fn encode(&self, __encoder: &mut __E)

Source§

impl<__CTX> HashStable<__CTX> for AttributeKind
where __CTX: HashStableContext,

Source§

fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)

Source§

impl PrintAttribute for AttributeKind

Source§

fn should_render(&self) -> bool

Whether or not this will render as something meaningful, or if it’s skipped (which will force the containing struct to also skip printing a comma and the field name).
Source§

fn print_attribute(&self, __p: &mut Printer)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Aligned for T

Source§

const ALIGN: Alignment

Alignment of Self.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 40 bytes

Size for each variant:

  • Align: 11 bytes
  • AllowConstFnUnstable: 15 bytes
  • AllowInternalUnstable: 15 bytes
  • AsPtr: 11 bytes
  • BodyStability: 35 bytes
  • Cold: 11 bytes
  • Confusables: 23 bytes
  • ConstContinue: 11 bytes
  • ConstStability: 39 bytes
  • ConstStabilityIndirect: 0 bytes
  • Deprecation: 27 bytes
  • DocComment: 15 bytes
  • Inline: 23 bytes
  • LoopMatch: 11 bytes
  • MacroTransparency: 1 byte
  • MayDangle: 11 bytes
  • MustUse: 15 bytes
  • Naked: 11 bytes
  • NoMangle: 11 bytes
  • Optimize: 11 bytes
  • PubTransparent: 11 bytes
  • Repr: 15 bytes
  • SkipDuringMethodDispatch: 11 bytes
  • Stability: 35 bytes
  • TrackCaller: 11 bytes