@@ -70,7 +70,6 @@ pub enum OptimizeAttr {
7070#[ derive( HashStable_Generic ) ]
7171pub struct Stability {
7272 pub level : StabilityLevel ,
73- pub feature : Symbol ,
7473}
7574
7675impl Stability {
@@ -88,11 +87,11 @@ impl Stability {
8887}
8988
9089/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
90+ /// For details see [the dev guide](https://rustc-dev-guide.rust-lang.org/stability.html#rustc_const_unstable).
9191#[ derive( Encodable , Decodable , Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
9292#[ derive( HashStable_Generic ) ]
9393pub struct ConstStability {
9494 pub level : StabilityLevel ,
95- pub feature : Symbol ,
9695 /// This is true iff the `const_stable_indirect` attribute is present.
9796 pub const_stable_indirect : bool ,
9897 /// whether the function has a `#[rustc_promotable]` attribute
@@ -114,7 +113,6 @@ impl ConstStability {
114113#[ derive( HashStable_Generic ) ]
115114pub struct DefaultBodyStability {
116115 pub level : StabilityLevel ,
117- pub feature : Symbol ,
118116}
119117
120118/// The available stability levels.
@@ -123,31 +121,11 @@ pub struct DefaultBodyStability {
123121pub enum StabilityLevel {
124122 /// `#[unstable]`
125123 Unstable {
124+ /// The information unique to each `#[unstable]` attribute
125+ unstables : Unstability ,
126126 /// Reason for the current stability level.
127127 reason : UnstableReason ,
128- /// Relevant `rust-lang/rust` issue.
129- issue : Option < NonZero < u32 > > ,
130128 is_soft : bool ,
131- /// If part of a feature is stabilized and a new feature is added for the remaining parts,
132- /// then the `implied_by` attribute is used to indicate which now-stable feature previously
133- /// contained an item.
134- ///
135- /// ```pseudo-Rust
136- /// #[unstable(feature = "foo", issue = "...")]
137- /// fn foo() {}
138- /// #[unstable(feature = "foo", issue = "...")]
139- /// fn foobar() {}
140- /// ```
141- ///
142- /// ...becomes...
143- ///
144- /// ```pseudo-Rust
145- /// #[stable(feature = "foo", since = "1.XX.X")]
146- /// fn foo() {}
147- /// #[unstable(feature = "foobar", issue = "...", implied_by = "foo")]
148- /// fn foobar() {}
149- /// ```
150- implied_by : Option < Symbol > ,
151129 } ,
152130 /// `#[stable]`
153131 Stable {
@@ -185,6 +163,35 @@ impl StabilityLevel {
185163 }
186164}
187165
166+ /// An instance of an `#[unstable]`, `#[rustc_const_unstable]`, or similar attribute
167+ #[ derive( Encodable , Decodable , PartialEq , Copy , Clone , Debug , Eq , Hash ) ]
168+ #[ derive( HashStable_Generic ) ]
169+ pub struct Unstability {
170+ pub feature : Symbol ,
171+ /// Relevant `rust-lang/rust` issue.
172+ pub issue : Option < NonZero < u32 > > ,
173+ /// If part of a feature is stabilized and a new feature is added for the remaining parts,
174+ /// then the `implied_by` attribute is used to indicate which now-stable feature previously
175+ /// contained an item.
176+ ///
177+ /// ```pseudo-Rust
178+ /// #[unstable(feature = "foo", issue = "...")]
179+ /// fn foo() {}
180+ /// #[unstable(feature = "foo", issue = "...")]
181+ /// fn foobar() {}
182+ /// ```
183+ ///
184+ /// ...becomes...
185+ ///
186+ /// ```pseudo-Rust
187+ /// #[stable(feature = "foo", since = "1.XX.X")]
188+ /// fn foo() {}
189+ /// #[unstable(feature = "foobar", issue = "...", implied_by = "foo")]
190+ /// fn foobar() {}
191+ /// ```
192+ pub implied_by : Option < Symbol > ,
193+ }
194+
188195#[ derive( Encodable , Decodable , PartialEq , Copy , Clone , Debug , Eq , Hash ) ]
189196#[ derive( HashStable_Generic ) ]
190197pub enum UnstableReason {
@@ -231,8 +238,8 @@ pub fn find_stability(
231238 break ;
232239 }
233240
234- if let Some ( ( feature , level) ) = parse_unstability ( sess, attr) {
235- stab = Some ( ( Stability { level, feature } , attr. span ) ) ;
241+ if let Some ( level) = parse_unstability ( sess, attr) {
242+ stab = Some ( ( Stability { level } , attr. span ) ) ;
236243 }
237244 }
238245 sym:: stable => {
@@ -241,8 +248,8 @@ pub fn find_stability(
241248 . emit_err ( session_diagnostics:: MultipleStabilityLevels { span : attr. span } ) ;
242249 break ;
243250 }
244- if let Some ( ( feature , level) ) = parse_stability ( sess, attr) {
245- stab = Some ( ( Stability { level, feature } , attr. span ) ) ;
251+ if let Some ( level) = parse_stability ( sess, attr) {
252+ stab = Some ( ( Stability { level } , attr. span ) ) ;
246253 }
247254 }
248255 _ => { }
@@ -290,14 +297,9 @@ pub fn find_const_stability(
290297 break ;
291298 }
292299
293- if let Some ( ( feature , level) ) = parse_unstability ( sess, attr) {
300+ if let Some ( level) = parse_unstability ( sess, attr) {
294301 const_stab = Some ( (
295- ConstStability {
296- level,
297- feature,
298- const_stable_indirect : false ,
299- promotable : false ,
300- } ,
302+ ConstStability { level, const_stable_indirect : false , promotable : false } ,
301303 attr. span ,
302304 ) ) ;
303305 }
@@ -308,14 +310,9 @@ pub fn find_const_stability(
308310 . emit_err ( session_diagnostics:: MultipleStabilityLevels { span : attr. span } ) ;
309311 break ;
310312 }
311- if let Some ( ( feature , level) ) = parse_stability ( sess, attr) {
313+ if let Some ( level) = parse_stability ( sess, attr) {
312314 const_stab = Some ( (
313- ConstStability {
314- level,
315- feature,
316- const_stable_indirect : false ,
317- promotable : false ,
318- } ,
315+ ConstStability { level, const_stable_indirect : false , promotable : false } ,
319316 attr. span ,
320317 ) ) ;
321318 }
@@ -369,12 +366,7 @@ pub fn unmarked_crate_const_stab(
369366 // We enforce recursive const stability rules for those functions.
370367 let const_stable_indirect =
371368 attrs. iter ( ) . any ( |a| a. name_or_empty ( ) == sym:: rustc_const_stable_indirect) ;
372- ConstStability {
373- feature : regular_stab. feature ,
374- const_stable_indirect,
375- promotable : false ,
376- level : regular_stab. level ,
377- }
369+ ConstStability { const_stable_indirect, promotable : false , level : regular_stab. level }
378370}
379371
380372/// Collects stability info from `rustc_default_body_unstable` attributes in `attrs`.
@@ -393,8 +385,8 @@ pub fn find_body_stability(
393385 break ;
394386 }
395387
396- if let Some ( ( feature , level) ) = parse_unstability ( sess, attr) {
397- body_stab = Some ( ( DefaultBodyStability { level, feature } , attr. span ) ) ;
388+ if let Some ( level) = parse_unstability ( sess, attr) {
389+ body_stab = Some ( ( DefaultBodyStability { level } , attr. span ) ) ;
398390 }
399391 }
400392 }
@@ -420,7 +412,7 @@ fn insert_or_error(sess: &Session, meta: &MetaItem, item: &mut Option<Symbol>) -
420412
421413/// Read the content of a `stable`/`rustc_const_stable` attribute, and return the feature name and
422414/// its stability information.
423- fn parse_stability ( sess : & Session , attr : & Attribute ) -> Option < ( Symbol , StabilityLevel ) > {
415+ fn parse_stability ( sess : & Session , attr : & Attribute ) -> Option < StabilityLevel > {
424416 let meta = attr. meta ( ) ?;
425417 let MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } = meta else { return None } ;
426418
@@ -474,17 +466,16 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
474466 } ;
475467
476468 match feature {
477- Ok ( feature) => {
478- let level = StabilityLevel :: Stable { since, allowed_through_unstable_modules : false } ;
479- Some ( ( feature, level) )
469+ Ok ( _feature) => {
470+ Some ( StabilityLevel :: Stable { since, allowed_through_unstable_modules : false } )
480471 }
481472 Err ( ErrorGuaranteed { .. } ) => None ,
482473 }
483474}
484475
485476/// Read the content of a `unstable`/`rustc_const_unstable`/`rustc_default_body_unstable`
486477/// attribute, and return the feature name and its stability information.
487- fn parse_unstability ( sess : & Session , attr : & Attribute ) -> Option < ( Symbol , StabilityLevel ) > {
478+ fn parse_unstability ( sess : & Session , attr : & Attribute ) -> Option < StabilityLevel > {
488479 let meta = attr. meta ( ) ?;
489480 let MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } = meta else { return None } ;
490481
@@ -564,12 +555,11 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
564555 match ( feature, issue) {
565556 ( Ok ( feature) , Ok ( _) ) => {
566557 let level = StabilityLevel :: Unstable {
558+ unstables : Unstability { feature, issue : issue_num, implied_by } ,
567559 reason : UnstableReason :: from_opt_reason ( reason) ,
568- issue : issue_num,
569560 is_soft,
570- implied_by,
571561 } ;
572- Some ( ( feature , level) )
562+ Some ( level)
573563 }
574564 ( Err ( ErrorGuaranteed { .. } ) , _) | ( _, Err ( ErrorGuaranteed { .. } ) ) => None ,
575565 }
0 commit comments