pub enum AttributeKind {
Show 18 variants
AutomaticallyDerived,
Cold,
Deprecated {
deprecation: Deprecation,
span: Span,
},
Fundamental,
Ignore {
span: Span,
reason: Option<Ustr>,
},
Inline(InlineAttr, Span),
MayDangle(Span),
Naked(Span),
NoLink,
NoMangle(Span),
NonExhaustive(Span),
Optimize(OptimizeAttr, Span),
RustcAlign {
align: u64,
span: Span,
},
RustcDiagnosticItem(Ustr),
RustcIntrinsic,
ShouldPanic {
reason: Option<Ustr>,
},
TargetFeature {
features: Vec<(Ustr, Span)>,
attr_span: Span,
was_forced: bool,
},
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 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:
InlineAttris used during code generation to control function inliningOptimizeAttris used to control optimization levelsInstructionSetAttris 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§
AutomaticallyDerived
Represents #[automatically_derived]
Cold
Represents #[cold].
Deprecated
Represents #[deprecated].
Fundamental
Represents #[fundamental].
Ignore
Represents #[ignore]
Fields
Inline(InlineAttr, Span)
Represents #[inline] and #[rustc_force_inline].
MayDangle(Span)
Represents #[may_dangle].
Naked(Span)
Represents #[naked]
NoLink
Represents #[no_link]
NoMangle(Span)
Represents #[no_mangle]
NonExhaustive(Span)
Represents #[non_exhaustive]
Optimize(OptimizeAttr, Span)
Represents #[optimize(size|speed)]
RustcAlign
Represents #[align(N)].
RustcDiagnosticItem(Ustr)
Represents #[rustc_diagnostic_item]
RustcIntrinsic
Represents #[rustc_intrinsic]
ShouldPanic
Represents #[should_panic]
TargetFeature
Represents #[target_feature(enable = "...")] and
#[unsafe(force_target_feature(enable = "...")].
TrackCaller(Span)
Represents #[track_caller]
Trait Implementations§
Source§impl Clone for AttributeKind
impl Clone for AttributeKind
Source§fn clone(&self) -> AttributeKind
fn clone(&self) -> AttributeKind
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AttributeKind
impl Debug for AttributeKind
Source§impl<'de> Deserialize<'de> for AttributeKind
impl<'de> Deserialize<'de> for AttributeKind
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'s, V> Drive<'s, V> for AttributeKindwhere
V: Visitor + Visit<'s, Deprecation> + Visit<'s, Span> + Visit<'s, Option<Ustr>> + Visit<'s, InlineAttr> + Visit<'s, OptimizeAttr> + Visit<'s, u64> + Visit<'s, Ustr> + Visit<'s, Vec<(Ustr, Span)>> + Visit<'s, bool>,
impl<'s, V> Drive<'s, V> for AttributeKindwhere
V: Visitor + Visit<'s, Deprecation> + Visit<'s, Span> + Visit<'s, Option<Ustr>> + Visit<'s, InlineAttr> + Visit<'s, OptimizeAttr> + Visit<'s, u64> + Visit<'s, Ustr> + Visit<'s, Vec<(Ustr, Span)>> + Visit<'s, bool>,
Source§fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner(&'s self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl<'s, V> DriveMut<'s, V> for AttributeKindwhere
V: Visitor + VisitMut<'s, Deprecation> + VisitMut<'s, Span> + VisitMut<'s, Option<Ustr>> + VisitMut<'s, InlineAttr> + VisitMut<'s, OptimizeAttr> + VisitMut<'s, u64> + VisitMut<'s, Ustr> + VisitMut<'s, Vec<(Ustr, Span)>> + VisitMut<'s, bool>,
impl<'s, V> DriveMut<'s, V> for AttributeKindwhere
V: Visitor + VisitMut<'s, Deprecation> + VisitMut<'s, Span> + VisitMut<'s, Option<Ustr>> + VisitMut<'s, InlineAttr> + VisitMut<'s, OptimizeAttr> + VisitMut<'s, u64> + VisitMut<'s, Ustr> + VisitMut<'s, Vec<(Ustr, Span)>> + VisitMut<'s, bool>,
Source§fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
fn drive_inner_mut(&'s mut self, visitor: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl PartialEq for AttributeKind
impl PartialEq for AttributeKind
Source§fn eq(&self, other: &AttributeKind) -> bool
fn eq(&self, other: &AttributeKind) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for AttributeKind
impl Serialize for AttributeKind
impl Eq for AttributeKind
impl StructuralPartialEq for AttributeKind
Auto Trait Implementations§
impl Freeze for AttributeKind
impl RefUnwindSafe for AttributeKind
impl Send for AttributeKind
impl Sync for AttributeKind
impl Unpin for AttributeKind
impl UnsafeUnpin 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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more