rustc_hir/attrs/
encode_cross_crate.rs

1use crate::attrs::AttributeKind;
2
3#[derive(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            AllowConstFnUnstable(..) => No,
23            AllowIncoherentImpl(..) => No,
24            AllowInternalUnsafe(..) => Yes,
25            AllowInternalUnstable(..) => Yes,
26            AsPtr(..) => Yes,
27            AutomaticallyDerived(..) => Yes,
28            BodyStability { .. } => No,
29            CfgAttrTrace => Yes,
30            CfgTrace(..) => Yes,
31            CfiEncoding { .. } => Yes,
32            Coinductive(..) => No,
33            Cold(..) => No,
34            Confusables { .. } => Yes,
35            ConstContinue(..) => No,
36            ConstStability { .. } => Yes,
37            ConstStabilityIndirect => No,
38            Coroutine(..) => No,
39            Coverage(..) => No,
40            CrateName { .. } => No,
41            CustomMir(_, _, _) => Yes,
42            DebuggerVisualizer(..) => No,
43            DenyExplicitImpl(..) => No,
44            Deprecation { .. } => Yes,
45            DoNotImplementViaObject(..) => No,
46            Doc(_) => Yes,
47            DocComment { .. } => Yes,
48            Dummy => No,
49            EiiExternItem => No,
50            EiiExternTarget(_) => Yes,
51            EiiImpls(..) => No,
52            ExportName { .. } => Yes,
53            ExportStable => No,
54            FfiConst(..) => No,
55            FfiPure(..) => No,
56            Fundamental { .. } => Yes,
57            Ignore { .. } => No,
58            Inline(..) => No,
59            InstructionSet(..) => No,
60            Link(..) => No,
61            LinkName { .. } => Yes, // Needed for rustdoc
62            LinkOrdinal { .. } => No,
63            LinkSection { .. } => Yes, // Needed for rustdoc
64            Linkage(..) => No,
65            LoopMatch(..) => No,
66            MacroEscape(..) => No,
67            MacroExport { .. } => Yes,
68            MacroTransparency(..) => Yes,
69            MacroUse { .. } => No,
70            Marker(..) => No,
71            MayDangle(..) => No,
72            MoveSizeLimit { .. } => No,
73            MustUse { .. } => Yes,
74            Naked(..) => No,
75            NoCore(..) => No,
76            NoImplicitPrelude(..) => No,
77            NoLink => No,
78            NoMangle(..) => Yes, // Needed for rustdoc
79            NoStd(..) => No,
80            NonExhaustive(..) => Yes, // Needed for rustdoc
81            ObjcClass { .. } => No,
82            ObjcSelector { .. } => No,
83            Optimize(..) => No,
84            ParenSugar(..) => No,
85            PassByValue(..) => Yes,
86            Path(..) => No,
87            PatternComplexityLimit { .. } => No,
88            PinV2(..) => Yes,
89            Pointee(..) => No,
90            ProcMacro(..) => No,
91            ProcMacroAttribute(..) => No,
92            ProcMacroDerive { .. } => No,
93            PubTransparent(..) => Yes,
94            RecursionLimit { .. } => No,
95            Repr { .. } => No,
96            RustcBuiltinMacro { .. } => Yes,
97            RustcCoherenceIsCore(..) => No,
98            RustcLayoutScalarValidRangeEnd(..) => Yes,
99            RustcLayoutScalarValidRangeStart(..) => Yes,
100            RustcLegacyConstGenerics { .. } => Yes,
101            RustcLintDiagnostics => Yes,
102            RustcLintOptDenyFieldAccess { .. } => Yes,
103            RustcLintOptTy => Yes,
104            RustcLintQueryInstability => Yes,
105            RustcLintUntrackedQueryInformation => Yes,
106            RustcMain => No,
107            RustcMustImplementOneOf { .. } => No,
108            RustcNeverReturnsNullPointer => Yes,
109            RustcNoImplicitAutorefs => Yes,
110            RustcObjectLifetimeDefault => No,
111            RustcPassIndirectlyInNonRusticAbis(..) => No,
112            RustcScalableVector { .. } => Yes,
113            RustcShouldNotBeCalledOnConstItems(..) => Yes,
114            RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
115            Sanitize { .. } => No,
116            ShouldPanic { .. } => No,
117            SkipDuringMethodDispatch { .. } => No,
118            SpecializationTrait(..) => No,
119            Stability { .. } => Yes,
120            StdInternalSymbol(..) => No,
121            TargetFeature { .. } => No,
122            ThreadLocal => No,
123            TrackCaller(..) => Yes,
124            TypeConst(..) => Yes,
125            TypeLengthLimit { .. } => No,
126            UnsafeSpecializationMarker(..) => No,
127            UnstableFeatureBound(..) => No,
128            Used { .. } => No,
129            WindowsSubsystem(..) => No,
130            // tidy-alphabetical-end
131        }
132    }
133}