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            Optimize(..) => No,
87            PanicRuntime => No,
88            PatchableFunctionEntry { .. } => Yes,
89            Path(..) => No,
90            PatternComplexityLimit { .. } => No,
91            PinV2(..) => Yes,
92            PreludeImport => No,
93            ProcMacro => No,
94            ProcMacroAttribute => No,
95            ProcMacroDerive { .. } => No,
96            ProfilerRuntime => No,
97            RecursionLimit { .. } => No,
98            ReexportTestHarnessMain(..) => No,
99            RegisterTool(..) => No,
100            Repr { .. } => No,
101            RustcAbi { .. } => No,
102            RustcAlign { .. } => No,
103            RustcAllocator => No,
104            RustcAllocatorZeroed => No,
105            RustcAllocatorZeroedVariant { .. } => Yes,
106            RustcAllowConstFnUnstable(..) => No,
107            RustcAllowIncoherentImpl(..) => No,
108            RustcAsPtr => Yes,
109            RustcAutodiff(..) => Yes,
110            RustcBodyStability { .. } => No,
111            RustcBuiltinMacro { .. } => Yes,
112            RustcCaptureAnalysis => No,
113            RustcCguTestAttr { .. } => No,
114            RustcClean { .. } => No,
115            RustcCoherenceIsCore => No,
116            RustcCoinductive => No,
117            RustcComptime(..) => No, // Encoded directly in signature
118            RustcConfusables { .. } => Yes,
119            RustcConstStability { .. } => Yes,
120            RustcConstStableIndirect => No,
121            RustcConversionSuggestion => Yes,
122            RustcDeallocator => No,
123            RustcDelayedBugFromInsideQuery => No,
124            RustcDenyExplicitImpl => No,
125            RustcDeprecatedSafe2024 { .. } => Yes,
126            RustcDiagnosticItem(..) => Yes,
127            RustcDoNotConstCheck => Yes,
128            RustcDocPrimitive(..) => Yes,
129            RustcDummy => No,
130            RustcDumpDefParents => No,
131            RustcDumpDefPath(..) => No,
132            RustcDumpGenerics => No,
133            RustcDumpHiddenTypeOfOpaques => No,
134            RustcDumpInferredOutlives => No,
135            RustcDumpItemBounds => No,
136            RustcDumpLayout(..) => No,
137            RustcDumpObjectLifetimeDefaults => No,
138            RustcDumpPredicates => No,
139            RustcDumpSymbolName(..) => Yes,
140            RustcDumpUserArgs => No,
141            RustcDumpVariances => No,
142            RustcDumpVariancesOfOpaques => No,
143            RustcDumpVtable(..) => No,
144            RustcDynIncompatibleTrait(..) => No,
145            RustcEffectiveVisibility => Yes,
146            RustcEiiForeignItem => No,
147            RustcEvaluateWhereClauses => Yes,
148            RustcHasIncoherentInherentImpls => Yes,
149            RustcIfThisChanged(..) => No,
150            RustcInheritOverflowChecks => No,
151            RustcInsignificantDtor => Yes,
152            RustcIntrinsic => Yes,
153            RustcIntrinsicConstStableIndirect => No,
154            RustcLegacyConstGenerics { .. } => Yes,
155            RustcLintOptDenyFieldAccess { .. } => Yes,
156            RustcLintOptTy => Yes,
157            RustcLintQueryInstability => Yes,
158            RustcLintUntrackedQueryInformation => Yes,
159            RustcMacroTransparency(..) => Yes,
160            RustcMain => No,
161            RustcMir(..) => Yes,
162            RustcMustImplementOneOf { .. } => No,
163            RustcMustMatchExhaustively(..) => Yes,
164            RustcNeverReturnsNullPtr => Yes,
165            RustcNeverTypeOptions { .. } => No,
166            RustcNoImplicitAutorefs => Yes,
167            RustcNoImplicitBounds => No,
168            RustcNoMirInline => Yes,
169            RustcNoWritable => Yes,
170            RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
171            RustcNonnullOptimizationGuaranteed => Yes,
172            RustcNounwind => No,
173            RustcObjcClass { .. } => No,
174            RustcObjcSelector { .. } => No,
175            RustcOffloadKernel => Yes,
176            RustcParenSugar => No,
177            RustcPassByValue => Yes,
178            RustcPassIndirectlyInNonRusticAbis(..) => No,
179            RustcPreserveUbChecks => No,
180            RustcProcMacroDecls => No,
181            RustcPubTransparent(..) => Yes,
182            RustcReallocator => No,
183            RustcRegions => No,
184            RustcReservationImpl(..) => Yes,
185            RustcScalableVector { .. } => Yes,
186            RustcShouldNotBeCalledOnConstItems => Yes,
187            RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
188            RustcSkipDuringMethodDispatch { .. } => No,
189            RustcSpecializationTrait => No,
190            RustcStdInternalSymbol => No,
191            RustcStrictCoherence(..) => Yes,
192            RustcTestMarker(..) => No,
193            RustcThenThisWouldNeed(..) => No,
194            RustcTrivialFieldReads => Yes,
195            RustcUnsafeSpecializationMarker => No,
196            Sanitize { .. } => No,
197            ShouldPanic { .. } => No,
198            Splat(..) => Yes,
199            Stability { .. } => Yes,
200            TargetFeature { .. } => No,
201            TestRunner(..) => Yes,
202            ThreadLocal => No,
203            TrackCaller(..) => Yes,
204            TypeLengthLimit { .. } => No,
205            Unroll(..) => No,
206            UnstableFeatureBound(..) => No,
207            UnstableRemoved(..) => Yes,
208            Used { .. } => No,
209            WindowsSubsystem(..) => No,
210            // tidy-alphabetical-end
211        }
212    }
213}