File tree 2 files changed +49
-5
lines changed
2 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ pub struct TypeDef {
13
13
vis : Option < String > ,
14
14
docs : Option < Docs > ,
15
15
derive : Vec < String > ,
16
- allow : Option < String > ,
16
+ allow : Vec < String > ,
17
17
repr : Option < String > ,
18
18
bounds : Vec < Bound > ,
19
19
macros : Vec < String > ,
@@ -27,7 +27,7 @@ impl TypeDef {
27
27
vis : None ,
28
28
docs : None ,
29
29
derive : vec ! [ ] ,
30
- allow : None ,
30
+ allow : vec ! [ ] ,
31
31
repr : None ,
32
32
bounds : vec ! [ ] ,
33
33
macros : vec ! [ ] ,
@@ -61,7 +61,7 @@ impl TypeDef {
61
61
}
62
62
63
63
pub fn allow ( & mut self , allow : & str ) {
64
- self . allow = Some ( allow. to_string ( ) ) ;
64
+ self . allow . push ( allow. to_string ( ) ) ;
65
65
}
66
66
67
67
pub fn repr ( & mut self , repr : & str ) {
@@ -107,8 +107,8 @@ impl TypeDef {
107
107
Ok ( ( ) )
108
108
}
109
109
110
- fn fmt_allow ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
111
- if let Some ( ref allow) = self . allow {
110
+ fn fmt_allow ( & self , fmt : & mut Formatter ) -> fmt:: Result {
111
+ for allow in & self . allow {
112
112
write ! ( fmt, "#[allow({})]\n " , allow) ?;
113
113
}
114
114
Original file line number Diff line number Diff line change @@ -561,3 +561,47 @@ impl Foo for Bar {
561
561
562
562
assert_eq ! ( scope. to_string( ) , & expect[ 1 ..] ) ;
563
563
}
564
+
565
+ #[ test]
566
+ fn struct_with_multiple_allow ( ) {
567
+ let mut scope = Scope :: new ( ) ;
568
+
569
+ scope
570
+ . new_struct ( "Foo" )
571
+ . allow ( "dead_code" )
572
+ . allow ( "clippy::all" )
573
+ . field ( "one" , "u8" )
574
+ . field ( "two" , "u8" ) ;
575
+
576
+ let expect = r#"
577
+ #[allow(dead_code)]
578
+ #[allow(clippy::all)]
579
+ struct Foo {
580
+ one: u8,
581
+ two: u8,
582
+ }"# ;
583
+
584
+ assert_eq ! ( scope. to_string( ) , & expect[ 1 ..] ) ;
585
+ }
586
+
587
+ #[ test]
588
+ fn enum_with_multiple_allow ( ) {
589
+ let mut scope = Scope :: new ( ) ;
590
+
591
+ scope
592
+ . new_enum ( "IpAddrKind" )
593
+ . allow ( "dead_code" )
594
+ . allow ( "clippy::all" )
595
+ . push_variant ( Variant :: new ( "V4" ) )
596
+ . push_variant ( Variant :: new ( "V6" ) ) ;
597
+
598
+ let expect = r#"
599
+ #[allow(dead_code)]
600
+ #[allow(clippy::all)]
601
+ enum IpAddrKind {
602
+ V4,
603
+ V6,
604
+ }"# ;
605
+
606
+ assert_eq ! ( scope. to_string( ) , & expect[ 1 ..] ) ;
607
+ }
You can’t perform that action at this time.
0 commit comments