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            CoherenceIsCore => No,
30            Coinductive(..) => No,
31            Cold(..) => No,
32            Confusables { .. } => Yes,
33            ConstContinue(..) => No,
34            ConstStability { .. } => Yes,
35            ConstStabilityIndirect => No,
36            ConstTrait(..) => No,
37            Coroutine(..) => No,
38            Coverage(..) => No,
39            CrateName { .. } => No,
40            CustomMir(_, _, _) => Yes,
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            MacroTransparency(..) => Yes,
61            MacroUse { .. } => No,
62            Marker(..) => No,
63            MayDangle(..) => No,
64            MoveSizeLimit { .. } => No,
65            MustUse { .. } => Yes,
66            Naked(..) => No,
67            NoImplicitPrelude(..) => No,
68            NoMangle(..) => Yes,      // Needed for rustdoc
69            NonExhaustive(..) => Yes, // Needed for rustdoc
70            Optimize(..) => No,
71            ParenSugar(..) => No,
72            PassByValue(..) => Yes,
73            Path(..) => No,
74            PatternComplexityLimit { .. } => No,
75            Pointee(..) => No,
76            ProcMacro(..) => No,
77            ProcMacroAttribute(..) => No,
78            ProcMacroDerive { .. } => No,
79            PubTransparent(..) => Yes,
80            RecursionLimit { .. } => No,
81            Repr { .. } => No,
82            RustcBuiltinMacro { .. } => Yes,
83            RustcLayoutScalarValidRangeEnd(..) => Yes,
84            RustcLayoutScalarValidRangeStart(..) => Yes,
85            RustcObjectLifetimeDefault => No,
86            Sanitize { .. } => No,
87            ShouldPanic { .. } => No,
88            SkipDuringMethodDispatch { .. } => No,
89            SpecializationTrait(..) => No,
90            Stability { .. } => Yes,
91            StdInternalSymbol(..) => No,
92            TargetFeature { .. } => No,
93            TrackCaller(..) => Yes,
94            TypeConst(..) => Yes,
95            TypeLengthLimit { .. } => No,
96            UnsafeSpecializationMarker(..) => No,
97            UnstableFeatureBound(..) => No,
98            Used { .. } => No,
99            // tidy-alphabetical-end
100        }
101    }
102}