From 0f88d142338468ccbf966cc353c041b2362328ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Tue, 18 Jul 2023 16:45:10 +0200 Subject: [PATCH] Iterate over all elements of `Path` when making sure `timeout` is not used twice This fixes code completion inside intellij-rust and rust-analyzer when using another proc macro with tests, like `#[tokio::test]` --- ntest_timeout/src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ntest_timeout/src/lib.rs b/ntest_timeout/src/lib.rs index 4757670..18cc48b 100644 --- a/ntest_timeout/src/lib.rs +++ b/ntest_timeout/src/lib.rs @@ -83,20 +83,17 @@ fn check_other_attributes(input: &syn::ItemFn) { match meta { std::result::Result::Ok(m) => match m { syn::Meta::Path(p) => { - let identifier = p.get_ident().expect("Expected identifier!"); - if identifier == "timeout" { + if p.segments.iter().any(|ps| ps.ident == "timeout") { panic!("Timeout attribute is only allowed once"); } } syn::Meta::List(ml) => { - let identifier = ml.path.get_ident().expect("Expected identifier!"); - if identifier == "timeout" { + if ml.path.segments.iter().any(|ps| ps.ident == "timeout") { panic!("Timeout attribute is only allowed once"); } } syn::Meta::NameValue(nv) => { - let identifier = nv.path.get_ident().expect("Expected identifier!"); - if identifier == "timeout" { + if nv.path.segments.iter().any(|ps| ps.ident == "timeout") { panic!("Timeout attribute is only allowed once"); } }