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            DebuggerVisualizer(..) => No,
41            DenyExplicitImpl(..) => No,
42            Deprecation { .. } => Yes,
43            DoNotImplementViaObject(..) => No,
44            DocComment { .. } => Yes,
45            Dummy => No,
46            ExportName { .. } => Yes,
47            ExportStable => No,
48            FfiConst(..) => No,
49            FfiPure(..) => No,
50            Fundamental { .. } => Yes,
51            Ignore { .. } => No,
52            Inline(..) => No,
53            Link(..) => No,
54            LinkName { .. } => Yes, // Needed for rustdoc
55            LinkOrdinal { .. } => No,
56            LinkSection { .. } => Yes, // Needed for rustdoc
57            Linkage(..) => No,
58            LoopMatch(..) => No,
59            MacroEscape(..) => No,
60            MacroExport { .. } => Yes,
61            MacroTransparency(..) => Yes,
62            MacroUse { .. } => No,
63            Marker(..) => No,
64            MayDangle(..) => No,
65            MoveSizeLimit { .. } => No,
66            MustUse { .. } => Yes,
67            Naked(..) => No,
68            NoCore(..) => No,
69            NoImplicitPrelude(..) => No,
70            NoMangle(..) => Yes, // Needed for rustdoc
71            NoStd(..) => No,
72            NonExhaustive(..) => Yes, // Needed for rustdoc
73            ObjcClass { .. } => No,
74            ObjcSelector { .. } => No,
75            Optimize(..) => No,
76            ParenSugar(..) => No,
77            PassByValue(..) => Yes,
78            Path(..) => No,
79            PatternComplexityLimit { .. } => No,
80            Pointee(..) => No,
81            ProcMacro(..) => No,
82            ProcMacroAttribute(..) => No,
83            ProcMacroDerive { .. } => No,
84            PubTransparent(..) => Yes,
85            RecursionLimit { .. } => No,
86            Repr { .. } => No,
87            RustcBuiltinMacro { .. } => Yes,
88            RustcCoherenceIsCore(..) => No,
89            RustcLayoutScalarValidRangeEnd(..) => Yes,
90            RustcLayoutScalarValidRangeStart(..) => Yes,
91            RustcObjectLifetimeDefault => No,
92            RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
93            Sanitize { .. } => No,
94            ShouldPanic { .. } => No,
95            SkipDuringMethodDispatch { .. } => No,
96            SpecializationTrait(..) => No,
97            Stability { .. } => Yes,
98            StdInternalSymbol(..) => No,
99            TargetFeature { .. } => No,
100            TrackCaller(..) => Yes,
101            TypeConst(..) => Yes,
102            TypeLengthLimit { .. } => No,
103            UnsafeSpecializationMarker(..) => No,
104            UnstableFeatureBound(..) => No,
105            Used { .. } => No,
106            // tidy-alphabetical-end
107        }
108    }
109}