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            LinkName { .. } => Yes, // Needed for rustdoc
54            LinkOrdinal { .. } => No,
55            LinkSection { .. } => Yes, // Needed for rustdoc
56            Linkage(..) => No,
57            LoopMatch(..) => No,
58            MacroEscape(..) => No,
59            MacroTransparency(..) => Yes,
60            MacroUse { .. } => No,
61            Marker(..) => No,
62            MayDangle(..) => No,
63            MustUse { .. } => Yes,
64            Naked(..) => No,
65            NoImplicitPrelude(..) => No,
66            NoMangle(..) => Yes,      // Needed for rustdoc
67            NonExhaustive(..) => Yes, // Needed for rustdoc
68            Optimize(..) => No,
69            ParenSugar(..) => No,
70            PassByValue(..) => Yes,
71            Path(..) => No,
72            Pointee(..) => No,
73            ProcMacro(..) => No,
74            ProcMacroAttribute(..) => No,
75            ProcMacroDerive { .. } => No,
76            PubTransparent(..) => Yes,
77            Repr { .. } => No,
78            RustcBuiltinMacro { .. } => Yes,
79            RustcLayoutScalarValidRangeEnd(..) => Yes,
80            RustcLayoutScalarValidRangeStart(..) => Yes,
81            RustcObjectLifetimeDefault => No,
82            Sanitize { .. } => No,
83            ShouldPanic { .. } => No,
84            SkipDuringMethodDispatch { .. } => No,
85            SpecializationTrait(..) => No,
86            Stability { .. } => Yes,
87            StdInternalSymbol(..) => No,
88            TargetFeature { .. } => No,
89            TrackCaller(..) => Yes,
90            TypeConst(..) => Yes,
91            UnsafeSpecializationMarker(..) => No,
92            UnstableFeatureBound(..) => No,
93            Used { .. } => No,
94            // tidy-alphabetical-end
95        }
96    }
97}