Skip to main content

rustc_attr_ir/
encode_cross_crate.rs

1use crate::AttributeKind;
2
3#[derive(#[automatically_derived]impl ::core::marker::StructuralPartialEq for
    EncodeCrossCrate {
}
#[automatically_derived]impl ::core::cmp::PartialEq for EncodeCrossCrate {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}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            AllowInternalUnsafe(..) => Yes,
22            AllowInternalUnstable(..) => Yes,
23            AlwaysGca => 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            Deprecated { .. } => Yes,
40            DoNotRecommend => Yes,
41            Doc(_) => Yes,
42            DocComment { .. } => Yes,
43            EiiDeclaration(_) => Yes,
44            EiiImpl(..) => No,
45            ExportName { .. } => Yes,
46            ExportStable => No,
47            Feature(..) => No,
48            FfiConst => No,
49            FfiPure(..) => No,
50            Fundamental { .. } => Yes,
51            Ignore { .. } => No,
52            Inline(..) => No,
53            InstructionSet(..) => No,
54            InstrumentFn(..) => No,
55            Lang(..) => Yes,
56            Link(..) => No,
57            LinkName { .. } => Yes, // Needed for rustdoc
58            LinkOrdinal { .. } => No,
59            LinkSection { .. } => Yes, // Needed for rustdoc
60            Linkage(..) => No,
61            LintAsPtr => Yes,
62            LintCheck(..) => No,
63            LintNeverReturnsNullPtr => Yes,
64            LintShouldNotBeCalledOnConstItems => Yes,
65            LoopMatch(..) => No,
66            MacroEscape => No,
67            MacroExport { .. } => Yes,
68            MacroUse { .. } => No,
69            Marker => No,
70            MayDangle(..) => No,
71            MoveSizeLimit { .. } => No,
72            MustNotSuspend { .. } => Yes,
73            MustUse { .. } => Yes,
74            Naked(..) => No,
75            NeedsAllocator => No,
76            NeedsPanicRuntime => No,
77            NoBuiltins => Yes,
78            NoCore => No,
79            NoImplicitPrelude => No,
80            NoLink => No,
81            NoMain => No,
82            NoMangle(..) => Yes, // Needed for rustdoc
83            NoStd => No,
84            NonExhaustive(..) => Yes, // Needed for rustdoc
85            OnConst { .. } => Yes,
86            OnMove { .. } => Yes,
87            OnTypeError { .. } => Yes,
88            OnUnimplemented { .. } => Yes,
89            OnUnknown { .. } => Yes,
90            OnUnmatchedArgs { .. } => Yes,
91            Opaque => Yes,
92            Optimize(..) => No,
93            PanicRuntime => No,
94            PatchableFunctionEntry { .. } => Yes,
95            Path(..) => No,
96            PatternComplexityLimit { .. } => No,
97            PinV2(..) => Yes,
98            PreludeImport => No,
99            ProcMacro => No,
100            ProcMacroAttribute => No,
101            ProcMacroDerive { .. } => No,
102            ProfilerRuntime => No,
103            RecursionLimit { .. } => No,
104            ReexportTestHarnessMain(..) => No,
105            RegisterTool { .. } => No,
106            Repr { .. } => No,
107            RustcAbi { .. } => No,
108            RustcAlign { .. } => No,
109            RustcAllocator => No,
110            RustcAllocatorZeroed => No,
111            RustcAllocatorZeroedVariant { .. } => Yes,
112            RustcAllowConstFnUnstable(..) => No,
113            RustcAllowIncoherentImpl(..) => No,
114            RustcAllowLifetimeDependentSpecialization => No,
115            RustcAssertVariance { .. } => No,
116            RustcAutodiff(..) => Yes,
117            RustcBodyStability { .. } => No,
118            RustcBuiltinMacro { .. } => Yes,
119            RustcCanonicalSymbol => No,
120            RustcCaptureAnalysis => No,
121            RustcCguTestAttr { .. } => No,
122            RustcClean { .. } => No,
123            RustcCoherenceIsCore => No,
124            RustcCoinductive => No,
125            RustcComptime(..) => No, // Encoded directly in signature
126            RustcConfusables { .. } => Yes,
127            RustcConstStability { .. } => Yes,
128            RustcConstStableIndirect => No,
129            RustcConversionSuggestion => Yes,
130            RustcDeallocator => No,
131            RustcDelayedBugFromInsideQuery => No,
132            RustcDenyExplicitImpl => No,
133            RustcDeprecatedSafe2024 { .. } => Yes,
134            RustcDiagnosticItem(..) => Yes,
135            RustcDoNotConstCheck => Yes,
136            RustcDocPrimitive(..) => Yes,
137            RustcDummy => No,
138            RustcDumpClauses => No,
139            RustcDumpDefParents => No,
140            RustcDumpDefPath(..) => No,
141            RustcDumpGenerics => No,
142            RustcDumpHiddenTypeOfOpaques => No,
143            RustcDumpInferredOutlives => No,
144            RustcDumpItemBounds => No,
145            RustcDumpLayout(..) => No,
146            RustcDumpObjectLifetimeDefaults => No,
147            RustcDumpSymbolName(..) => Yes,
148            RustcDumpUserArgs => No,
149            RustcDumpVariances => No,
150            RustcDumpVariancesOfOpaques => No,
151            RustcDumpVtable(..) => No,
152            RustcDynIncompatibleTrait(..) => No,
153            RustcEffectiveVisibility => Yes,
154            RustcEiiForeignItem => No,
155            RustcEvaluateWhereClauses => Yes,
156            RustcHasIncoherentInherentImpls => Yes,
157            RustcIfThisChanged(..) => No,
158            RustcInheritOverflowChecks => No,
159            RustcInsignificantDtor => Yes,
160            RustcIntrinsic { .. } => Yes,
161            RustcIntrinsicConstStableIndirect => No,
162            RustcLegacyConstGenerics { .. } => Yes,
163            RustcLintOptDenyFieldAccess { .. } => Yes,
164            RustcLintOptTy => Yes,
165            RustcLintQueryInstability => Yes,
166            RustcLintUntrackedQueryInformation => Yes,
167            RustcMacroTransparency(..) => Yes,
168            RustcMain => No,
169            RustcMir(..) => Yes,
170            RustcMustImplementOneOf { .. } => No,
171            RustcMustMatchExhaustively(..) => Yes,
172            RustcNoImplicitAutorefs => Yes,
173            RustcNoImplicitBounds => No,
174            RustcNoMirInline => Yes,
175            RustcNoWritable => Yes,
176            RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
177            RustcNonnullOptimizationGuaranteed => Yes,
178            RustcNounwind => No,
179            RustcObjcClass { .. } => No,
180            RustcObjcSelector { .. } => No,
181            RustcOffloadKernel => Yes,
182            RustcPanicsWhenZero => Yes,
183            RustcParenSugar => No,
184            RustcPassByValue => Yes,
185            RustcPassIndirectlyInNonRusticAbis(..) => No,
186            RustcPreserveUbChecks => No,
187            RustcProcMacroDecls => No,
188            RustcPubTransparent(..) => Yes,
189            RustcReallocator => No,
190            RustcRegions => No,
191            RustcScalableVector { .. } => Yes,
192            RustcShowSpans(_) => No,
193            RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
194            RustcSkipDuringMethodDispatch { .. } => No,
195            RustcSpecializationTrait => No,
196            RustcStdInternalSymbol => No,
197            RustcStrictCoherence(..) => Yes,
198            RustcTestEntrypointMarker => No,
199            RustcTestMarker(..) => No,
200            RustcThenThisWouldNeed(..) => No,
201            RustcTrivialFieldReads(..) => No,
202            Sanitize { .. } => No,
203            ShouldPanic { .. } => No,
204            Splat(..) => Yes,
205            Stability { .. } => Yes,
206            TargetFeature { .. } => No,
207            TestRunner(..) => Yes,
208            ThreadLocal => No,
209            TrackCaller(..) => Yes,
210            TypeLengthLimit { .. } => No,
211            UncheckedTypeAlias => Yes,
212            Unroll(..) => No,
213            UnstableFeatureBound(..) => No,
214            UnstableRemoved(..) => Yes,
215            Used { .. } => No,
216            WindowsSubsystem(..) => No,
217            // tidy-alphabetical-end
218        }
219    }
220
221    /// Whether this attribute is an extern indicator.
222    ///
223    /// Must stay in sync with [`CodegenFnAttrs::contains_extern_indicator`].
224    ///
225    /// [`CodegenFnAttrs::contains_extern_indicator`]: ../rustc_middle/middle/codegen_fn_attrs/struct.CodegenFnAttrs.html#method.contains_extern_indicator
226    pub fn is_extern_indicator(&self) -> bool {
227        use AttributeKind::*;
228
229        match self {
230            // tidy-alphabetical-start
231            AllowInternalUnsafe(..) => false,
232            AllowInternalUnstable(..) => false,
233            AlwaysGca => false,
234            AutomaticallyDerived => false,
235            CfgAttrTrace(..) => false,
236            CfgTrace(..) => false,
237            CfiEncoding { .. } => false,
238            Cold => false,
239            CollapseDebugInfo(..) => false,
240            CompilerBuiltins => false,
241            ConstContinue(..) => false,
242            Coroutine => false,
243            Coverage(..) => false,
244            CrateName { .. } => false,
245            CrateType(_) => false,
246            CustomMir(_, _) => false,
247            DebuggerVisualizer(..) => false,
248            DefaultLibAllocator => false,
249            Deprecated { .. } => false,
250            DoNotRecommend => false,
251            Doc(_) => false,
252            DocComment { .. } => false,
253            EiiDeclaration(_) => false,
254            EiiImpl(..) => true,
255            ExportName { .. } => true,
256            ExportStable => false,
257            Feature(..) => false,
258            FfiConst => false,
259            FfiPure(..) => false,
260            Fundamental { .. } => false,
261            Ignore { .. } => false,
262            Inline(..) => false,
263            InstructionSet(..) => false,
264            InstrumentFn(..) => false,
265            Lang(item) => item.link_name().is_some(),
266            Link(..) => false,
267            LinkName { .. } => false,
268            LinkOrdinal { .. } => false,
269            LinkSection { .. } => false,
270            Linkage(linkage, _) => match *linkage {
271                crate::Linkage::Internal => false,
272                crate::Linkage::AvailableExternally
273                | crate::Linkage::External
274                | crate::Linkage::ExternalWeak
275                | crate::Linkage::LinkOnceAny
276                | crate::Linkage::LinkOnceODR
277                | crate::Linkage::WeakAny
278                | crate::Linkage::WeakODR => true,
279            },
280            LintAsPtr => false,
281            LintCheck(_) => false,
282            LintNeverReturnsNullPtr => false,
283            LintShouldNotBeCalledOnConstItems => false,
284            LoopMatch(..) => false,
285            MacroEscape => false,
286            MacroExport { .. } => false,
287            MacroUse { .. } => false,
288            Marker => false,
289            MayDangle(..) => false,
290            MoveSizeLimit { .. } => false,
291            MustNotSuspend { .. } => false,
292            MustUse { .. } => false,
293            Naked(..) => false,
294            NeedsAllocator => false,
295            NeedsPanicRuntime => false,
296            NoBuiltins => false,
297            NoCore => false,
298            NoImplicitPrelude => false,
299            NoLink => false,
300            NoMain => false,
301            NoMangle(..) => true,
302            NoStd => false,
303            NonExhaustive(..) => false,
304            OnConst { .. } => false,
305            OnMove { .. } => false,
306            OnTypeError { .. } => false,
307            OnUnimplemented { .. } => false,
308            OnUnknown { .. } => false,
309            OnUnmatchedArgs { .. } => false,
310            Opaque => false,
311            Optimize(..) => false,
312            PanicRuntime => false,
313            PatchableFunctionEntry { .. } => false,
314            Path(..) => false,
315            PatternComplexityLimit { .. } => false,
316            PinV2(..) => false,
317            PreludeImport => false,
318            ProcMacro => false,
319            ProcMacroAttribute => false,
320            ProcMacroDerive { .. } => false,
321            ProfilerRuntime => false,
322            RecursionLimit { .. } => false,
323            ReexportTestHarnessMain(..) => false,
324            RegisterTool { .. } => false,
325            Repr { .. } => false,
326            RustcAbi { .. } => false,
327            RustcAlign { .. } => false,
328            RustcAllocator => false,
329            RustcAllocatorZeroed => false,
330            RustcAllocatorZeroedVariant { .. } => false,
331            RustcAllowConstFnUnstable(..) => false,
332            RustcAllowIncoherentImpl(..) => false,
333            RustcAllowLifetimeDependentSpecialization => false,
334            RustcAssertVariance { .. } => false,
335            RustcAutodiff(..) => false,
336            RustcBodyStability { .. } => false,
337            RustcBuiltinMacro { .. } => false,
338            RustcCanonicalSymbol => false,
339            RustcCaptureAnalysis => false,
340            RustcCguTestAttr { .. } => false,
341            RustcClean { .. } => false,
342            RustcCoherenceIsCore => false,
343            RustcCoinductive => false,
344            RustcComptime(..) => false,
345            RustcConfusables { .. } => false,
346            RustcConstStability { .. } => false,
347            RustcConstStableIndirect => false,
348            RustcConversionSuggestion => false,
349            RustcDeallocator => false,
350            RustcDelayedBugFromInsideQuery => false,
351            RustcDenyExplicitImpl => false,
352            RustcDeprecatedSafe2024 { .. } => false,
353            RustcDiagnosticItem(..) => false,
354            RustcDoNotConstCheck => false,
355            RustcDocPrimitive(..) => false,
356            RustcDummy => false,
357            RustcDumpClauses => false,
358            RustcDumpDefParents => false,
359            RustcDumpDefPath(..) => false,
360            RustcDumpGenerics => false,
361            RustcDumpHiddenTypeOfOpaques => false,
362            RustcDumpInferredOutlives => false,
363            RustcDumpItemBounds => false,
364            RustcDumpLayout(..) => false,
365            RustcDumpObjectLifetimeDefaults => false,
366            RustcDumpSymbolName(..) => false,
367            RustcDumpUserArgs => false,
368            RustcDumpVariances => false,
369            RustcDumpVariancesOfOpaques => false,
370            RustcDumpVtable(..) => false,
371            RustcDynIncompatibleTrait(..) => false,
372            RustcEffectiveVisibility => false,
373            RustcEiiForeignItem => true,
374            RustcEvaluateWhereClauses => false,
375            RustcHasIncoherentInherentImpls => false,
376            RustcIfThisChanged(..) => false,
377            RustcInheritOverflowChecks => false,
378            RustcInsignificantDtor => false,
379            RustcIntrinsic { .. } => false,
380            RustcIntrinsicConstStableIndirect => false,
381            RustcLegacyConstGenerics { .. } => false,
382            RustcLintOptDenyFieldAccess { .. } => false,
383            RustcLintOptTy => false,
384            RustcLintQueryInstability => false,
385            RustcLintUntrackedQueryInformation => false,
386            RustcMacroTransparency(..) => false,
387            RustcMain => false,
388            RustcMir(..) => false,
389            RustcMustImplementOneOf { .. } => false,
390            RustcMustMatchExhaustively(..) => false,
391            RustcNoImplicitAutorefs => false,
392            RustcNoImplicitBounds => false,
393            RustcNoMirInline => false,
394            RustcNoWritable => false,
395            RustcNonConstTraitMethod => false,
396            RustcNonnullOptimizationGuaranteed => false,
397            RustcNounwind => false,
398            RustcObjcClass { .. } => false,
399            RustcObjcSelector { .. } => false,
400            RustcOffloadKernel => true,
401            RustcPanicsWhenZero => false,
402            RustcParenSugar => false,
403            RustcPassByValue => false,
404            RustcPassIndirectlyInNonRusticAbis(..) => false,
405            RustcPreserveUbChecks => false,
406            RustcProcMacroDecls => false,
407            RustcPubTransparent(..) => false,
408            RustcReallocator => false,
409            RustcRegions => false,
410            RustcScalableVector { .. } => false,
411            RustcShowSpans(_) => false,
412            RustcSimdMonomorphizeLaneLimit(..) => false,
413            RustcSkipDuringMethodDispatch { .. } => false,
414            RustcSpecializationTrait => false,
415            RustcStdInternalSymbol => true,
416            RustcStrictCoherence(..) => false,
417            RustcTestEntrypointMarker => false,
418            RustcTestMarker(..) => false,
419            RustcThenThisWouldNeed(..) => false,
420            RustcTrivialFieldReads(..) => false,
421            Sanitize { .. } => false,
422            ShouldPanic { .. } => false,
423            Splat(..) => false,
424            Stability { .. } => false,
425            TargetFeature { .. } => false,
426            TestRunner(..) => false,
427            ThreadLocal => false,
428            TrackCaller(..) => false,
429            TypeLengthLimit { .. } => false,
430            UncheckedTypeAlias => false,
431            Unroll(..) => false,
432            UnstableFeatureBound(..) => false,
433            UnstableRemoved(..) => false,
434            Used { .. } => false,
435            WindowsSubsystem(..) => false,
436            // tidy-alphabetical-end
437        }
438    }
439}