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