Skip to content

Commit 5c0addc

Browse files
update scope handling
1 parent 63f6e71 commit 5c0addc

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

core/src/target_os_check.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ enum TargetScope {
1414

1515
#[derive(Default)]
1616
struct TargetOsIterator {
17-
meta: VecDeque<Meta>,
18-
scope: TargetScope,
17+
meta: VecDeque<(TargetScope, Meta)>,
18+
// scope: TargetScope,
1919
}
2020

2121
impl TargetOsIterator {
2222
fn new(meta: Meta) -> Self {
2323
Self {
24-
meta: VecDeque::from([meta]),
25-
..Default::default()
24+
meta: VecDeque::from([(TargetScope::Accept, meta)]),
25+
// ..Default::default()
2626
}
2727
}
2828
}
@@ -31,10 +31,10 @@ impl Iterator for TargetOsIterator {
3131
type Item = (TargetScope, String);
3232

3333
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() {
3535
if meta.path().is_ident("not") {
3636
debug!("encountered not");
37-
self.scope = TargetScope::Reject
37+
scope = TargetScope::Reject
3838
}
3939

4040
match meta {
@@ -54,7 +54,8 @@ impl Iterator for TargetOsIterator {
5454
})
5555
.ok()?;
5656
debug!("\texpanding 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)));
5859
}
5960
Meta::NameValue(nv) => {
6061
#[cfg(test)]
@@ -70,7 +71,7 @@ impl Iterator for TargetOsIterator {
7071
_ => None,
7172
})
7273
{
73-
return Some((self.scope, value));
74+
return Some((scope, value));
7475
}
7576
}
7677
}
@@ -300,4 +301,16 @@ mod test {
300301
&["macos".into(), "android".into()]
301302
));
302303
}
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+
}
303316
}

0 commit comments

Comments
 (0)