blob: 0f4bb8f167d9fe291f80c7acbac970fbf547175f [file]
use crate::AttributeKind;
#[derive(PartialEq)]
pub enum EncodeCrossCrate {
Yes,
No,
}
impl AttributeKind {
/// Whether this attribute should be encoded in metadata files.
///
/// If this is "Yes", then another crate can do `tcx.get_all_attrs(did)` for a did in this crate, and get the attribute.
/// When this is No, the attribute is filtered out while encoding and other crate won't be able to observe it.
/// This can be unexpectedly good for performance, so unless necessary for cross-crate compilation, prefer No.
pub fn encode_cross_crate(&self) -> EncodeCrossCrate {
use AttributeKind::*;
use EncodeCrossCrate::*;
match self {
// tidy-alphabetical-start
AllowInternalUnsafe(..) => Yes,
AllowInternalUnstable(..) => Yes,
AlwaysGca => Yes,
AutomaticallyDerived => Yes,
CfgAttrTrace(..) => Yes,
CfgTrace(..) => Yes,
CfiEncoding { .. } => Yes,
Cold => No,
CollapseDebugInfo(..) => Yes,
CompilerBuiltins => No,
ConstContinue(..) => No,
Coroutine => No,
Coverage(..) => No,
CrateName { .. } => No,
CrateType(_) => No,
CustomMir(_, _) => Yes,
DebuggerVisualizer(..) => No,
DefaultLibAllocator => No,
Deprecated { .. } => Yes,
DoNotRecommend => Yes,
Doc(_) => Yes,
DocComment { .. } => Yes,
EiiDeclaration(_) => Yes,
EiiImpl(..) => No,
ExportName { .. } => Yes,
ExportStable => No,
Feature(..) => No,
FfiConst => No,
FfiPure(..) => No,
Fundamental { .. } => Yes,
Ignore { .. } => No,
Inline(..) => No,
InstructionSet(..) => No,
InstrumentFn(..) => No,
Lang(..) => Yes,
Link(..) => No,
LinkName { .. } => Yes, // Needed for rustdoc
LinkOrdinal { .. } => No,
LinkSection { .. } => Yes, // Needed for rustdoc
Linkage(..) => No,
LintAsPtr => Yes,
LintCheck(..) => No,
LintNeverReturnsNullPtr => Yes,
LintShouldNotBeCalledOnConstItems => Yes,
LoopMatch(..) => No,
MacroEscape => No,
MacroExport { .. } => Yes,
MacroUse { .. } => No,
Marker => No,
MayDangle(..) => No,
MoveSizeLimit { .. } => No,
MustNotSuspend { .. } => Yes,
MustUse { .. } => Yes,
Naked(..) => No,
NeedsAllocator => No,
NeedsPanicRuntime => No,
NoBuiltins => Yes,
NoCore => No,
NoImplicitPrelude => No,
NoLink => No,
NoMain => No,
NoMangle(..) => Yes, // Needed for rustdoc
NoStd => No,
NonExhaustive(..) => Yes, // Needed for rustdoc
OnConst { .. } => Yes,
OnMove { .. } => Yes,
OnTypeError { .. } => Yes,
OnUnimplemented { .. } => Yes,
OnUnknown { .. } => Yes,
OnUnmatchedArgs { .. } => Yes,
Opaque => Yes,
Optimize(..) => No,
PanicRuntime => No,
PatchableFunctionEntry { .. } => Yes,
Path(..) => No,
PatternComplexityLimit { .. } => No,
PinV2(..) => Yes,
PreludeImport => No,
ProcMacro => No,
ProcMacroAttribute => No,
ProcMacroDerive { .. } => No,
ProfilerRuntime => No,
RecursionLimit { .. } => No,
ReexportTestHarnessMain(..) => No,
RegisterTool { .. } => No,
Repr { .. } => No,
RustcAbi { .. } => No,
RustcAlign { .. } => No,
RustcAllocator => No,
RustcAllocatorZeroed => No,
RustcAllocatorZeroedVariant { .. } => Yes,
RustcAllowConstFnUnstable(..) => No,
RustcAllowIncoherentImpl(..) => No,
RustcAllowLifetimeDependentSpecialization => No,
RustcAssertVariance { .. } => No,
RustcAutodiff(..) => Yes,
RustcBodyStability { .. } => No,
RustcBuiltinMacro { .. } => Yes,
RustcCanonicalSymbol => No,
RustcCaptureAnalysis => No,
RustcCguTestAttr { .. } => No,
RustcClean { .. } => No,
RustcCoherenceIsCore => No,
RustcCoinductive => No,
RustcComptime(..) => No, // Encoded directly in signature
RustcConfusables { .. } => Yes,
RustcConstStability { .. } => Yes,
RustcConstStableIndirect => No,
RustcConversionSuggestion => Yes,
RustcDeallocator => No,
RustcDelayedBugFromInsideQuery => No,
RustcDenyExplicitImpl => No,
RustcDeprecatedSafe2024 { .. } => Yes,
RustcDiagnosticItem(..) => Yes,
RustcDoNotConstCheck => Yes,
RustcDocPrimitive(..) => Yes,
RustcDummy => No,
RustcDumpClauses => No,
RustcDumpDefParents => No,
RustcDumpDefPath(..) => No,
RustcDumpGenerics => No,
RustcDumpHiddenTypeOfOpaques => No,
RustcDumpInferredOutlives => No,
RustcDumpItemBounds => No,
RustcDumpLayout(..) => No,
RustcDumpObjectLifetimeDefaults => No,
RustcDumpSymbolName(..) => Yes,
RustcDumpUserArgs => No,
RustcDumpVariances => No,
RustcDumpVariancesOfOpaques => No,
RustcDumpVtable(..) => No,
RustcDynIncompatibleTrait(..) => No,
RustcEffectiveVisibility => Yes,
RustcEiiForeignItem => No,
RustcEvaluateWhereClauses => Yes,
RustcHasIncoherentInherentImpls => Yes,
RustcIfThisChanged(..) => No,
RustcInheritOverflowChecks => No,
RustcInsignificantDtor => Yes,
RustcIntrinsic => Yes,
RustcIntrinsicConstStableIndirect => No,
RustcLegacyConstGenerics { .. } => Yes,
RustcLintOptDenyFieldAccess { .. } => Yes,
RustcLintOptTy => Yes,
RustcLintQueryInstability => Yes,
RustcLintUntrackedQueryInformation => Yes,
RustcMacroTransparency(..) => Yes,
RustcMain => No,
RustcMir(..) => Yes,
RustcMustImplementOneOf { .. } => No,
RustcMustMatchExhaustively(..) => Yes,
RustcNoImplicitAutorefs => Yes,
RustcNoImplicitBounds => No,
RustcNoMirInline => Yes,
RustcNoWritable => Yes,
RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
RustcNonnullOptimizationGuaranteed => Yes,
RustcNounwind => No,
RustcObjcClass { .. } => No,
RustcObjcSelector { .. } => No,
RustcOffloadKernel => Yes,
RustcPanicsWhenZero => Yes,
RustcParenSugar => No,
RustcPassByValue => Yes,
RustcPassIndirectlyInNonRusticAbis(..) => No,
RustcPreserveUbChecks => No,
RustcProcMacroDecls => No,
RustcPubTransparent(..) => Yes,
RustcReallocator => No,
RustcRegions => No,
RustcScalableVector { .. } => Yes,
RustcShowSpans(_) => No,
RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
RustcSkipDuringMethodDispatch { .. } => No,
RustcSpecializationTrait => No,
RustcStdInternalSymbol => No,
RustcStrictCoherence(..) => Yes,
RustcTestEntrypointMarker => No,
RustcTestMarker(..) => No,
RustcThenThisWouldNeed(..) => No,
RustcTrivialFieldReads(..) => No,
Sanitize { .. } => No,
ShouldPanic { .. } => No,
Splat(..) => Yes,
Stability { .. } => Yes,
TargetFeature { .. } => No,
TestRunner(..) => Yes,
ThreadLocal => No,
TrackCaller(..) => Yes,
TypeLengthLimit { .. } => No,
UncheckedTypeAlias => Yes,
Unroll(..) => No,
UnstableFeatureBound(..) => No,
UnstableRemoved(..) => Yes,
Used { .. } => No,
WindowsSubsystem(..) => No,
// tidy-alphabetical-end
}
}
/// Whether this attribute is an extern indicator.
///
/// Must stay in sync with [`CodegenFnAttrs::contains_extern_indicator`].
///
/// [`CodegenFnAttrs::contains_extern_indicator`]: ../rustc_middle/middle/codegen_fn_attrs/struct.CodegenFnAttrs.html#method.contains_extern_indicator
pub fn is_extern_indicator(&self) -> bool {
use AttributeKind::*;
match self {
// tidy-alphabetical-start
AllowInternalUnsafe(..) => false,
AllowInternalUnstable(..) => false,
AlwaysGca => false,
AutomaticallyDerived => false,
CfgAttrTrace(..) => false,
CfgTrace(..) => false,
CfiEncoding { .. } => false,
Cold => false,
CollapseDebugInfo(..) => false,
CompilerBuiltins => false,
ConstContinue(..) => false,
Coroutine => false,
Coverage(..) => false,
CrateName { .. } => false,
CrateType(_) => false,
CustomMir(_, _) => false,
DebuggerVisualizer(..) => false,
DefaultLibAllocator => false,
Deprecated { .. } => false,
DoNotRecommend => false,
Doc(_) => false,
DocComment { .. } => false,
EiiDeclaration(_) => false,
EiiImpl(..) => true,
ExportName { .. } => true,
ExportStable => false,
Feature(..) => false,
FfiConst => false,
FfiPure(..) => false,
Fundamental { .. } => false,
Ignore { .. } => false,
Inline(..) => false,
InstructionSet(..) => false,
InstrumentFn(..) => false,
Lang(item) => item.link_name().is_some(),
Link(..) => false,
LinkName { .. } => false,
LinkOrdinal { .. } => false,
LinkSection { .. } => false,
Linkage(linkage, _) => match *linkage {
crate::Linkage::Internal => false,
crate::Linkage::AvailableExternally
| crate::Linkage::External
| crate::Linkage::ExternalWeak
| crate::Linkage::LinkOnceAny
| crate::Linkage::LinkOnceODR
| crate::Linkage::WeakAny
| crate::Linkage::WeakODR => true,
},
LintAsPtr => false,
LintCheck(_) => false,
LintNeverReturnsNullPtr => false,
LintShouldNotBeCalledOnConstItems => false,
LoopMatch(..) => false,
MacroEscape => false,
MacroExport { .. } => false,
MacroUse { .. } => false,
Marker => false,
MayDangle(..) => false,
MoveSizeLimit { .. } => false,
MustNotSuspend { .. } => false,
MustUse { .. } => false,
Naked(..) => false,
NeedsAllocator => false,
NeedsPanicRuntime => false,
NoBuiltins => false,
NoCore => false,
NoImplicitPrelude => false,
NoLink => false,
NoMain => false,
NoMangle(..) => true,
NoStd => false,
NonExhaustive(..) => false,
OnConst { .. } => false,
OnMove { .. } => false,
OnTypeError { .. } => false,
OnUnimplemented { .. } => false,
OnUnknown { .. } => false,
OnUnmatchedArgs { .. } => false,
Opaque => false,
Optimize(..) => false,
PanicRuntime => false,
PatchableFunctionEntry { .. } => false,
Path(..) => false,
PatternComplexityLimit { .. } => false,
PinV2(..) => false,
PreludeImport => false,
ProcMacro => false,
ProcMacroAttribute => false,
ProcMacroDerive { .. } => false,
ProfilerRuntime => false,
RecursionLimit { .. } => false,
ReexportTestHarnessMain(..) => false,
RegisterTool { .. } => false,
Repr { .. } => false,
RustcAbi { .. } => false,
RustcAlign { .. } => false,
RustcAllocator => false,
RustcAllocatorZeroed => false,
RustcAllocatorZeroedVariant { .. } => false,
RustcAllowConstFnUnstable(..) => false,
RustcAllowIncoherentImpl(..) => false,
RustcAllowLifetimeDependentSpecialization => false,
RustcAssertVariance { .. } => false,
RustcAutodiff(..) => false,
RustcBodyStability { .. } => false,
RustcBuiltinMacro { .. } => false,
RustcCanonicalSymbol => false,
RustcCaptureAnalysis => false,
RustcCguTestAttr { .. } => false,
RustcClean { .. } => false,
RustcCoherenceIsCore => false,
RustcCoinductive => false,
RustcComptime(..) => false,
RustcConfusables { .. } => false,
RustcConstStability { .. } => false,
RustcConstStableIndirect => false,
RustcConversionSuggestion => false,
RustcDeallocator => false,
RustcDelayedBugFromInsideQuery => false,
RustcDenyExplicitImpl => false,
RustcDeprecatedSafe2024 { .. } => false,
RustcDiagnosticItem(..) => false,
RustcDoNotConstCheck => false,
RustcDocPrimitive(..) => false,
RustcDummy => false,
RustcDumpClauses => false,
RustcDumpDefParents => false,
RustcDumpDefPath(..) => false,
RustcDumpGenerics => false,
RustcDumpHiddenTypeOfOpaques => false,
RustcDumpInferredOutlives => false,
RustcDumpItemBounds => false,
RustcDumpLayout(..) => false,
RustcDumpObjectLifetimeDefaults => false,
RustcDumpSymbolName(..) => false,
RustcDumpUserArgs => false,
RustcDumpVariances => false,
RustcDumpVariancesOfOpaques => false,
RustcDumpVtable(..) => false,
RustcDynIncompatibleTrait(..) => false,
RustcEffectiveVisibility => false,
RustcEiiForeignItem => true,
RustcEvaluateWhereClauses => false,
RustcHasIncoherentInherentImpls => false,
RustcIfThisChanged(..) => false,
RustcInheritOverflowChecks => false,
RustcInsignificantDtor => false,
RustcIntrinsic => false,
RustcIntrinsicConstStableIndirect => false,
RustcLegacyConstGenerics { .. } => false,
RustcLintOptDenyFieldAccess { .. } => false,
RustcLintOptTy => false,
RustcLintQueryInstability => false,
RustcLintUntrackedQueryInformation => false,
RustcMacroTransparency(..) => false,
RustcMain => false,
RustcMir(..) => false,
RustcMustImplementOneOf { .. } => false,
RustcMustMatchExhaustively(..) => false,
RustcNoImplicitAutorefs => false,
RustcNoImplicitBounds => false,
RustcNoMirInline => false,
RustcNoWritable => false,
RustcNonConstTraitMethod => false,
RustcNonnullOptimizationGuaranteed => false,
RustcNounwind => false,
RustcObjcClass { .. } => false,
RustcObjcSelector { .. } => false,
RustcOffloadKernel => true,
RustcPanicsWhenZero => false,
RustcParenSugar => false,
RustcPassByValue => false,
RustcPassIndirectlyInNonRusticAbis(..) => false,
RustcPreserveUbChecks => false,
RustcProcMacroDecls => false,
RustcPubTransparent(..) => false,
RustcReallocator => false,
RustcRegions => false,
RustcScalableVector { .. } => false,
RustcShowSpans(_) => false,
RustcSimdMonomorphizeLaneLimit(..) => false,
RustcSkipDuringMethodDispatch { .. } => false,
RustcSpecializationTrait => false,
RustcStdInternalSymbol => true,
RustcStrictCoherence(..) => false,
RustcTestEntrypointMarker => false,
RustcTestMarker(..) => false,
RustcThenThisWouldNeed(..) => false,
RustcTrivialFieldReads(..) => false,
Sanitize { .. } => false,
ShouldPanic { .. } => false,
Splat(..) => false,
Stability { .. } => false,
TargetFeature { .. } => false,
TestRunner(..) => false,
ThreadLocal => false,
TrackCaller(..) => false,
TypeLengthLimit { .. } => false,
UncheckedTypeAlias => false,
Unroll(..) => false,
UnstableFeatureBound(..) => false,
UnstableRemoved(..) => false,
Used { .. } => false,
WindowsSubsystem(..) => false,
// tidy-alphabetical-end
}
}
}