@@ -70,7 +70,6 @@ pub enum OptimizeAttr {
70
70
#[ derive( HashStable_Generic ) ]
71
71
pub struct Stability {
72
72
pub level : StabilityLevel ,
73
- pub feature : Symbol ,
74
73
}
75
74
76
75
impl Stability {
@@ -88,11 +87,11 @@ impl Stability {
88
87
}
89
88
90
89
/// 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).
91
91
#[ derive( Encodable , Decodable , Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
92
92
#[ derive( HashStable_Generic ) ]
93
93
pub struct ConstStability {
94
94
pub level : StabilityLevel ,
95
- pub feature : Symbol ,
96
95
/// This is true iff the `const_stable_indirect` attribute is present.
97
96
pub const_stable_indirect : bool ,
98
97
/// whether the function has a `#[rustc_promotable]` attribute
@@ -114,7 +113,6 @@ impl ConstStability {
114
113
#[ derive( HashStable_Generic ) ]
115
114
pub struct DefaultBodyStability {
116
115
pub level : StabilityLevel ,
117
- pub feature : Symbol ,
118
116
}
119
117
120
118
/// The available stability levels.
@@ -123,31 +121,11 @@ pub struct DefaultBodyStability {
123
121
pub enum StabilityLevel {
124
122
/// `#[unstable]`
125
123
Unstable {
124
+ /// The information unique to each `#[unstable]` attribute
125
+ unstables : Unstability ,
126
126
/// Reason for the current stability level.
127
127
reason : UnstableReason ,
128
- /// Relevant `rust-lang/rust` issue.
129
- issue : Option < NonZero < u32 > > ,
130
128
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 > ,
151
129
} ,
152
130
/// `#[stable]`
153
131
Stable {
@@ -185,6 +163,35 @@ impl StabilityLevel {
185
163
}
186
164
}
187
165
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
+
188
195
#[ derive( Encodable , Decodable , PartialEq , Copy , Clone , Debug , Eq , Hash ) ]
189
196
#[ derive( HashStable_Generic ) ]
190
197
pub enum UnstableReason {
@@ -231,8 +238,8 @@ pub fn find_stability(
231
238
break ;
232
239
}
233
240
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 ) ) ;
236
243
}
237
244
}
238
245
sym:: stable => {
@@ -241,8 +248,8 @@ pub fn find_stability(
241
248
. emit_err ( session_diagnostics:: MultipleStabilityLevels { span : attr. span } ) ;
242
249
break ;
243
250
}
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 ) ) ;
246
253
}
247
254
}
248
255
_ => { }
@@ -290,14 +297,9 @@ pub fn find_const_stability(
290
297
break ;
291
298
}
292
299
293
- if let Some ( ( feature , level) ) = parse_unstability ( sess, attr) {
300
+ if let Some ( level) = parse_unstability ( sess, attr) {
294
301
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 } ,
301
303
attr. span ,
302
304
) ) ;
303
305
}
@@ -308,14 +310,9 @@ pub fn find_const_stability(
308
310
. emit_err ( session_diagnostics:: MultipleStabilityLevels { span : attr. span } ) ;
309
311
break ;
310
312
}
311
- if let Some ( ( feature , level) ) = parse_stability ( sess, attr) {
313
+ if let Some ( level) = parse_stability ( sess, attr) {
312
314
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 } ,
319
316
attr. span ,
320
317
) ) ;
321
318
}
@@ -369,12 +366,7 @@ pub fn unmarked_crate_const_stab(
369
366
// We enforce recursive const stability rules for those functions.
370
367
let const_stable_indirect =
371
368
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 }
378
370
}
379
371
380
372
/// Collects stability info from `rustc_default_body_unstable` attributes in `attrs`.
@@ -393,8 +385,8 @@ pub fn find_body_stability(
393
385
break ;
394
386
}
395
387
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 ) ) ;
398
390
}
399
391
}
400
392
}
@@ -420,7 +412,7 @@ fn insert_or_error(sess: &Session, meta: &MetaItem, item: &mut Option<Symbol>) -
420
412
421
413
/// Read the content of a `stable`/`rustc_const_stable` attribute, and return the feature name and
422
414
/// its stability information.
423
- fn parse_stability ( sess : & Session , attr : & Attribute ) -> Option < ( Symbol , StabilityLevel ) > {
415
+ fn parse_stability ( sess : & Session , attr : & Attribute ) -> Option < StabilityLevel > {
424
416
let meta = attr. meta ( ) ?;
425
417
let MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } = meta else { return None } ;
426
418
@@ -474,17 +466,16 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
474
466
} ;
475
467
476
468
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 } )
480
471
}
481
472
Err ( ErrorGuaranteed { .. } ) => None ,
482
473
}
483
474
}
484
475
485
476
/// Read the content of a `unstable`/`rustc_const_unstable`/`rustc_default_body_unstable`
486
477
/// 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 > {
488
479
let meta = attr. meta ( ) ?;
489
480
let MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } = meta else { return None } ;
490
481
@@ -564,12 +555,11 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
564
555
match ( feature, issue) {
565
556
( Ok ( feature) , Ok ( _) ) => {
566
557
let level = StabilityLevel :: Unstable {
558
+ unstables : Unstability { feature, issue : issue_num, implied_by } ,
567
559
reason : UnstableReason :: from_opt_reason ( reason) ,
568
- issue : issue_num,
569
560
is_soft,
570
- implied_by,
571
561
} ;
572
- Some ( ( feature , level) )
562
+ Some ( level)
573
563
}
574
564
( Err ( ErrorGuaranteed { .. } ) , _) | ( _, Err ( ErrorGuaranteed { .. } ) ) => None ,
575
565
}
0 commit comments