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