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            AllowInternalUnsafe(..) => Yes,
22            AllowInternalUnstable(..) => Yes,
23            AutomaticallyDerived => Yes,
24            CfgAttrTrace(..) => Yes,
25            CfgTrace(..) => Yes,
26            CfiEncoding { .. } => Yes,
27            Cold => No,
28            CollapseDebugInfo(..) => Yes,
29            CompilerBuiltins => No,
30            ConstContinue(..) => No,
31            Coroutine => No,
32            Coverage(..) => No,
33            CrateName { .. } => No,
34            CrateType(_) => No,
35            CustomMir(_, _) => Yes,
36            DebuggerVisualizer(..) => No,
37            DefaultLibAllocator => No,
38            Deprecated { .. } => Yes,
39            DoNotRecommend => Yes,
40            Doc(_) => Yes,
41            DocComment { .. } => Yes,
42            EiiDeclaration(_) => Yes,
43            EiiImpls(..) => No,
44            ExportName { .. } => Yes,
45            ExportStable => No,
46            Feature(..) => No,
47            FfiConst => No,
48            FfiPure(..) => No,
49            Fundamental { .. } => Yes,
50            Ignore { .. } => No,
51            Inline(..) => No,
52            InstructionSet(..) => No,
53            InstrumentFn(..) => 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            OnConst { .. } => Yes,
81            OnMove { .. } => Yes,
82            OnTypeError { .. } => Yes,
83            OnUnimplemented { .. } => Yes,
84            OnUnknown { .. } => Yes,
85            OnUnmatchedArgs { .. } => Yes,
86            Opaque => Yes,
87            Optimize(..) => No,
88            PanicRuntime => No,
89            PatchableFunctionEntry { .. } => Yes,
90            Path(..) => No,
91            PatternComplexityLimit { .. } => No,
92            PinV2(..) => Yes,
93            PreludeImport => No,
94            ProcMacro => No,
95            ProcMacroAttribute => No,
96            ProcMacroDerive { .. } => No,
97            ProfilerRuntime => No,
98            RecursionLimit { .. } => No,
99            ReexportTestHarnessMain(..) => No,
100            RegisterTool { .. } => No,
101            Repr { .. } => No,
102            RustcAbi { .. } => No,
103            RustcAlign { .. } => No,
104            RustcAllocator => No,
105            RustcAllocatorZeroed => No,
106            RustcAllocatorZeroedVariant { .. } => Yes,
107            RustcAllowConstFnUnstable(..) => No,
108            RustcAllowIncoherentImpl(..) => No,
109            RustcAsPtr => Yes,
110            RustcAutodiff(..) => Yes,
111            RustcBodyStability { .. } => No,
112            RustcBuiltinMacro { .. } => Yes,
113            RustcCanonicalSymbol => No,
114            RustcCaptureAnalysis => No,
115            RustcCguTestAttr { .. } => No,
116            RustcClean { .. } => No,
117            RustcCoherenceIsCore => No,
118            RustcCoinductive => No,
119            RustcComptime(..) => No, // Encoded directly in signature
120            RustcConfusables { .. } => Yes,
121            RustcConstStability { .. } => Yes,
122            RustcConstStableIndirect => No,
123            RustcConversionSuggestion => Yes,
124            RustcDeallocator => No,
125            RustcDelayedBugFromInsideQuery => No,
126            RustcDenyExplicitImpl => No,
127            RustcDeprecatedSafe2024 { .. } => Yes,
128            RustcDiagnosticItem(..) => Yes,
129            RustcDoNotConstCheck => Yes,
130            RustcDocPrimitive(..) => Yes,
131            RustcDummy => No,
132            RustcDumpDefParents => No,
133            RustcDumpDefPath(..) => No,
134            RustcDumpGenerics => No,
135            RustcDumpHiddenTypeOfOpaques => No,
136            RustcDumpInferredOutlives => No,
137            RustcDumpItemBounds => No,
138            RustcDumpLayout(..) => No,
139            RustcDumpObjectLifetimeDefaults => No,
140            RustcDumpPredicates => No,
141            RustcDumpSymbolName(..) => Yes,
142            RustcDumpUserArgs => No,
143            RustcDumpVariances => No,
144            RustcDumpVariancesOfOpaques => No,
145            RustcDumpVtable(..) => No,
146            RustcDynIncompatibleTrait(..) => No,
147            RustcEffectiveVisibility => Yes,
148            RustcEiiForeignItem => No,
149            RustcEvaluateWhereClauses => Yes,
150            RustcHasIncoherentInherentImpls => Yes,
151            RustcIfThisChanged(..) => No,
152            RustcInheritOverflowChecks => No,
153            RustcInsignificantDtor => Yes,
154            RustcIntrinsic => Yes,
155            RustcIntrinsicConstStableIndirect => No,
156            RustcLegacyConstGenerics { .. } => Yes,
157            RustcLintOptDenyFieldAccess { .. } => Yes,
158            RustcLintOptTy => Yes,
159            RustcLintQueryInstability => Yes,
160            RustcLintUntrackedQueryInformation => Yes,
161            RustcMacroTransparency(..) => Yes,
162            RustcMain => No,
163            RustcMir(..) => Yes,
164            RustcMustImplementOneOf { .. } => No,
165            RustcMustMatchExhaustively(..) => Yes,
166            RustcNeverReturnsNullPtr => Yes,
167            RustcNeverTypeOptions { .. } => No,
168            RustcNoImplicitAutorefs => Yes,
169            RustcNoImplicitBounds => No,
170            RustcNoMirInline => Yes,
171            RustcNoWritable => Yes,
172            RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
173            RustcNonnullOptimizationGuaranteed => Yes,
174            RustcNounwind => No,
175            RustcObjcClass { .. } => No,
176            RustcObjcSelector { .. } => No,
177            RustcOffloadKernel => Yes,
178            RustcPanicsWhenZero => Yes,
179            RustcParenSugar => No,
180            RustcPassByValue => Yes,
181            RustcPassIndirectlyInNonRusticAbis(..) => No,
182            RustcPreserveUbChecks => No,
183            RustcProcMacroDecls => No,
184            RustcPubTransparent(..) => Yes,
185            RustcReallocator => No,
186            RustcRegions => No,
187            RustcReservationImpl(..) => Yes,
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            RustcTestEntrypointMarker => No,
196            RustcTestMarker(..) => No,
197            RustcThenThisWouldNeed(..) => No,
198            RustcTrivialFieldReads => Yes,
199            RustcUnsafeSpecializationMarker => No,
200            Sanitize { .. } => No,
201            ShouldPanic { .. } => No,
202            Splat(..) => Yes,
203            Stability { .. } => Yes,
204            TargetFeature { .. } => No,
205            TestRunner(..) => Yes,
206            ThreadLocal => No,
207            TrackCaller(..) => Yes,
208            TypeLengthLimit { .. } => No,
209            Unroll(..) => No,
210            UnstableFeatureBound(..) => No,
211            UnstableRemoved(..) => Yes,
212            Used { .. } => No,
213            WindowsSubsystem(..) => No,
214            // tidy-alphabetical-end
215        }
216    }
217}