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            Align { .. } => No,
22            AllowInternalUnsafe(..) => Yes,
23            AllowInternalUnstable(..) => 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            Deprecation { .. } => Yes,
40            DoNotRecommend { .. } => Yes,
41            Doc(_) => Yes,
42            DocComment { .. } => Yes,
43            EiiDeclaration(_) => Yes,
44            EiiForeignItem => No,
45            EiiImpls(..) => No,
46            ExportName { .. } => Yes,
47            ExportStable => No,
48            FfiConst(..) => No,
49            FfiPure(..) => No,
50            Fundamental { .. } => Yes,
51            Ignore { .. } => No,
52            Inline(..) => No,
53            InstructionSet(..) => 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            Optimize(..) => No,
81            PanicRuntime => No,
82            PatchableFunctionEntry { .. } => Yes,
83            Path(..) => No,
84            PatternComplexityLimit { .. } => No,
85            PinV2(..) => Yes,
86            Pointee(..) => No,
87            PreludeImport => No,
88            ProcMacro(..) => No,
89            ProcMacroAttribute(..) => No,
90            ProcMacroDerive { .. } => No,
91            ProfilerRuntime => No,
92            RecursionLimit { .. } => No,
93            ReexportTestHarnessMain(..) => No,
94            Repr { .. } => No,
95            RustcAbi { .. } => No,
96            RustcAllocator => No,
97            RustcAllocatorZeroed => No,
98            RustcAllocatorZeroedVariant { .. } => Yes,
99            RustcAllowConstFnUnstable(..) => No,
100            RustcAllowIncoherentImpl(..) => No,
101            RustcAsPtr(..) => Yes,
102            RustcBodyStability { .. } => No,
103            RustcBuiltinMacro { .. } => Yes,
104            RustcCaptureAnalysis => No,
105            RustcCguTestAttr { .. } => No,
106            RustcClean { .. } => No,
107            RustcCoherenceIsCore(..) => No,
108            RustcCoinductive(..) => No,
109            RustcConfusables { .. } => Yes,
110            RustcConstStability { .. } => Yes,
111            RustcConstStabilityIndirect => No,
112            RustcConversionSuggestion => Yes,
113            RustcDeallocator => No,
114            RustcDefPath(..) => No,
115            RustcDelayedBugFromInsideQuery => No,
116            RustcDenyExplicitImpl(..) => No,
117            RustcDeprecatedSafe2024 { .. } => Yes,
118            RustcDiagnosticItem(..) => Yes,
119            RustcDoNotConstCheck => Yes,
120            RustcDocPrimitive(..) => Yes,
121            RustcDummy => No,
122            RustcDumpDefParents => No,
123            RustcDumpItemBounds => No,
124            RustcDumpPredicates => No,
125            RustcDumpUserArgs => No,
126            RustcDumpVtable(..) => No,
127            RustcDynIncompatibleTrait(..) => No,
128            RustcEffectiveVisibility => Yes,
129            RustcEvaluateWhereClauses => Yes,
130            RustcHasIncoherentInherentImpls => Yes,
131            RustcHiddenTypeOfOpaques => No,
132            RustcIfThisChanged(..) => No,
133            RustcInsignificantDtor => Yes,
134            RustcIntrinsic => Yes,
135            RustcIntrinsicConstStableIndirect => No,
136            RustcLayout(..) => No,
137            RustcLayoutScalarValidRangeEnd(..) => Yes,
138            RustcLayoutScalarValidRangeStart(..) => Yes,
139            RustcLegacyConstGenerics { .. } => Yes,
140            RustcLintOptDenyFieldAccess { .. } => Yes,
141            RustcLintOptTy => Yes,
142            RustcLintQueryInstability => Yes,
143            RustcLintUntrackedQueryInformation => Yes,
144            RustcMacroTransparency(..) => Yes,
145            RustcMain => No,
146            RustcMir(..) => Yes,
147            RustcMustImplementOneOf { .. } => No,
148            RustcNeverReturnsNullPointer => Yes,
149            RustcNeverTypeOptions { .. } => No,
150            RustcNoImplicitAutorefs => Yes,
151            RustcNoImplicitBounds => No,
152            RustcNoMirInline => Yes,
153            RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
154            RustcNonnullOptimizationGuaranteed => Yes,
155            RustcNounwind => No,
156            RustcObjcClass { .. } => No,
157            RustcObjcSelector { .. } => No,
158            RustcObjectLifetimeDefault => No,
159            RustcOffloadKernel => Yes,
160            RustcOutlives => No,
161            RustcParenSugar(..) => No,
162            RustcPassByValue(..) => Yes,
163            RustcPassIndirectlyInNonRusticAbis(..) => No,
164            RustcPreserveUbChecks => No,
165            RustcProcMacroDecls => No,
166            RustcPubTransparent(..) => Yes,
167            RustcReallocator => No,
168            RustcRegions => No,
169            RustcReservationImpl(..) => Yes,
170            RustcScalableVector { .. } => Yes,
171            RustcShouldNotBeCalledOnConstItems(..) => Yes,
172            RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
173            RustcSkipDuringMethodDispatch { .. } => No,
174            RustcSpecializationTrait(..) => No,
175            RustcStdInternalSymbol(..) => No,
176            RustcStrictCoherence(..) => Yes,
177            RustcSymbolName(..) => Yes,
178            RustcTestMarker(..) => No,
179            RustcThenThisWouldNeed(..) => No,
180            RustcTrivialFieldReads => Yes,
181            RustcUnsafeSpecializationMarker(..) => No,
182            RustcVariance => No,
183            RustcVarianceOfOpaques => No,
184            Sanitize { .. } => No,
185            ShouldPanic { .. } => No,
186            Stability { .. } => Yes,
187            TargetFeature { .. } => No,
188            TestRunner(..) => Yes,
189            ThreadLocal => No,
190            TrackCaller(..) => Yes,
191            TypeLengthLimit { .. } => No,
192            UnstableFeatureBound(..) => No,
193            Used { .. } => No,
194            WindowsSubsystem(..) => No,
195            // tidy-alphabetical-end
196        }
197    }
198}