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 inliningOptimizeAttr
is used to control optimization levelsInstructionSetAttr
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)]
.
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
stability: DefaultBodyStability
Cold(Span)
Represents #[cold]
.
Confusables
Represents #[rustc_confusables]
.
ConstContinue(Span)
Represents #[const_continue]
.
ConstStability
Represents #[rustc_const_stable]
and #[rustc_const_unstable]
.
Fields
stability: PartialConstStability
ConstStabilityIndirect
Represents #[rustc_const_stable_indirect]
.
Deprecation
Represents #[deprecated]
.
DocComment
Represents #[doc]
.
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
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]
.
Stability
Represents #[stable]
, #[unstable]
and #[rustc_allowed_through_unstable_modules]
.
TrackCaller(Span)
Represents #[track_caller]
Implementations§
Source§impl AttributeKind
impl AttributeKind
pub fn encode_cross_crate(&self) -> EncodeCrossCrate
Trait Implementations§
Source§impl Clone for AttributeKind
impl Clone for AttributeKind
Source§fn clone(&self) -> AttributeKind
fn clone(&self) -> AttributeKind
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AttributeKind
impl Debug for AttributeKind
Source§impl<__D: SpanDecoder> Decodable<__D> for AttributeKind
impl<__D: SpanDecoder> Decodable<__D> for AttributeKind
Source§impl<__E: SpanEncoder> Encodable<__E> for AttributeKind
impl<__E: SpanEncoder> Encodable<__E> for AttributeKind
Source§impl<__CTX> HashStable<__CTX> for AttributeKindwhere
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for AttributeKindwhere
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
Source§impl PrintAttribute for AttributeKind
impl PrintAttribute for AttributeKind
Source§fn should_render(&self) -> bool
fn should_render(&self) -> bool
fn print_attribute(&self, __p: &mut Printer)
Auto Trait Implementations§
impl DynSend for AttributeKind
impl DynSync for AttributeKind
impl Freeze for AttributeKind
impl RefUnwindSafe for AttributeKind
impl Send for AttributeKind
impl Sync for AttributeKind
impl Unpin for AttributeKind
impl UnwindSafe for AttributeKind
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
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 bytesAllowConstFnUnstable
: 15 bytesAllowInternalUnstable
: 15 bytesAsPtr
: 11 bytesBodyStability
: 35 bytesCold
: 11 bytesConfusables
: 23 bytesConstContinue
: 11 bytesConstStability
: 39 bytesConstStabilityIndirect
: 0 bytesDeprecation
: 27 bytesDocComment
: 15 bytesInline
: 23 bytesLoopMatch
: 11 bytesMacroTransparency
: 1 byteMayDangle
: 11 bytesMustUse
: 15 bytesNaked
: 11 bytesNoMangle
: 11 bytesOptimize
: 11 bytesPubTransparent
: 11 bytesRepr
: 15 bytesSkipDuringMethodDispatch
: 11 bytesStability
: 35 bytesTrackCaller
: 11 bytes