Port crate name to the new attribute system

This commit is contained in:
Jana Dönszelmann
2025-08-11 11:46:30 +02:00
parent 4b35cde904
commit 59ceb02d65
25 changed files with 458 additions and 366 deletions

View File

@@ -367,6 +367,9 @@ pub enum AttributeKind {
/// Represents `#[coverage(..)]`.
Coverage(Span, CoverageAttrKind),
/// Represents `#[crate_name = ...]`
CrateName { name: Symbol, name_span: Span, attr_span: Span, style: AttrStyle },
/// Represents `#[custom_mir]`.
CustomMir(Option<(MirDialect, Span)>, Option<(MirPhase, Span)>, Span),

View File

@@ -7,6 +7,11 @@ pub enum EncodeCrossCrate {
}
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::*;
@@ -31,6 +36,7 @@ impl AttributeKind {
ConstTrait(..) => No,
Coroutine(..) => No,
Coverage(..) => No,
CrateName { .. } => No,
CustomMir(_, _, _) => Yes,
DenyExplicitImpl(..) => No,
Deprecation { .. } => Yes,