@@ -124,13 +124,11 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
124
124
///
125
125
/// - `#[stable]`
126
126
/// - `#[unstable]`
127
- /// - `#[rustc_deprecated]`
128
127
#[ derive( RustcEncodable , RustcDecodable , Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
129
128
#[ derive( HashStable_Generic ) ]
130
129
pub struct Stability {
131
130
pub level : StabilityLevel ,
132
131
pub feature : Symbol ,
133
- pub rustc_depr : Option < RustcDeprecation > ,
134
132
}
135
133
136
134
/// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
@@ -163,15 +161,6 @@ impl StabilityLevel {
163
161
}
164
162
}
165
163
166
- #[ derive( RustcEncodable , RustcDecodable , PartialEq , PartialOrd , Copy , Clone , Debug , Eq , Hash ) ]
167
- #[ derive( HashStable_Generic ) ]
168
- pub struct RustcDeprecation {
169
- pub since : Symbol ,
170
- pub reason : Symbol ,
171
- /// A text snippet used to completely replace any use of the deprecated item in an expression.
172
- pub suggestion : Option < Symbol > ,
173
- }
174
-
175
164
/// Checks if `attrs` contains an attribute like `#![feature(feature_name)]`.
176
165
/// This will not perform any "sanity checks" on the form of the attributes.
177
166
pub fn contains_feature_attr ( attrs : & [ Attribute ] , feature_name : Symbol ) -> bool {
@@ -205,15 +194,13 @@ where
205
194
use StabilityLevel :: * ;
206
195
207
196
let mut stab: Option < Stability > = None ;
208
- let mut rustc_depr: Option < RustcDeprecation > = None ;
209
197
let mut const_stab: Option < ConstStability > = None ;
210
198
let mut promotable = false ;
211
199
let mut allow_const_fn_ptr = false ;
212
200
let diagnostic = & sess. span_diagnostic ;
213
201
214
202
' outer: for attr in attrs_iter {
215
203
if ![
216
- sym:: rustc_deprecated,
217
204
sym:: rustc_const_unstable,
218
205
sym:: rustc_const_stable,
219
206
sym:: unstable,
@@ -258,76 +245,8 @@ where
258
245
}
259
246
} ;
260
247
261
- macro_rules! get_meta {
262
- ( $( $name: ident) ,+) => {
263
- $(
264
- let mut $name = None ;
265
- ) +
266
- for meta in metas {
267
- if let Some ( mi) = meta. meta_item( ) {
268
- match mi. name_or_empty( ) {
269
- $(
270
- sym:: $name => if !get( mi, & mut $name) { continue ' outer } ,
271
- ) +
272
- _ => {
273
- let expected = & [ $( stringify!( $name) ) ,+ ] ;
274
- handle_errors(
275
- sess,
276
- mi. span,
277
- AttrError :: UnknownMetaItem (
278
- pprust:: path_to_string( & mi. path) ,
279
- expected,
280
- ) ,
281
- ) ;
282
- continue ' outer
283
- }
284
- }
285
- } else {
286
- handle_errors(
287
- sess,
288
- meta. span( ) ,
289
- AttrError :: UnsupportedLiteral (
290
- "unsupported literal" ,
291
- false ,
292
- ) ,
293
- ) ;
294
- continue ' outer
295
- }
296
- }
297
- }
298
- }
299
-
300
248
let meta_name = meta. name_or_empty ( ) ;
301
249
match meta_name {
302
- sym:: rustc_deprecated => {
303
- if rustc_depr. is_some ( ) {
304
- struct_span_err ! (
305
- diagnostic,
306
- item_sp,
307
- E0540 ,
308
- "multiple rustc_deprecated attributes"
309
- )
310
- . emit ( ) ;
311
- continue ' outer;
312
- }
313
-
314
- get_meta ! ( since, reason, suggestion) ;
315
-
316
- match ( since, reason) {
317
- ( Some ( since) , Some ( reason) ) => {
318
- rustc_depr = Some ( RustcDeprecation { since, reason, suggestion } )
319
- }
320
- ( None , _) => {
321
- handle_errors ( sess, attr. span , AttrError :: MissingSince ) ;
322
- continue ;
323
- }
324
- _ => {
325
- struct_span_err ! ( diagnostic, attr. span, E0543 , "missing 'reason'" )
326
- . emit ( ) ;
327
- continue ;
328
- }
329
- }
330
- }
331
250
sym:: rustc_const_unstable | sym:: unstable => {
332
251
if meta_name == sym:: unstable && stab. is_some ( ) {
333
252
handle_errors ( sess, attr. span , AttrError :: MultipleStabilityLevels ) ;
@@ -429,7 +348,7 @@ where
429
348
( Some ( feature) , reason, Some ( _) ) => {
430
349
let level = Unstable { reason, issue : issue_num, is_soft } ;
431
350
if sym:: unstable == meta_name {
432
- stab = Some ( Stability { level, feature, rustc_depr : None } ) ;
351
+ stab = Some ( Stability { level, feature } ) ;
433
352
} else {
434
353
const_stab = Some ( ConstStability {
435
354
level,
@@ -501,7 +420,7 @@ where
501
420
( Some ( feature) , Some ( since) ) => {
502
421
let level = Stable { since } ;
503
422
if sym:: stable == meta_name {
504
- stab = Some ( Stability { level, feature, rustc_depr : None } ) ;
423
+ stab = Some ( Stability { level, feature } ) ;
505
424
} else {
506
425
const_stab = Some ( ConstStability {
507
426
level,
@@ -526,22 +445,6 @@ where
526
445
}
527
446
}
528
447
529
- // Merge the deprecation info into the stability info
530
- if let Some ( rustc_depr) = rustc_depr {
531
- if let Some ( ref mut stab) = stab {
532
- stab. rustc_depr = Some ( rustc_depr) ;
533
- } else {
534
- struct_span_err ! (
535
- diagnostic,
536
- item_sp,
537
- E0549 ,
538
- "rustc_deprecated attribute must be paired with \
539
- either stable or unstable attribute"
540
- )
541
- . emit ( ) ;
542
- }
543
- }
544
-
545
448
// Merge the const-unstable info into the stability info
546
449
if promotable || allow_const_fn_ptr {
547
450
if let Some ( ref mut stab) = const_stab {
@@ -714,7 +617,16 @@ pub fn eval_condition(
714
617
#[ derive( RustcEncodable , RustcDecodable , Clone , HashStable_Generic ) ]
715
618
pub struct Deprecation {
716
619
pub since : Option < Symbol > ,
620
+ /// The note to issue a reason.
717
621
pub note : Option < Symbol > ,
622
+ /// A text snippet used to completely replace any use of the deprecated item in an expression.
623
+ ///
624
+ /// This is currently unstable.
625
+ pub suggestion : Option < Symbol > ,
626
+
627
+ /// Whether to treat the since attribute as being a Rust version identifier
628
+ /// (rather than an opaque string).
629
+ pub is_since_rustc_version : bool ,
718
630
}
719
631
720
632
/// Finds the deprecation attribute. `None` if none exists.
@@ -738,7 +650,7 @@ where
738
650
let diagnostic = & sess. span_diagnostic ;
739
651
740
652
' outer: for attr in attrs_iter {
741
- if !attr. check_name ( sym:: deprecated) {
653
+ if !( attr. check_name ( sym:: deprecated) || attr . check_name ( sym :: rustc_deprecated ) ) {
742
654
continue ;
743
655
}
744
656
@@ -751,11 +663,12 @@ where
751
663
Some ( meta) => meta,
752
664
None => continue ,
753
665
} ;
754
- depr = match & meta. kind {
755
- MetaItemKind :: Word => Some ( Deprecation { since : None , note : None } ) ,
756
- MetaItemKind :: NameValue ( ..) => {
757
- meta. value_str ( ) . map ( |note| Deprecation { since : None , note : Some ( note) } )
758
- }
666
+ let mut since = None ;
667
+ let mut note = None ;
668
+ let mut suggestion = None ;
669
+ match & meta. kind {
670
+ MetaItemKind :: Word => { }
671
+ MetaItemKind :: NameValue ( ..) => note = meta. value_str ( ) ,
759
672
MetaItemKind :: List ( list) => {
760
673
let get = |meta : & MetaItem , item : & mut Option < Symbol > | {
761
674
if item. is_some ( ) {
@@ -789,8 +702,6 @@ where
789
702
}
790
703
} ;
791
704
792
- let mut since = None ;
793
- let mut note = None ;
794
705
for meta in list {
795
706
match meta {
796
707
NestedMetaItem :: MetaItem ( mi) => match mi. name_or_empty ( ) {
@@ -799,18 +710,32 @@ where
799
710
continue ' outer;
800
711
}
801
712
}
802
- sym:: note => {
713
+ sym:: note if attr. check_name ( sym:: deprecated) => {
714
+ if !get ( mi, & mut note) {
715
+ continue ' outer;
716
+ }
717
+ }
718
+ sym:: reason if attr. check_name ( sym:: rustc_deprecated) => {
803
719
if !get ( mi, & mut note) {
804
720
continue ' outer;
805
721
}
806
722
}
723
+ sym:: suggestion if attr. check_name ( sym:: rustc_deprecated) => {
724
+ if !get ( mi, & mut suggestion) {
725
+ continue ' outer;
726
+ }
727
+ }
807
728
_ => {
808
729
handle_errors (
809
730
sess,
810
731
meta. span ( ) ,
811
732
AttrError :: UnknownMetaItem (
812
733
pprust:: path_to_string ( & mi. path ) ,
813
- & [ "since" , "note" ] ,
734
+ if attr. check_name ( sym:: deprecated) {
735
+ & [ "since" , "note" ]
736
+ } else {
737
+ & [ "since" , "reason" , "suggestion" ]
738
+ } ,
814
739
) ,
815
740
) ;
816
741
continue ' outer;
@@ -829,10 +754,29 @@ where
829
754
}
830
755
}
831
756
}
757
+ }
758
+ }
759
+
760
+ if suggestion. is_some ( ) && attr. check_name ( sym:: deprecated) {
761
+ unreachable ! ( "only allowed on rustc_deprecated" )
762
+ }
832
763
833
- Some ( Deprecation { since, note } )
764
+ if attr. check_name ( sym:: rustc_deprecated) {
765
+ if since. is_none ( ) {
766
+ handle_errors ( sess, attr. span , AttrError :: MissingSince ) ;
767
+ continue ;
834
768
}
835
- } ;
769
+
770
+ if note. is_none ( ) {
771
+ struct_span_err ! ( diagnostic, attr. span, E0543 , "missing 'reason'" ) . emit ( ) ;
772
+ continue ;
773
+ }
774
+ }
775
+
776
+ mark_used ( & attr) ;
777
+
778
+ let is_since_rustc_version = attr. check_name ( sym:: rustc_deprecated) ;
779
+ depr = Some ( Deprecation { since, note, suggestion, is_since_rustc_version } ) ;
836
780
}
837
781
838
782
depr
0 commit comments