Skip to main content

rustc_hir/attrs/
encode_cross_crate.rs

1use crate::attrs::AttributeKind;
2
3#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for EncodeCrossCrate {
    #[inline]
    fn eq(&self, other: &EncodeCrossCrate) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}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            AllowInternalUnsafe(..) => Yes,
23            AllowInternalUnstable(..) => Yes,
24            AutomaticallyDerived(..) => Yes,
25            CfgAttrTrace => Yes,
26            CfgTrace(..) => Yes,
27            CfiEncoding { .. } => Yes,
28            Cold(..) => No,
29            CollapseDebugInfo(..) => Yes,
30            CompilerBuiltins => No,
31            ConstContinue(..) => No,
32            Coroutine(..) => No,
33            Coverage(..) => No,
34            CrateName { .. } => No,
35            CrateType(_) => No,
36            CustomMir(_, _, _) => Yes,
37            DebuggerVisualizer(..) => No,
38            DefaultLibAllocator => No,
39            Deprecation { .. } => Yes,
40            DoNotRecommend { .. } => Yes,
41            Doc(_) => Yes,
42            DocComment { .. } => Yes,
43            EiiDeclaration(_) => Yes,
44            EiiForeignItem => No,
45            EiiImpls(..) => No,
46            ExportName { .. } => Yes,
47            ExportStable => No,
48            FfiConst(..) => No,
49            FfiPure(..) => No,
50            Fundamental { .. } => Yes,
51            Ignore { .. } => No,
52            Inline(..) => No,
53            InstructionSet(..) => No,
54            Lang(..) => Yes,
55            Link(..) => No,
56            LinkName { .. } => Yes, // Needed for rustdoc
57            LinkOrdinal { .. } => No,
58            LinkSection { .. } => Yes, // Needed for rustdoc
59            Linkage(..) => No,
60            LoopMatch(..) => No,
61            MacroEscape(..) => No,
62            MacroExport { .. } => Yes,
63            MacroUse { .. } => No,
64            Marker(..) => No,
65            MayDangle(..) => No,
66            MoveSizeLimit { .. } => No,
67            MustNotSupend { .. } => Yes,
68            MustUse { .. } => Yes,
69            Naked(..) => No,
70            NeedsAllocator => No,
71            NeedsPanicRuntime => No,
72            NoBuiltins => Yes,
73            NoCore(..) => No,
74            NoImplicitPrelude(..) => No,
75            NoLink => No,
76            NoMain => No,
77            NoMangle(..) => Yes, // Needed for rustdoc
78            NoStd(..) => No,
79            NonExhaustive(..) => Yes, // Needed for rustdoc
80            Optimize(..) => No,
81            PanicRuntime => No,
82            PatchableFunctionEntry { .. } => Yes,
83            Path(..) => No,
84            PatternComplexityLimit { .. } => No,
85            PinV2(..) => Yes,
86            Pointee(..) => No,
87            PreludeImport => No,
88            ProcMacro(..) => No,
89            ProcMacroAttribute(..) => No,
90            ProcMacroDerive { .. } => No,
91            ProfilerRuntime => No,
92            RecursionLimit { .. } => No,
93            ReexportTestHarnessMain(..) => No,
94            Repr { .. } => No,
95            RustcAbi { .. } => No,
96            RustcAllocator => No,
97            RustcAllocatorZeroed => No,
98            RustcAllocatorZeroedVariant { .. } => Yes,
99            RustcAllowConstFnUnstable(..) => No,
100            RustcAllowIncoherentImpl(..) => No,
101            RustcAsPtr(..) => Yes,
102            RustcBodyStability { .. } => No,
103            RustcBuiltinMacro { .. } => Yes,
104            RustcCaptureAnalysis => No,
105            RustcCguTestAttr { .. } => No,
106            RustcClean { .. } => No,
107            RustcCoherenceIsCore(..) => No,
108            RustcCoinductive(..) => No,
109            RustcConfusables { .. } => Yes,
110            RustcConstStability { .. } => Yes,
111            RustcConstStabilityIndirect => No,
112            RustcConversionSuggestion => Yes,
113            RustcDeallocator => No,
114            RustcDefPath(..) => No,
115            RustcDelayedBugFromInsideQuery => No,
116            RustcDenyExplicitImpl(..) => No,
117            RustcDeprecatedSafe2024 { .. } => Yes,
118            RustcDiagnosticItem(..) => Yes,
119            RustcDoNotConstCheck => Yes,
120            RustcDummy => No,
121            RustcDumpDefParents => No,
122            RustcDumpItemBounds => No,
123            RustcDumpPredicates => No,
124            RustcDumpUserArgs => No,
125            RustcDumpVtable(..) => No,
126            RustcDynIncompatibleTrait(..) => No,
127            RustcEffectiveVisibility => Yes,
128            RustcEvaluateWhereClauses => Yes,
129            RustcHasIncoherentInherentImpls => Yes,
130            RustcHiddenTypeOfOpaques => No,
131            RustcIfThisChanged(..) => No,
132            RustcInsignificantDtor => Yes,
133            RustcIntrinsic => Yes,
134            RustcIntrinsicConstStableIndirect => No,
135            RustcLayout(..) => No,
136            RustcLayoutScalarValidRangeEnd(..) => Yes,
137            RustcLayoutScalarValidRangeStart(..) => Yes,
138            RustcLegacyConstGenerics { .. } => Yes,
139            RustcLintOptDenyFieldAccess { .. } => Yes,
140            RustcLintOptTy => Yes,
141            RustcLintQueryInstability => Yes,
142            RustcLintUntrackedQueryInformation => Yes,
143            RustcMacroTransparency(..) => Yes,
144            RustcMain => No,
145            RustcMir(..) => Yes,
146            RustcMustImplementOneOf { .. } => No,
147            RustcNeverReturnsNullPointer => Yes,
148            RustcNeverTypeOptions { .. } => No,
149            RustcNoImplicitAutorefs => Yes,
150            RustcNoImplicitBounds => No,
151            RustcNoMirInline => Yes,
152            RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
153            RustcNonnullOptimizationGuaranteed => Yes,
154            RustcNounwind => No,
155            RustcObjcClass { .. } => No,
156            RustcObjcSelector { .. } => No,
157            RustcObjectLifetimeDefault => No,
158            RustcOffloadKernel => Yes,
159            RustcOutlives => No,
160            RustcParenSugar(..) => No,
161            RustcPassByValue(..) => Yes,
162            RustcPassIndirectlyInNonRusticAbis(..) => No,
163            RustcPreserveUbChecks => No,
164            RustcProcMacroDecls => No,
165            RustcPubTransparent(..) => Yes,
166            RustcReallocator => No,
167            RustcRegions => No,
168            RustcReservationImpl(..) => Yes,
169            RustcScalableVector { .. } => Yes,
170            RustcShouldNotBeCalledOnConstItems(..) => Yes,
171            RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
172            RustcSkipDuringMethodDispatch { .. } => No,
173            RustcSpecializationTrait(..) => No,
174            RustcStdInternalSymbol(..) => No,
175            RustcStrictCoherence(..) => Yes,
176            RustcSymbolName(..) => Yes,
177            RustcTestMarker(..) => No,
178            RustcThenThisWouldNeed(..) => No,
179            RustcTrivialFieldReads => Yes,
180            RustcUnsafeSpecializationMarker(..) => No,
181            RustcVariance => No,
182            RustcVarianceOfOpaques => No,
183            Sanitize { .. } => No,
184            ShouldPanic { .. } => No,
185            Stability { .. } => Yes,
186            TargetFeature { .. } => No,
187            TestRunner(..) => Yes,
188            ThreadLocal => No,
189            TrackCaller(..) => Yes,
190            TypeLengthLimit { .. } => No,
191            UnstableFeatureBound(..) => No,
192            Used { .. } => No,
193            WindowsSubsystem(..) => No,
194            // tidy-alphabetical-end
195        }
196    }
197}