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