@@ -76,14 +76,23 @@ pub fn get_deprecated(attrs: &Vec<Attribute>) -> Option<DeprecationAttr> {
76
76
fn get_deprecated_meta_list ( list : & MetaList ) -> DeprecationAttr {
77
77
for meta in & list. nested {
78
78
match meta {
79
- & NestedMeta :: Meta ( Meta :: NameValue ( ref nv) ) if nv. ident == "note" => match & nv. lit {
80
- & Lit :: Str ( ref strlit) => {
81
- return DeprecationAttr {
82
- reason : Some ( strlit. value ( ) . to_string ( ) ) ,
83
- } ;
79
+ & NestedMeta :: Meta ( Meta :: NameValue ( ref nv) ) => {
80
+ if nv. ident == "note" {
81
+ match & nv. lit {
82
+ & Lit :: Str ( ref strlit) => {
83
+ return DeprecationAttr {
84
+ reason : Some ( strlit. value ( ) ) ,
85
+ } ;
86
+ }
87
+ _ => panic ! ( "deprecated attribute note value only has string literal" ) ,
88
+ }
89
+ } else {
90
+ panic ! (
91
+ "Unrecognized setting on #[deprecated(..)] attribute: {}" ,
92
+ nv. ident
93
+ ) ;
84
94
}
85
- _ => panic ! ( "deprecated attribute note value only has string literal" ) ,
86
- } ,
95
+ }
87
96
_ => { }
88
97
}
89
98
}
@@ -434,7 +443,7 @@ pub enum FieldAttributeParseMode {
434
443
enum FieldAttribute {
435
444
Name ( syn:: LitStr ) ,
436
445
Description ( syn:: LitStr ) ,
437
- Deprecation ( Option < syn :: LitStr > ) ,
446
+ Deprecation ( DeprecationAttr ) ,
438
447
Skip ( syn:: Ident ) ,
439
448
Arguments ( HashMap < String , FieldAttributeArgument > ) ,
440
449
}
@@ -466,11 +475,13 @@ impl parse::Parse for FieldAttribute {
466
475
"deprecated" | "deprecation" => {
467
476
let reason = if input. peek ( Token ! [ =] ) {
468
477
input. parse :: < Token ! [ =] > ( ) ?;
469
- Some ( input. parse ( ) ?)
478
+ Some ( input. parse :: < syn :: LitStr > ( ) ?. value ( ) )
470
479
} else {
471
480
None
472
481
} ;
473
- Ok ( FieldAttribute :: Deprecation ( reason) )
482
+ Ok ( FieldAttribute :: Deprecation ( DeprecationAttr {
483
+ reason : reason,
484
+ } ) )
474
485
}
475
486
"skip" => Ok ( FieldAttribute :: Skip ( ident) ) ,
476
487
"arguments" => {
@@ -525,10 +536,8 @@ impl parse::Parse for FieldAttributes {
525
536
FieldAttribute :: Description ( name) => {
526
537
output. description = Some ( name. value ( ) ) ;
527
538
}
528
- FieldAttribute :: Deprecation ( reason_opt) => {
529
- output. deprecation = Some ( DeprecationAttr {
530
- reason : reason_opt. map ( |val| val. value ( ) ) ,
531
- } ) ;
539
+ FieldAttribute :: Deprecation ( attr) => {
540
+ output. deprecation = Some ( attr) ;
532
541
}
533
542
FieldAttribute :: Skip ( _) => {
534
543
output. skip = true ;
@@ -553,6 +562,7 @@ impl FieldAttributes {
553
562
_mode : FieldAttributeParseMode ,
554
563
) -> syn:: parse:: Result < Self > {
555
564
let doc_comment = get_doc_comment ( & attrs) ;
565
+ let deprecation = get_deprecated ( & attrs) ;
556
566
557
567
let attr_opt = attrs
558
568
. into_iter ( )
@@ -562,9 +572,15 @@ impl FieldAttributes {
562
572
Some ( attr) => syn:: parse ( attr. tts . into ( ) ) ?,
563
573
None => Self :: default ( ) ,
564
574
} ;
575
+
576
+ // Check for regular doc comment.
565
577
if output. description . is_none ( ) {
566
578
output. description = doc_comment;
567
579
}
580
+ if output. deprecation . is_none ( ) {
581
+ output. deprecation = deprecation;
582
+ }
583
+
568
584
Ok ( output)
569
585
}
570
586
0 commit comments