mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Reduce AttributeKind from 40 to 32 bytes
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<Attrib
|
||||
}
|
||||
|
||||
Some(AttributeKind::Deprecated {
|
||||
deprecation: Deprecation { since, note, suggestion },
|
||||
deprecation: Box::new(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 })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -969,7 +969,7 @@ pub fn new(
|
||||
stability,
|
||||
deprecation: find_attr!(
|
||||
attrs,
|
||||
Deprecated { deprecation, .. } => *deprecation
|
||||
Deprecated { deprecation, .. } => **deprecation
|
||||
),
|
||||
helper_attrs,
|
||||
edition,
|
||||
|
||||
@@ -1013,7 +1013,7 @@ pub enum AttributeKind {
|
||||
|
||||
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
|
||||
Deprecated {
|
||||
deprecation: Deprecation,
|
||||
deprecation: Box<Deprecation>,
|
||||
span: Span,
|
||||
},
|
||||
|
||||
@@ -1233,7 +1233,6 @@ pub enum AttributeKind {
|
||||
/// Represents `#[pattern_complexity_limit]`
|
||||
PatternComplexityLimit {
|
||||
attr_span: Span,
|
||||
limit_span: Span,
|
||||
limit: Limit,
|
||||
},
|
||||
|
||||
@@ -1348,8 +1347,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 +1671,5 @@ pub enum AttributeKind {
|
||||
WindowsSubsystem(WindowsSubsystemKind, Span),
|
||||
// tidy-alphabetical-end
|
||||
}
|
||||
|
||||
const _: () = assert!(std::mem::size_of::<AttributeKind>() == 32);
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
@@ -379,6 +379,7 @@ macro_rules! find_attr_span {
|
||||
}
|
||||
}
|
||||
}
|
||||
let attrs = self.tcx.hir_attrs(self.tcx.local_def_id_to_hir_id(def_id));
|
||||
|
||||
// If the current node is a function with const stability attributes (directly given or
|
||||
// implied), check if the function/method is const or the parent impl block is const.
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 ================================================================
|
||||
|
||||
Reference in New Issue
Block a user