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            Deprecation { .. } => Yes,
39            DoNotRecommend { .. } => Yes,
40            Doc(_) => Yes,
41            DocComment { .. } => Yes,
42            EiiDeclaration(_) => Yes,
43            EiiForeignItem => No,
44            EiiImpls(..) => No,
45            ExportName { .. } => Yes,
46            ExportStable => No,
47            FfiConst(..) => No,
48            FfiPure(..) => No,
49            Fundamental { .. } => Yes,
50            Ignore { .. } => No,
51            Inline(..) => No,
52            InstructionSet(..) => No,
53            Link(..) => No,
54            LinkName { .. } => Yes, // Needed for rustdoc
55            LinkOrdinal { .. } => No,
56            LinkSection { .. } => Yes, // Needed for rustdoc
57            Linkage(..) => No,
58            LoopMatch(..) => No,
59            MacroEscape(..) => No,
60            MacroExport { .. } => Yes,
61            MacroUse { .. } => No,
62            Marker(..) => No,
63            MayDangle(..) => No,
64            MoveSizeLimit { .. } => No,
65            MustNotSupend { .. } => Yes,
66            MustUse { .. } => Yes,
67            Naked(..) => No,
68            NeedsAllocator => No,
69            NeedsPanicRuntime => No,
70            NoBuiltins => Yes,
71            NoCore(..) => No,
72            NoImplicitPrelude(..) => No,
73            NoLink => No,
74            NoMain => No,
75            NoMangle(..) => Yes, // Needed for rustdoc
76            NoStd(..) => No,
77            NonExhaustive(..) => Yes, // Needed for rustdoc
78            Optimize(..) => No,
79            PanicRuntime => No,
80            PatchableFunctionEntry { .. } => Yes,
81            Path(..) => No,
82            PatternComplexityLimit { .. } => No,
83            PinV2(..) => Yes,
84            Pointee(..) => No,
85            PreludeImport => No,
86            ProcMacro(..) => No,
87            ProcMacroAttribute(..) => No,
88            ProcMacroDerive { .. } => No,
89            ProfilerRuntime => No,
90            RecursionLimit { .. } => No,
91            ReexportTestHarnessMain(..) => No,
92            Repr { .. } => No,
93            RustcAbi { .. } => No,
94            RustcAllocator => No,
95            RustcAllocatorZeroed => No,
96            RustcAllocatorZeroedVariant { .. } => Yes,
97            RustcAllowConstFnUnstable(..) => No,
98            RustcAllowIncoherentImpl(..) => No,
99            RustcAsPtr(..) => Yes,
100            RustcBodyStability { .. } => No,
101            RustcBuiltinMacro { .. } => Yes,
102            RustcCaptureAnalysis => No,
103            RustcCguTestAttr { .. } => No,
104            RustcClean { .. } => No,
105            RustcCoherenceIsCore(..) => No,
106            RustcCoinductive(..) => No,
107            RustcConfusables { .. } => Yes,
108            RustcConstStability { .. } => Yes,
109            RustcConstStabilityIndirect => No,
110            RustcConversionSuggestion => Yes,
111            RustcDeallocator => No,
112            RustcDefPath(..) => No,
113            RustcDelayedBugFromInsideQuery => No,
114            RustcDenyExplicitImpl(..) => No,
115            RustcDeprecatedSafe2024 { .. } => Yes,
116            RustcDummy => No,
117            RustcDumpDefParents => No,
118            RustcDumpItemBounds => No,
119            RustcDumpPredicates => No,
120            RustcDumpUserArgs => No,
121            RustcDumpVtable(..) => No,
122            RustcDynIncompatibleTrait(..) => No,
123            RustcEffectiveVisibility => Yes,
124            RustcEvaluateWhereClauses => Yes,
125            RustcHasIncoherentInherentImpls => Yes,
126            RustcHiddenTypeOfOpaques => No,
127            RustcIfThisChanged(..) => No,
128            RustcInsignificantDtor => Yes,
129            RustcIntrinsic => Yes,
130            RustcIntrinsicConstStableIndirect => No,
131            RustcLayout(..) => No,
132            RustcLayoutScalarValidRangeEnd(..) => Yes,
133            RustcLayoutScalarValidRangeStart(..) => Yes,
134            RustcLegacyConstGenerics { .. } => Yes,
135            RustcLintOptDenyFieldAccess { .. } => Yes,
136            RustcLintOptTy => Yes,
137            RustcLintQueryInstability => Yes,
138            RustcLintUntrackedQueryInformation => Yes,
139            RustcMacroTransparency(..) => Yes,
140            RustcMain => No,
141            RustcMir(..) => Yes,
142            RustcMustImplementOneOf { .. } => No,
143            RustcNeverReturnsNullPointer => Yes,
144            RustcNeverTypeOptions { .. } => No,
145            RustcNoImplicitAutorefs => Yes,
146            RustcNoImplicitBounds => No,
147            RustcNoMirInline => Yes,
148            RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
149            RustcNounwind => No,
150            RustcObjcClass { .. } => No,
151            RustcObjcSelector { .. } => No,
152            RustcObjectLifetimeDefault => No,
153            RustcOffloadKernel => Yes,
154            RustcOutlives => No,
155            RustcParenSugar(..) => No,
156            RustcPassByValue(..) => Yes,
157            RustcPassIndirectlyInNonRusticAbis(..) => No,
158            RustcPreserveUbChecks => No,
159            RustcPubTransparent(..) => Yes,
160            RustcReallocator => No,
161            RustcRegions => No,
162            RustcReservationImpl(..) => Yes,
163            RustcScalableVector { .. } => Yes,
164            RustcShouldNotBeCalledOnConstItems(..) => Yes,
165            RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
166            RustcSkipDuringMethodDispatch { .. } => No,
167            RustcSpecializationTrait(..) => No,
168            RustcStdInternalSymbol(..) => No,
169            RustcStrictCoherence(..) => Yes,
170            RustcSymbolName(..) => Yes,
171            RustcThenThisWouldNeed(..) => No,
172            RustcTrivialFieldReads => Yes,
173            RustcUnsafeSpecializationMarker(..) => No,
174            RustcVariance => No,
175            RustcVarianceOfOpaques => No,
176            Sanitize { .. } => No,
177            ShouldPanic { .. } => No,
178            Stability { .. } => Yes,
179            TargetFeature { .. } => No,
180            TestRunner(..) => Yes,
181            ThreadLocal => No,
182            TrackCaller(..) => Yes,
183            TypeLengthLimit { .. } => No,
184            UnstableFeatureBound(..) => No,
185            Used { .. } => No,
186            WindowsSubsystem(..) => No,
187            // tidy-alphabetical-end
188        }
189    }
190}