rustc_hir/attrs/
encode_cross_crate.rs

1use crate::attrs::AttributeKind;
2
3#[derive(PartialEq)]
4pub enum EncodeCrossCrate {
5    Yes,
6    No,
7}
8
9impl AttributeKind {
10    /// Whether this attribute should be encoded in metadata files.
11    ///
12    /// If this is "Yes", then another crate can do `tcx.get_all_attrs(did)` for a did in this crate, and get the attribute.
13    /// When this is No, the attribute is filtered out while encoding and other crate won't be able to observe it.
14    /// This can be unexpectedly good for performance, so unless necessary for cross-crate compilation, prefer No.
15    pub fn encode_cross_crate(&self) -> EncodeCrossCrate {
16        use AttributeKind::*;
17        use EncodeCrossCrate::*;
18
19        match self {
20            // tidy-alphabetical-start
21            Align { .. } => No,
22            AllowConstFnUnstable(..) => No,
23            AllowIncoherentImpl(..) => No,
24            AllowInternalUnsafe(..) => Yes,
25            AllowInternalUnstable(..) => Yes,
26            AsPtr(..) => Yes,
27            AutomaticallyDerived(..) => Yes,
28            BodyStability { .. } => No,
29            Coinductive(..) => No,
30            Cold(..) => No,
31            Confusables { .. } => Yes,
32            ConstContinue(..) => No,
33            ConstStability { .. } => Yes,
34            ConstStabilityIndirect => No,
35            ConstTrait(..) => No,
36            Coroutine(..) => No,
37            Coverage(..) => No,
38            CrateName { .. } => No,
39            CustomMir(_, _, _) => Yes,
40            DenyExplicitImpl(..) => No,
41            Deprecation { .. } => Yes,
42            DoNotImplementViaObject(..) => No,
43            DocComment { .. } => Yes,
44            Dummy => No,
45            ExportName { .. } => Yes,
46            ExportStable => No,
47            FfiConst(..) => No,
48            FfiPure(..) => No,
49            Fundamental { .. } => Yes,
50            Ignore { .. } => No,
51            Inline(..) => No,
52            Link(..) => No,
53            LinkName { .. } => Yes, // Needed for rustdoc
54            LinkOrdinal { .. } => No,
55            LinkSection { .. } => Yes, // Needed for rustdoc
56            Linkage(..) => No,
57            LoopMatch(..) => No,
58            MacroEscape(..) => No,
59            MacroExport { .. } => Yes,
60            MacroTransparency(..) => Yes,
61            MacroUse { .. } => No,
62            Marker(..) => No,
63            MayDangle(..) => No,
64            MoveSizeLimit { .. } => No,
65            MustUse { .. } => Yes,
66            Naked(..) => No,
67            NoCore(..) => No,
68            NoImplicitPrelude(..) => No,
69            NoMangle(..) => Yes, // Needed for rustdoc
70            NoStd(..) => No,
71            NonExhaustive(..) => Yes, // Needed for rustdoc
72            ObjcClass { .. } => No,
73            ObjcSelector { .. } => No,
74            Optimize(..) => No,
75            ParenSugar(..) => No,
76            PassByValue(..) => Yes,
77            Path(..) => No,
78            PatternComplexityLimit { .. } => No,
79            Pointee(..) => No,
80            ProcMacro(..) => No,
81            ProcMacroAttribute(..) => No,
82            ProcMacroDerive { .. } => No,
83            PubTransparent(..) => Yes,
84            RecursionLimit { .. } => No,
85            Repr { .. } => No,
86            RustcBuiltinMacro { .. } => Yes,
87            RustcCoherenceIsCore(..) => No,
88            RustcLayoutScalarValidRangeEnd(..) => Yes,
89            RustcLayoutScalarValidRangeStart(..) => Yes,
90            RustcObjectLifetimeDefault => No,
91            Sanitize { .. } => No,
92            ShouldPanic { .. } => No,
93            SkipDuringMethodDispatch { .. } => No,
94            SpecializationTrait(..) => No,
95            Stability { .. } => Yes,
96            StdInternalSymbol(..) => No,
97            TargetFeature { .. } => No,
98            TrackCaller(..) => Yes,
99            TypeConst(..) => Yes,
100            TypeLengthLimit { .. } => No,
101            UnsafeSpecializationMarker(..) => No,
102            UnstableFeatureBound(..) => No,
103            Used { .. } => No,
104            // tidy-alphabetical-end
105        }
106    }
107}