rustc_attr_data_structures/
attributes.rs
1use rustc_abi::Align;
2use rustc_ast as ast;
3use rustc_macros::{Decodable, Encodable, HashStable_Generic};
4use rustc_span::{Span, Symbol};
5
6use crate::RustcVersion;
7
8#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
9pub enum InlineAttr {
10 None,
11 Hint,
12 Always,
13 Never,
14 Force {
18 attr_span: Span,
19 reason: Option<Symbol>,
20 },
21}
22
23impl InlineAttr {
24 pub fn always(&self) -> bool {
25 match self {
26 InlineAttr::Always | InlineAttr::Force { .. } => true,
27 InlineAttr::None | InlineAttr::Hint | InlineAttr::Never => false,
28 }
29 }
30}
31
32#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic)]
33pub enum InstructionSetAttr {
34 ArmA32,
35 ArmT32,
36}
37
38#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic, Default)]
39pub enum OptimizeAttr {
40 #[default]
42 Default,
43 DoNotOptimize,
45 Speed,
47 Size,
49}
50
51impl OptimizeAttr {
52 pub fn do_not_optimize(&self) -> bool {
53 matches!(self, Self::DoNotOptimize)
54 }
55}
56
57#[derive(Clone, Debug, Encodable, Decodable)]
58pub enum DiagnosticAttribute {
59 DoNotRecommend,
61 OnUnimplemented,
62 }
64
65#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone)]
66pub enum ReprAttr {
67 ReprInt(IntType),
68 ReprRust,
69 ReprC,
70 ReprPacked(Align),
71 ReprSimd,
72 ReprTransparent,
73 ReprAlign(Align),
74}
75pub use ReprAttr::*;
76
77pub enum TransparencyError {
78 UnknownTransparency(Symbol, Span),
79 MultipleTransparencyAttrs(Span, Span),
80}
81
82#[derive(Eq, PartialEq, Debug, Copy, Clone)]
83#[derive(Encodable, Decodable)]
84pub enum IntType {
85 SignedInt(ast::IntTy),
86 UnsignedInt(ast::UintTy),
87}
88
89#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
90pub struct Deprecation {
91 pub since: DeprecatedSince,
92 pub note: Option<Symbol>,
94 pub suggestion: Option<Symbol>,
98}
99
100#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
102pub enum DeprecatedSince {
103 RustcVersion(RustcVersion),
104 Future,
106 NonStandard(Symbol),
109 Unspecified,
111 Err,
114}
115
116impl Deprecation {
117 pub fn is_in_effect(&self) -> bool {
121 match self.since {
122 DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT,
123 DeprecatedSince::Future => false,
124 DeprecatedSince::NonStandard(_) => true,
126 DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
128 }
129 }
130
131 pub fn is_since_rustc_version(&self) -> bool {
132 matches!(self.since, DeprecatedSince::RustcVersion(_))
133 }
134}