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