rustc_attr_data_structures/
attributes.rs1use rustc_abi::Align;
2use rustc_ast::token::CommentKind;
3use rustc_ast::{self as ast, AttrStyle};
4use rustc_macros::{Decodable, Encodable, HashStable_Generic, PrintAttribute};
5use rustc_span::hygiene::Transparency;
6use rustc_span::{Span, Symbol};
7use thin_vec::ThinVec;
8
9use crate::{DefaultBodyStability, PartialConstStability, PrintAttribute, RustcVersion, Stability};
10
11#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
12pub enum InlineAttr {
13 None,
14 Hint,
15 Always,
16 Never,
17 Force {
21 attr_span: Span,
22 reason: Option<Symbol>,
23 },
24}
25
26impl InlineAttr {
27 pub fn always(&self) -> bool {
28 match self {
29 InlineAttr::Always | InlineAttr::Force { .. } => true,
30 InlineAttr::None | InlineAttr::Hint | InlineAttr::Never => false,
31 }
32 }
33}
34
35#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic)]
36pub enum InstructionSetAttr {
37 ArmA32,
38 ArmT32,
39}
40
41#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic, Default)]
42pub enum OptimizeAttr {
43 #[default]
45 Default,
46 DoNotOptimize,
48 Speed,
50 Size,
52}
53
54impl OptimizeAttr {
55 pub fn do_not_optimize(&self) -> bool {
56 matches!(self, Self::DoNotOptimize)
57 }
58}
59
60#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic, PrintAttribute)]
61pub enum DiagnosticAttribute {
62 DoNotRecommend,
64 OnUnimplemented,
65 }
67
68#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone, HashStable_Generic, PrintAttribute)]
69pub enum ReprAttr {
70 ReprInt(IntType),
71 ReprRust,
72 ReprC,
73 ReprPacked(Align),
74 ReprSimd,
75 ReprTransparent,
76 ReprAlign(Align),
77 ReprEmpty,
79}
80pub use ReprAttr::*;
81
82pub enum TransparencyError {
83 UnknownTransparency(Symbol, Span),
84 MultipleTransparencyAttrs(Span, Span),
85}
86
87#[derive(Eq, PartialEq, Debug, Copy, Clone)]
88#[derive(Encodable, Decodable, HashStable_Generic, PrintAttribute)]
89pub enum IntType {
90 SignedInt(ast::IntTy),
91 UnsignedInt(ast::UintTy),
92}
93
94#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
95pub struct Deprecation {
96 pub since: DeprecatedSince,
97 pub note: Option<Symbol>,
99 pub suggestion: Option<Symbol>,
103}
104
105#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
107pub enum DeprecatedSince {
108 RustcVersion(RustcVersion),
109 Future,
111 NonStandard(Symbol),
114 Unspecified,
116 Err,
119}
120
121impl Deprecation {
122 pub fn is_in_effect(&self) -> bool {
126 match self.since {
127 DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT,
128 DeprecatedSince::Future => false,
129 DeprecatedSince::NonStandard(_) => true,
131 DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
133 }
134 }
135
136 pub fn is_since_rustc_version(&self) -> bool {
137 matches!(self.since, DeprecatedSince::RustcVersion(_))
138 }
139}
140
141#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
161pub enum AttributeKind {
162 AllowConstFnUnstable(ThinVec<Symbol>),
164 AllowInternalUnstable(ThinVec<(Symbol, Span)>),
165 BodyStability {
166 stability: DefaultBodyStability,
167 span: Span,
169 },
170 Confusables {
171 symbols: ThinVec<Symbol>,
172 first_span: Span,
174 },
175 ConstStability {
176 stability: PartialConstStability,
177 span: Span,
179 },
180 ConstStabilityIndirect,
181 Deprecation {
182 deprecation: Deprecation,
183 span: Span,
184 },
185 Diagnostic(DiagnosticAttribute),
186 DocComment {
187 style: AttrStyle,
188 kind: CommentKind,
189 span: Span,
190 comment: Symbol,
191 },
192 MacroTransparency(Transparency),
193 Repr(ThinVec<(ReprAttr, Span)>),
194 RustcMacroEdition2021,
195 Stability {
196 stability: Stability,
197 span: Span,
199 },
200 }