Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes at a mod-level #104

Merged
merged 6 commits into from
Jan 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix some clippy issues
  • Loading branch information
palfrey committed Dec 30, 2023
commit 67d22ff9eef867032031e30fc65a58154f588364
31 changes: 14 additions & 17 deletions serial_test_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ fn fs_parallel_core(
parallel_setup(input, config, "fs")
}

#[allow(clippy::cmp_owned)]
fn core_setup(
input: proc_macro2::TokenStream,
config: &Config,
Expand All @@ -337,40 +338,36 @@ fn core_setup(
let mod_ast: SynResult<syn::ItemMod> = syn::parse2(input);
match mod_ast {
Ok(mut ast) => {
let new_content = ast.content.clone().and_then(|(brace, items)| {
let new_content = ast.content.clone().map(|(brace, items)| {
let new_items = items
.into_iter()
.map(|item| match item {
syn::Item::Fn(item_fn)
if item_fn
.attrs
.iter()
.find(|attr| {
attr.meta
.path()
.segments
.first()
.unwrap()
.ident
.to_string()
.contains("test")
})
.is_some() =>
if item_fn.attrs.iter().any(|attr| {
attr.meta
.path()
.segments
.first()
.unwrap()
.ident
.to_string()
.contains("test")
}) =>
{
syn::parse2(fn_setup(item_fn, config, prefix, kind)).unwrap()
}
other => other,
})
.collect();
Some((brace, new_items))
(brace, new_items)
});
if let Some(nc) = new_content {
ast.content.replace(nc);
}
ast.attrs.retain(|attr| {
attr.meta.path().segments.first().unwrap().ident.to_string() != "serial"
});
ast.into_token_stream().into()
ast.into_token_stream()
}
Err(_) => {
panic!("Attribute applied to something other than mod or fn!");
Expand Down
Loading