Auto merge of #155788 - mejrs:reduce_attr_size, r=<try>

Reduce AttributeKind from 40 to 32 bytes
This commit is contained in:
bors
2026-04-26 09:57:26 +00:00
14 changed files with 22 additions and 40 deletions
@@ -171,7 +171,6 @@ fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<Attrib
Some(AttributeKind::PatternComplexityLimit {
limit: cx.parse_limit_int(nv)?,
attr_span: cx.attr_span,
limit_span: nv.value_span,
})
}
}
@@ -163,7 +163,6 @@ fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<Attrib
Some(AttributeKind::Deprecated {
deprecation: Deprecation { since, note, suggestion },
span: cx.attr_span,
})
}
}
@@ -272,9 +272,9 @@ fn finalize(mut self, cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind>
}
}
let (stability, span) = self.stability?;
let (stability, _) = self.stability?;
Some(AttributeKind::RustcConstStability { stability, span })
Some(AttributeKind::RustcConstStability { stability })
}
}
@@ -1014,7 +1014,6 @@ pub enum AttributeKind {
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
Deprecated {
deprecation: Deprecation,
span: Span,
},
/// Represents `#[diagnostic::do_not_recommend]`.
@@ -1233,7 +1232,6 @@ pub enum AttributeKind {
/// Represents `#[pattern_complexity_limit]`
PatternComplexityLimit {
attr_span: Span,
limit_span: Span,
limit: Limit,
},
@@ -1348,8 +1346,6 @@ pub enum AttributeKind {
/// Represents `#[rustc_const_stable]` and `#[rustc_const_unstable]`.
RustcConstStability {
stability: PartialConstStability,
/// Span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` attribute
span: Span,
},
/// Represents `#[rustc_const_stable_indirect]`.
@@ -1674,3 +1670,5 @@ pub enum AttributeKind {
WindowsSubsystem(WindowsSubsystemKind, Span),
// tidy-alphabetical-end
}
const _: () = assert!(std::mem::size_of::<AttributeKind>() == 32);
-1
View File
@@ -1385,7 +1385,6 @@ fn span(&self) -> Span {
Attribute::Unparsed(u) => u.span,
// FIXME: should not be needed anymore when all attrs are parsed
Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
Attribute::Parsed(AttributeKind::Deprecated { span, .. }) => *span,
Attribute::Parsed(AttributeKind::CfgTrace(cfgs)) => cfgs[0].1,
a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
}
+3 -2
View File
@@ -150,8 +150,9 @@ fn check_attributes(
Attribute::Parsed(AttributeKind::RustcAllowConstFnUnstable(_, first_span)) => {
self.check_rustc_allow_const_fn_unstable(hir_id, *first_span, span, target)
}
Attribute::Parsed(AttributeKind::Deprecated { span: attr_span, .. }) => {
self.check_deprecated(hir_id, *attr_span, target)
Attribute::Parsed(AttributeKind::Deprecated { .. }) => {
// FIXME move to attr parsing
self.check_deprecated(hir_id, rustc_span::DUMMY_SP, target)
}
Attribute::Parsed(AttributeKind::TargetFeature{ attr_span, ..}) => {
self.check_target_feature(hir_id, *attr_span, target, attrs)
-2
View File
@@ -898,8 +898,6 @@ pub(crate) struct MissingConstErr {
pub(crate) struct ConstStableNotStable {
#[primary_span]
pub fn_sig_span: Span,
#[label("attribute specified here")]
pub const_span: Span,
}
#[derive(Diagnostic)]
+2 -2
View File
@@ -30,8 +30,8 @@ fn extract(&self, attr: &Attribute) -> Option<(Symbol, FeatureStability, Span)>
Attribute::Parsed(AttributeKind::Stability { stability, span }) => {
(stability.feature, stability.level, *span)
}
Attribute::Parsed(AttributeKind::RustcConstStability { stability, span }) => {
(stability.feature, stability.level, *span)
Attribute::Parsed(AttributeKind::RustcConstStability { stability }) => {
(stability.feature, stability.level, rustc_span::DUMMY_SP)
}
Attribute::Parsed(AttributeKind::RustcBodyStability { stability, span }) => {
(stability.feature, stability.level, *span)
+10 -9
View File
@@ -97,7 +97,7 @@ fn annotation_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> AnnotationKind {
fn lookup_deprecation_entry(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<DeprecationEntry> {
let depr = find_attr!(tcx, def_id,
Deprecated { deprecation, span: _ } => *deprecation
Deprecated { deprecation, .. } => *deprecation
);
let Some(depr) = depr else {
@@ -218,7 +218,7 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt
let const_stable_indirect = find_attr!(tcx, def_id, RustcConstStableIndirect);
let const_stab =
find_attr!(tcx, def_id, RustcConstStability { stability, span: _ } => *stability);
find_attr!(tcx, def_id, RustcConstStability { stability } => *stability);
// After checking the immediate attributes, get rid of the span and compute implied
// const stability: inherit feature gate from regular stability.
@@ -324,6 +324,7 @@ fn check_compatible_stability(&self, def_id: LocalDefId) {
let depr = self.tcx.lookup_deprecation_entry(def_id);
let stab = self.tcx.lookup_stability(def_id);
let const_stab = self.tcx.lookup_const_stability(def_id);
let attrs = self.tcx.hir_attrs(self.tcx.local_def_id_to_hir_id(def_id));
macro_rules! find_attr_span {
($name:ident) => {{
@@ -334,9 +335,9 @@ macro_rules! find_attr_span {
if stab.is_none()
&& depr.map_or(false, |d| d.attr.is_since_rustc_version())
&& let Some(span) = find_attr_span!(Deprecated)
&& find_attr!(attrs, Deprecated { .. })
{
self.tcx.dcx().emit_err(errors::DeprecatedAttribute { span });
self.tcx.dcx().emit_err(errors::DeprecatedAttribute { span: rustc_span::DUMMY_SP });
}
if let Some(stab) = stab {
@@ -386,7 +387,7 @@ macro_rules! find_attr_span {
if let Some(fn_sig) = fn_sig
&& !fn_sig.header.is_const()
&& const_stab.is_some()
&& find_attr_span!(RustcConstStability).is_some()
&& find_attr!(attrs, RustcConstStability{..})
{
self.tcx.dcx().emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span });
}
@@ -396,19 +397,19 @@ macro_rules! find_attr_span {
&& let Some(fn_sig) = fn_sig
&& const_stab.is_const_stable()
&& !stab.is_some_and(|s| s.is_stable())
&& let Some(const_span) = find_attr_span!(RustcConstStability)
&& find_attr!( attrs, RustcConstStability {..})
{
self.tcx
.dcx()
.emit_err(errors::ConstStableNotStable { fn_sig_span: fn_sig.span, const_span });
.emit_err(errors::ConstStableNotStable { fn_sig_span: fn_sig.span });
}
if let Some(stab) = &const_stab
&& stab.is_const_stable()
&& stab.const_stable_indirect
&& let Some(span) = find_attr_span!(RustcConstStability)
&& find_attr!(attrs, RustcConstStability {..})
{
self.tcx.dcx().emit_err(errors::RustcConstStableIndirectPairing { span });
self.tcx.dcx().emit_err(errors::RustcConstStableIndirectPairing { span: rustc_span::DUMMY_SP });
}
}
@@ -49,16 +49,12 @@ LL | pub extern "C" fn foo_c() {}
error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`
--> $DIR/rustc-const-stability-require-const.rs:52:1
|
LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
| ---------------------------------------------------------------- attribute specified here
LL | const fn barfoo_unmarked() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`
--> $DIR/rustc-const-stability-require-const.rs:57:1
|
LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
| ---------------------------------------------------------------- attribute specified here
LL | pub const fn barfoo_unstable() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1,4 +1,4 @@
#![crate_type = "lib"]
#![crate_type = "lib"] //~ ERROR feature `const_bar` implying `const_foobar` does not exist
#![feature(staged_api)]
#![stable(feature = "stability_attribute_implies", since = "1.0.0")]
#![rustc_const_stable(feature = "stability_attribute_implies", since = "1.0.0")]
@@ -8,7 +8,6 @@
#[stable(feature = "stability_attribute_implies", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_foobar", issue = "1", implied_by = "const_bar")]
//~^ ERROR feature `const_bar` implying `const_foobar` does not exist
pub const fn foobar() -> u32 {
0
}
@@ -1,8 +1,4 @@
error: feature `const_bar` implying `const_foobar` does not exist
--> $DIR/const-stability-attribute-implies-missing.rs:10:1
|
LL | #[rustc_const_unstable(feature = "const_foobar", issue = "1", implied_by = "const_bar")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error
@@ -153,10 +153,6 @@ LL | #[deprecated(since = "invalid", note = "text")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0549]: deprecated attribute must be paired with either stable or unstable attribute
--> $DIR/stability-attribute-sanity.rs:71:1
|
LL | #[deprecated(since = "5.5.5", note = "text")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0711]: feature `a` is declared stable since 1.0.0, but was previously declared stable since 4.4.4
--> $DIR/stability-attribute-sanity.rs:67:1
+2 -2
View File
@@ -93,10 +93,10 @@ hir-stats GenericParam 400 (NN.N%) 5 80
hir-stats Block 288 (NN.N%) 6 48
hir-stats GenericBound 256 (NN.N%) 4 64
hir-stats - Trait 256 (NN.N%) 4
hir-stats Attribute 160 (NN.N%) 4 40
hir-stats Variant 144 (NN.N%) 2 72
hir-stats GenericArgs 144 (NN.N%) 3 48
hir-stats FieldDef 128 (NN.N%) 2 64
hir-stats Attribute 128 (NN.N%) 4 32
hir-stats FnDecl 120 (NN.N%) 3 40
hir-stats Stmt 96 (NN.N%) 3 32
hir-stats - Expr 32 (NN.N%) 1
@@ -119,5 +119,5 @@ hir-stats TraitItemId 8 (NN.N%) 2 4
hir-stats ImplItemId 8 (NN.N%) 2 4
hir-stats ForeignItemId 4 (NN.N%) 1 4
hir-stats ----------------------------------------------------------------
hir-stats Total 8_576 172
hir-stats Total 8_544 172
hir-stats ================================================================