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