@@ -82,6 +82,10 @@ impl Iterator for TargetOsIterator {
82
82
}
83
83
84
84
pub ( crate ) fn accept_target_os ( attrs : & [ Attribute ] , target_os : & [ String ] ) -> bool {
85
+ if target_os. is_empty ( ) {
86
+ return true ;
87
+ }
88
+
85
89
let ( accepted, rejected) : ( Vec < _ > , Vec < _ > ) = attrs
86
90
. iter ( )
87
91
. inspect ( |attr| {
@@ -124,7 +128,7 @@ mod test {
124
128
use flexi_logger:: DeferredNow ;
125
129
use log:: Record ;
126
130
use std:: { io:: Write , sync:: Once } ;
127
- use syn:: { parse_quote, ItemStruct } ;
131
+ use syn:: { parse_quote, ItemEnum , ItemStruct } ;
128
132
129
133
static INIT : Once = Once :: new ( ) ;
130
134
@@ -326,4 +330,27 @@ mod test {
326
330
327
331
assert ! ( accept_target_os( & test_struct. attrs, & [ "android" . into( ) ] ) )
328
332
}
333
+
334
+ #[ test]
335
+ fn test_enum_no_target_os_enabled ( ) {
336
+ init_log ( ) ;
337
+
338
+ let test_enum: ItemEnum = parse_quote ! {
339
+ #[ typeshare]
340
+ pub enum TestEnum {
341
+ #[ cfg( target_os = "ios" ) ]
342
+ Variant1 ,
343
+ #[ cfg( target_os = "android" ) ]
344
+ Variant2 ,
345
+ }
346
+ } ;
347
+
348
+ let variants = test_enum
349
+ . variants
350
+ . iter ( )
351
+ . map ( |v| accept_target_os ( & v. attrs , & [ ] ) )
352
+ . collect :: < Vec < _ > > ( ) ;
353
+
354
+ assert_eq ! ( & variants, & [ true , true ] ) ;
355
+ }
329
356
}
0 commit comments