Skip to content

Commit fdc8c43

Browse files
committed
Fix nested attributes
1 parent c0c3802 commit fdc8c43

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ fn expand_for_cfg(ts: TokenStream, active_cfg: &Cfg) -> TokenStream {
3939
TokenTree::Punct(p) if p.as_char() == '#' => {
4040
// # ...
4141
let Some(TokenTree::Group(g)) = it.peek() else {
42+
out.extend([tt]);
4243
continue;
4344
};
4445
if g.delimiter() != Delimiter::Bracket {
46+
out.extend([tt]);
4547
continue;
4648
}
4749

@@ -51,12 +53,15 @@ fn expand_for_cfg(ts: TokenStream, active_cfg: &Cfg) -> TokenStream {
5153
attr_ts.extend(iter::once(TokenTree::Group(g.clone())));
5254

5355
let Ok(attr) = parse_any_attr(attr_ts) else {
56+
out.extend([tt]);
5457
continue;
5558
};
5659
let Some(cfg) = Cfg::from_attr(&attr) else {
60+
out.extend([tt]);
5761
continue;
5862
};
5963
if !attr.path().is_ident("cfg") {
64+
out.extend([tt]);
6065
continue;
6166
}
6267

tests/pass/nested_other_attrs.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use cfg_tt::cfg_tt;
2+
3+
cfg_tt! {
4+
/// some doc comment
5+
#[allow(clippy::pendantic)]
6+
pub fn foo() {
7+
#[cfg(windows)]
8+
let _ = "noop";
9+
}
10+
}
11+
12+
fn main() {
13+
foo();
14+
}

0 commit comments

Comments
 (0)