Skip to main content

rustc_attr_ir/
encode_cross_crate.rs

1use crate::AttributeKind;
2
3#[derive(#[automatically_derived]
impl ::core::marker::StructuralPartialEq for EncodeCrossCrate { }
#[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            AlwaysGca => 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            Deprecated { .. } => Yes,
40            DoNotRecommend => Yes,
41            Doc(_) => Yes,
42            DocComment { .. } => Yes,
43            EiiDeclaration(_) => Yes,
44            EiiImpl(..) => No,
45            ExportName { .. } => Yes,
46            ExportStable => No,
47            Feature(..) => No,
48            FfiConst => No,
49            FfiPure(..) => No,
50            Fundamental { .. } => Yes,
51            Ignore { .. } => No,
52            Inline(..) => No,
53            InstructionSet(..) => No,
54            InstrumentFn(..) => No,
55            Lang(..) => Yes,
56            Link(..) => No,
57            LinkName { .. } => Yes, // Needed for rustdoc
58            LinkOrdinal { .. } => No,
59            LinkSection { .. } => Yes, // Needed for rustdoc
60            Linkage(..) => No,
61            LoopMatch(..) => No,
62            MacroEscape => No,
63            MacroExport { .. } => Yes,
64            MacroUse { .. } => No,
65            Marker => No,
66            MayDangle(..) => No,
67            MoveSizeLimit { .. } => No,
68            MustNotSupend { .. } => Yes,
69            MustUse { .. } => Yes,
70            Naked(..) => No,
71            NeedsAllocator => No,
72            NeedsPanicRuntime => No,
73            NoBuiltins => Yes,
74            NoCore => No,
75            NoImplicitPrelude => No,
76            NoLink => No,
77            NoMain => No,
78            NoMangle(..) => Yes, // Needed for rustdoc
79            NoStd => No,
80            NonExhaustive(..) => Yes, // Needed for rustdoc
81            OnConst { .. } => Yes,
82            OnMove { .. } => Yes,
83            OnTypeError { .. } => Yes,
84            OnUnimplemented { .. } => Yes,
85            OnUnknown { .. } => Yes,
86            OnUnmatchedArgs { .. } => Yes,
87            Opaque => Yes,
88            Optimize(..) => No,
89            PanicRuntime => No,
90            PatchableFunctionEntry { .. } => Yes,
91            Path(..) => No,
92            PatternComplexityLimit { .. } => No,
93            PinV2(..) => Yes,
94            PreludeImport => No,
95            ProcMacro => No,
96            ProcMacroAttribute => No,
97            ProcMacroDerive { .. } => No,
98            ProfilerRuntime => No,
99            RecursionLimit { .. } => No,
100            ReexportTestHarnessMain(..) => No,
101            RegisterTool { .. } => No,
102            Repr { .. } => No,
103            RustcAbi { .. } => No,
104            RustcAlign { .. } => No,
105            RustcAllocator => No,
106            RustcAllocatorZeroed => No,
107            RustcAllocatorZeroedVariant { .. } => Yes,
108            RustcAllowConstFnUnstable(..) => No,
109            RustcAllowIncoherentImpl(..) => No,
110            RustcAllowLifetimeDependentSpecialization => No,
111            RustcAsPtr => Yes,
112            RustcAutodiff(..) => Yes,
113            RustcBodyStability { .. } => No,
114            RustcBuiltinMacro { .. } => Yes,
115            RustcCanonicalSymbol => No,
116            RustcCaptureAnalysis => No,
117            RustcCguTestAttr { .. } => No,
118            RustcClean { .. } => No,
119            RustcCoherenceIsCore => No,
120            RustcCoinductive => No,
121            RustcComptime(..) => No, // Encoded directly in signature
122            RustcConfusables { .. } => Yes,
123            RustcConstStability { .. } => Yes,
124            RustcConstStableIndirect => No,
125            RustcConversionSuggestion => Yes,
126            RustcDeallocator => No,
127            RustcDelayedBugFromInsideQuery => No,
128            RustcDenyExplicitImpl => No,
129            RustcDeprecatedSafe2024 { .. } => Yes,
130            RustcDiagnosticItem(..) => Yes,
131            RustcDoNotConstCheck => Yes,
132            RustcDocPrimitive(..) => Yes,
133            RustcDummy => No,
134            RustcDumpClauses => No,
135            RustcDumpDefParents => No,
136            RustcDumpDefPath(..) => No,
137            RustcDumpGenerics => No,
138            RustcDumpHiddenTypeOfOpaques => No,
139            RustcDumpInferredOutlives => No,
140            RustcDumpItemBounds => No,
141            RustcDumpLayout(..) => No,
142            RustcDumpObjectLifetimeDefaults => No,
143            RustcDumpSymbolName(..) => Yes,
144            RustcDumpUserArgs => No,
145            RustcDumpVariances => No,
146            RustcDumpVariancesOfOpaques => No,
147            RustcDumpVtable(..) => No,
148            RustcDynIncompatibleTrait(..) => No,
149            RustcEffectiveVisibility => Yes,
150            RustcEiiForeignItem => No,
151            RustcEvaluateWhereClauses => Yes,
152            RustcHasIncoherentInherentImpls => Yes,
153            RustcIfThisChanged(..) => No,
154            RustcInheritOverflowChecks => No,
155            RustcInsignificantDtor => Yes,
156            RustcIntrinsic => Yes,
157            RustcIntrinsicConstStableIndirect => No,
158            RustcLegacyConstGenerics { .. } => Yes,
159            RustcLintOptDenyFieldAccess { .. } => Yes,
160            RustcLintOptTy => Yes,
161            RustcLintQueryInstability => Yes,
162            RustcLintUntrackedQueryInformation => Yes,
163            RustcMacroTransparency(..) => Yes,
164            RustcMain => No,
165            RustcMir(..) => Yes,
166            RustcMustImplementOneOf { .. } => No,
167            RustcMustMatchExhaustively(..) => Yes,
168            RustcNeverReturnsNullPtr => Yes,
169            RustcNoImplicitAutorefs => Yes,
170            RustcNoImplicitBounds => No,
171            RustcNoMirInline => Yes,
172            RustcNoWritable => Yes,
173            RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
174            RustcNonnullOptimizationGuaranteed => Yes,
175            RustcNounwind => No,
176            RustcObjcClass { .. } => No,
177            RustcObjcSelector { .. } => No,
178            RustcOffloadKernel => Yes,
179            RustcPanicsWhenZero => Yes,
180            RustcParenSugar => No,
181            RustcPassByValue => Yes,
182            RustcPassIndirectlyInNonRusticAbis(..) => No,
183            RustcPreserveUbChecks => No,
184            RustcProcMacroDecls => No,
185            RustcPubTransparent(..) => Yes,
186            RustcReallocator => No,
187            RustcRegions => No,
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            RustcTestMarker(..) => No,
196            RustcThenThisWouldNeed(..) => No,
197            RustcTrivialFieldReads => Yes,
198            Sanitize { .. } => No,
199            ShouldPanic { .. } => No,
200            Splat(..) => Yes,
201            Stability { .. } => Yes,
202            TargetFeature { .. } => No,
203            TestRunner(..) => Yes,
204            ThreadLocal => No,
205            TrackCaller(..) => Yes,
206            TypeLengthLimit { .. } => No,
207            Unroll(..) => No,
208            UnstableFeatureBound(..) => No,
209            UnstableRemoved(..) => Yes,
210            Used { .. } => No,
211            WindowsSubsystem(..) => No,
212            // tidy-alphabetical-end
213        }
214    }
215}