@@ -14,15 +14,15 @@ enum TargetScope {
14
14
15
15
#[ derive( Default ) ]
16
16
struct TargetOsIterator {
17
- meta : VecDeque < Meta > ,
18
- scope : TargetScope ,
17
+ meta : VecDeque < ( TargetScope , Meta ) > ,
18
+ // scope: TargetScope,
19
19
}
20
20
21
21
impl TargetOsIterator {
22
22
fn new ( meta : Meta ) -> Self {
23
23
Self {
24
- meta : VecDeque :: from ( [ meta] ) ,
25
- ..Default :: default ( )
24
+ meta : VecDeque :: from ( [ ( TargetScope :: Accept , meta) ] ) ,
25
+ // ..Default::default()
26
26
}
27
27
}
28
28
}
@@ -31,10 +31,10 @@ impl Iterator for TargetOsIterator {
31
31
type Item = ( TargetScope , String ) ;
32
32
33
33
fn next ( & mut self ) -> Option < Self :: Item > {
34
- while let Some ( meta) = self . meta . pop_front ( ) {
34
+ while let Some ( ( mut scope , meta) ) = self . meta . pop_front ( ) {
35
35
if meta. path ( ) . is_ident ( "not" ) {
36
36
debug ! ( "encountered not" ) ;
37
- self . scope = TargetScope :: Reject
37
+ scope = TargetScope :: Reject
38
38
}
39
39
40
40
match meta {
@@ -54,7 +54,8 @@ impl Iterator for TargetOsIterator {
54
54
} )
55
55
. ok ( ) ?;
56
56
debug ! ( "\t expanding with {} meta" , nested_meta_list. len( ) ) ;
57
- self . meta . extend ( nested_meta_list) ;
57
+ self . meta
58
+ . extend ( nested_meta_list. into_iter ( ) . map ( |meta| ( scope, meta) ) ) ;
58
59
}
59
60
Meta :: NameValue ( nv) => {
60
61
#[ cfg( test) ]
@@ -70,7 +71,7 @@ impl Iterator for TargetOsIterator {
70
71
_ => None ,
71
72
} )
72
73
{
73
- return Some ( ( self . scope , value) ) ;
74
+ return Some ( ( scope, value) ) ;
74
75
}
75
76
}
76
77
}
@@ -300,4 +301,16 @@ mod test {
300
301
& [ "macos" . into( ) , "android" . into( ) ]
301
302
) ) ;
302
303
}
304
+
305
+ #[ test]
306
+ fn test_not_scope ( ) {
307
+ init_log ( ) ;
308
+
309
+ let test_struct: ItemStruct = parse_quote ! {
310
+ #[ cfg( all( not( feature = "my-feature" ) , target_os = "android" ) ) ]
311
+ pub struct Test ;
312
+ } ;
313
+
314
+ assert ! ( accept_target_os( & test_struct. attrs, & [ "android" . into( ) ] ) )
315
+ }
303
316
}
0 commit comments