1use rustc_abi::Align;
2use rustc_ast::token::CommentKind;
3use rustc_ast::{selfas ast, AttrStyle};
4use rustc_macros::{Decodable, Encodable, HashStable_Generic, PrintAttribute};
5use rustc_span::hygiene::Transparency;
6use rustc_span::{Span, Symbol};
7use thin_vec::ThinVec;
89use crate::{DefaultBodyStability, PartialConstStability, PrintAttribute, RustcVersion, Stability};
1011#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
12pub enum InlineAttr {
13None,
14 Hint,
15 Always,
16 Never,
17/// `#[rustc_force_inline]` forces inlining to happen in the MIR inliner - it reports an error
18 /// if the inlining cannot happen. It is limited to only free functions so that the calls
19 /// can always be resolved.
20Force {
21 attr_span: Span,
22 reason: Option<Symbol>,
23 },
24}
2526impl InlineAttr {
27pub fn always(&self) -> bool {
28match self{
29InlineAttr::Always | InlineAttr::Force { .. } => true,
30InlineAttr::None | InlineAttr::Hint | InlineAttr::Never => false,
31 }
32 }
33}
3435#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic)]
36pub enum InstructionSetAttr {
37 ArmA32,
38 ArmT32,
39}
4041#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic, Default)]
42pub enum OptimizeAttr {
43/// No `#[optimize(..)]` attribute
44#[default]
45Default,
46/// `#[optimize(none)]`
47DoNotOptimize,
48/// `#[optimize(speed)]`
49Speed,
50/// `#[optimize(size)]`
51Size,
52}
5354impl OptimizeAttr {
55pub fn do_not_optimize(&self) -> bool {
56matches!(self, Self::DoNotOptimize)
57 }
58}
5960#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic, PrintAttribute)]
61pub enum DiagnosticAttribute {
62// tidy-alphabetical-start
63DoNotRecommend,
64 OnUnimplemented,
65// tidy-alphabetical-end
66}
6768#[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// this one is just so we can emit a lint for it
78ReprEmpty,
79}
80pub use ReprAttr::*;
8182pub enum TransparencyError {
83 UnknownTransparency(Symbol, Span),
84 MultipleTransparencyAttrs(Span, Span),
85}
8687#[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}
9394#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
95pub struct Deprecation {
96pub since: DeprecatedSince,
97/// The note to issue a reason.
98pub note: Option<Symbol>,
99/// A text snippet used to completely replace any use of the deprecated item in an expression.
100 ///
101 /// This is currently unstable.
102pub suggestion: Option<Symbol>,
103}
104105/// Release in which an API is deprecated.
106#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
107pub enum DeprecatedSince {
108 RustcVersion(RustcVersion),
109/// Deprecated in the future ("to be determined").
110Future,
111/// `feature(staged_api)` is off. Deprecation versions outside the standard
112 /// library are allowed to be arbitrary strings, for better or worse.
113NonStandard(Symbol),
114/// Deprecation version is unspecified but optional.
115Unspecified,
116/// Failed to parse a deprecation version, or the deprecation version is
117 /// unspecified and required. An error has already been emitted.
118Err,
119}
120121impl Deprecation {
122/// Whether an item marked with #[deprecated(since = "X")] is currently
123 /// deprecated (i.e., whether X is not greater than the current rustc
124 /// version).
125pub fn is_in_effect(&self) -> bool {
126match self.since {
127DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT,
128DeprecatedSince::Future => false,
129// The `since` field doesn't have semantic purpose without `#![staged_api]`.
130DeprecatedSince::NonStandard(_) => true,
131// Assume deprecation is in effect if "since" field is absent or invalid.
132DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
133 }
134 }
135136pub fn is_since_rustc_version(&self) -> bool {
137matches!(self.since, DeprecatedSince::RustcVersion(_))
138 }
139}
140141/// Represent parsed, *built in*, inert attributes.
142///
143/// That means attributes that are not actually ever expanded.
144/// For more information on this, see the module docs on the [`rustc_attr_parsing`] crate.
145/// They're instead used as markers, to guide the compilation process in various way in most every stage of the compiler.
146/// These are kept around after the AST, into the HIR and further on.
147///
148/// The word "parsed" could be a little misleading here, because the parser already parses
149/// attributes early on. However, the result, an [`ast::Attribute`]
150/// is only parsed at a high level, still containing a token stream in many cases. That is
151/// because the structure of the contents varies from attribute to attribute.
152/// With a parsed attribute I mean that each attribute is processed individually into a
153/// final structure, which on-site (the place where the attribute is useful for, think the
154/// the place where `must_use` is checked) little to no extra parsing or validating needs to
155/// happen.
156///
157/// For more docs, look in [`rustc_attr_parsing`].
158///
159/// [`rustc_attr_parsing`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html
160#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
161pub enum AttributeKind {
162// tidy-alphabetical-start
163AllowConstFnUnstable(ThinVec<Symbol>),
164 AllowInternalUnstable(ThinVec<(Symbol, Span)>),
165 BodyStability {
166 stability: DefaultBodyStability,
167/// Span of the `#[rustc_default_body_unstable(...)]` attribute
168span: Span,
169 },
170 Confusables {
171 symbols: ThinVec<Symbol>,
172// FIXME(jdonszelmann): remove when target validation code is moved
173first_span: Span,
174 },
175 ConstStability {
176 stability: PartialConstStability,
177/// Span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` attribute
178span: 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 of the `#[stable(...)]` or `#[unstable(...)]` attribute
198span: Span,
199 },
200// tidy-alphabetical-end
201}