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,
},
RustcIntrinsic,
RustcTestEntrypointMarker,
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)].
RustcIntrinsic
Represents #[rustc_intrinsic]
RustcTestEntrypointMarker
Represents #[rustc_test_entrypoint_marker]
ShouldPanic
Represents #[should_panic]
TargetFeature
Represents #[target_feature(enable = "...")] and
#[unsafe(force_target_feature(enable = "...")].
TrackCaller(Span)
Represents #[track_caller]
Trait Implementations§
Source§impl AstVisitable for AttributeKind
impl AstVisitable for AttributeKind
Source§fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_two<V: ZipAst>(&self, other: &Self, v: &mut V) -> ControlFlow<V::Break>
fn drive_two<V: ZipAst>(&self, other: &Self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
self, in pre-order traversal.Source§fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
self, in pre-order traversal.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 Display for AttributeKind
Print a built-in attribute the way it is written in the source.
impl Display for AttributeKind
Print a built-in attribute the way it is written in the source.
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, 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, 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, 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, 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<'s, V> DriveTwo<'s, V> for AttributeKindwhere
V: Visitor<Break: Default> + VisitTwo<'s, Deprecation> + VisitTwo<'s, Span> + VisitTwo<'s, Option<Ustr>> + VisitTwo<'s, InlineAttr> + VisitTwo<'s, OptimizeAttr> + VisitTwo<'s, u64> + VisitTwo<'s, Vec<(Ustr, Span)>> + VisitTwo<'s, bool>,
impl<'s, V> DriveTwo<'s, V> for AttributeKindwhere
V: Visitor<Break: Default> + VisitTwo<'s, Deprecation> + VisitTwo<'s, Span> + VisitTwo<'s, Option<Ustr>> + VisitTwo<'s, InlineAttr> + VisitTwo<'s, OptimizeAttr> + VisitTwo<'s, u64> + VisitTwo<'s, Vec<(Ustr, Span)>> + VisitTwo<'s, bool>,
Source§fn drive_two_inner(
&'s self,
other: &'s Self,
visitor: &mut V,
) -> ControlFlow<V::Break>
fn drive_two_inner( &'s self, other: &'s Self, visitor: &mut V, ) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self and other, if they correspond. If
the values don’t match up, this returns Break(Default::default()).impl Eq for AttributeKind
Source§impl PartialEq for AttributeKind
impl PartialEq for AttributeKind
Source§impl Serialize for AttributeKind
impl Serialize 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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreimpl<T> Mappable for T
Source§impl<T> TyVisitable for Twhere
T: AstVisitable,
impl<T> TyVisitable for Twhere
T: AstVisitable,
Source§fn visit_vars(&mut self, v: &mut impl VarsVisitor)
fn visit_vars(&mut self, v: &mut impl VarsVisitor)
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen De Bruijn indices
will count from the outside of self.Source§fn substitute(self, generics: &GenericArgs) -> Self
fn substitute(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
Note: if self is an item that comes from a TraitDecl, you must use
substitute_with_self or substitute_inner_binder, otherwise you’ll get panics.Source§fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
This is appropriate when substituting an inner binder.Source§fn substitute_explicits(self, generics: &GenericArgs) -> Self
fn substitute_explicits(self, generics: &GenericArgs) -> Self
Source§fn substitute_with_self(
self,
generics: &GenericArgs,
self_ref: &TraitRefKind,
) -> Self
fn substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Self
TraitRefKind::SelfId trait ref.Source§fn substitute_with_tref(self, tref: &TraitRef) -> Self
fn substitute_with_tref(self, tref: &TraitRef) -> Self
TraitRefKind::SelfId trait ref.Source§fn try_substitute_with_tref(
self,
tref: &TraitRef,
) -> Result<Self, GenericsMismatch>
fn try_substitute_with_tref( self, tref: &TraitRef, ) -> Result<Self, GenericsMismatch>
TraitRefKind::SelfId trait ref.fn try_substitute( self, generics: &GenericArgs, ) -> Result<Self, GenericsMismatch>
fn try_substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Result<Self, GenericsMismatch>
Source§fn move_under_binder(self) -> Self
fn move_under_binder(self) -> Self
Source§fn move_under_binders(self, depth: DeBruijnId) -> Self
fn move_under_binders(self, depth: DeBruijnId) -> Self
depth binders.Source§fn move_from_under_binder(self) -> Option<Self>
fn move_from_under_binder(self) -> Option<Self>
Source§fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
depth binders. Returns None if it contains a variable bound in
one of these depth binders.Source§fn visit_db_id<B>(
&mut self,
f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>,
) -> ControlFlow<B>
fn visit_db_id<B>( &mut self, f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>, ) -> ControlFlow<B>
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen indices will count
from the outside of self.