@@ -537,19 +537,13 @@ pub fn test(args: TokenStream, input: TokenStream) -> TokenStream {
537537
538538 // The first attributes indicates sync condition
539539 let sync_cond = match_nested_meta_to_str_lit ! ( attr_args. first( ) . unwrap( ) ) ;
540- let mut ts = if attr_args. len ( ) == 1 {
541- quote ! (
542- #[ cfg( #sync_cond) ]
543- #[ cfg_attr( #sync_cond, maybe_async:: must_be_sync, test) ]
544- )
545- } else {
546- quote ! ( #[ cfg_attr( #sync_cond, maybe_async:: must_be_sync, test) ] )
547- } ;
540+ let mut ts = quote ! ( #[ cfg_attr( #sync_cond, maybe_async:: must_be_sync, test) ] ) ;
548541
549542 // The rest attributes indicates async condition and async test macro
550543 // only accepts in the forms of `async(cond, test_macro)`, but `cond` and
551544 // `test_macro` can be either meta attributes or string literal
552545 let mut async_token = Vec :: new ( ) ;
546+ let mut async_conditions = Vec :: new ( ) ;
553547 for async_meta in attr_args. into_iter ( ) . skip ( 1 ) {
554548 match async_meta {
555549 NestedMeta :: Meta ( meta) => match meta {
@@ -568,9 +562,9 @@ pub fn test(args: TokenStream, input: TokenStream) -> TokenStream {
568562 match_nested_meta_to_str_lit ! ( list. nested. first( ) . unwrap( ) ) ;
569563 let async_test = match_nested_meta_to_str_lit ! ( list. nested. last( ) . unwrap( ) ) ;
570564 let attr = quote ! (
571- #[ cfg( #async_cond) ]
572565 #[ cfg_attr( #async_cond, maybe_async:: must_be_async, #async_test) ]
573566 ) ;
567+ async_conditions. push ( async_cond) ;
574568 async_token. push ( attr) ;
575569 } else {
576570 let msg = format ! (
@@ -603,5 +597,16 @@ pub fn test(args: TokenStream, input: TokenStream) -> TokenStream {
603597
604598 async_token. into_iter ( ) . for_each ( |t| ts. extend ( t) ) ;
605599 ts. extend ( quote ! ( #input ) ) ;
606- ts. into ( )
600+ if !async_conditions. is_empty ( ) {
601+ quote ! {
602+ #[ cfg( any( #sync_cond, #( #async_conditions) , * ) ) ]
603+ #ts
604+ }
605+ } else {
606+ quote ! {
607+ #[ cfg( #sync_cond) ]
608+ #ts
609+ }
610+ }
611+ . into ( )
607612}
0 commit comments