From d6c9bc2738258da49021435a773a87e6644d5431 Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Fri, 19 Apr 2024 15:42:27 +0800 Subject: [PATCH 01/10] macros: append generated test attribute so others are aware of it This way other test macros can choose to not generate `#[::core::prelude::v1::test]` to avoid duplicated test runs. This commit also rejects existing `#[::core::prelude::v1::test]` just like how and why it rejects existing `#[test]`. --- .../tests/fail/macros_invalid_input.rs | 4 ++++ .../tests/fail/macros_invalid_input.stderr | 20 ++++++++++++++++- tokio-macros/Cargo.toml | 2 +- tokio-macros/src/entry.rs | 22 ++++++++++++------- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/tests-build/tests/fail/macros_invalid_input.rs b/tests-build/tests/fail/macros_invalid_input.rs index 99daf00b4f9..e73459a575f 100644 --- a/tests-build/tests/fail/macros_invalid_input.rs +++ b/tests-build/tests/fail/macros_invalid_input.rs @@ -45,4 +45,8 @@ async fn test_crate_not_path_invalid() {} #[test] async fn test_has_second_test_attr() {} +#[tokio::test] +#[::core::prelude::v1::test] +async fn test_has_generated_second_test_attr() {} + fn main() {} diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 0c8d65fc159..8d84e23637b 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -76,7 +76,7 @@ error: Failed to parse value of `crate` as path: "456" 41 | #[tokio::test(crate = "456")] | ^^^^^ -error: second test attribute is supplied +error: second test attribute is supplied, try to order it after `tokio::test` --> $DIR/macros_invalid_input.rs:45:1 | 45 | #[test] @@ -93,3 +93,21 @@ note: the lint level is defined here | 1 | #![deny(duplicate_macro_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: second test attribute is supplied, try to order it after `tokio::test` + --> $DIR/macros_invalid_input.rs:49:1 + | +49 | #[::core::prelude::v1::test::test] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: duplicated attribute + --> $DIR/macros_invalid_input.rs:49:1 + | +49 | #[::core::prelude::v1::test::test] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/macros_invalid_input.rs:1:9 + | +1 | #![deny(duplicate_macro_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tokio-macros/Cargo.toml b/tokio-macros/Cargo.toml index ea9839c6d06..b40dc184050 100644 --- a/tokio-macros/Cargo.toml +++ b/tokio-macros/Cargo.toml @@ -24,7 +24,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.60" quote = "1" -syn = { version = "2.0", features = ["full"] } +syn = { version = "2.0", features = ["full", "extra-traits"] } [dev-dependencies] tokio = { version = "1.0.0", path = "../tokio", features = ["full"] } diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index ed782ad38f6..7b23b5c8194 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -1,7 +1,7 @@ use proc_macro2::{Span, TokenStream, TokenTree}; use quote::{quote, quote_spanned, ToTokens}; use syn::parse::{Parse, ParseStream, Parser}; -use syn::{braced, Attribute, Ident, Path, Signature, Visibility}; +use syn::{braced, parse_quote, Attribute, Ident, Path, Signature, Visibility}; // syn::AttributeArgs does not implement syn::Parse type AttributeArgs = syn::punctuated::Punctuated; @@ -360,7 +360,7 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt rt = quote_spanned! {last_stmt_start_span=> #rt.start_paused(#v) }; } - let header = if is_test { + let generated_attrs = if is_test { quote! { #[::core::prelude::v1::test] } @@ -410,7 +410,7 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt } }; - input.into_tokens(header, body, last_block) + input.into_tokens(generated_attrs, body, last_block) } fn token_stream_with_error(mut tokens: TokenStream, error: syn::Error) -> TokenStream { @@ -451,8 +451,13 @@ pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) Ok(it) => it, Err(e) => return token_stream_with_error(item, e), }; - let config = if let Some(attr) = input.attrs().find(|attr| attr.meta.path().is_ident("test")) { - let msg = "second test attribute is supplied"; + let test_attr: Attribute = parse_quote! { #[test] }; + let qualified_test_attr = parse_quote! { #[::core::prelude::v1::test] }; + let config = if let Some(attr) = input + .attrs() + .find(|attr| **attr == test_attr || **attr == qualified_test_attr) + { + let msg = "second test attribute is supplied, try to order it after `tokio::test`"; Err(syn::Error::new_spanned(attr, msg)) } else { AttributeArgs::parse_terminated @@ -493,13 +498,11 @@ impl ItemFn { /// Convert our local function item into a token stream. fn into_tokens( self, - header: proc_macro2::TokenStream, + generated_attrs: proc_macro2::TokenStream, body: proc_macro2::TokenStream, last_block: proc_macro2::TokenStream, ) -> TokenStream { let mut tokens = proc_macro2::TokenStream::new(); - header.to_tokens(&mut tokens); - // Outer attributes are simply streamed as-is. for attr in self.outer_attrs { attr.to_tokens(&mut tokens); @@ -513,6 +516,9 @@ impl ItemFn { attr.to_tokens(&mut tokens); } + // Add generated macros at the end, so macros processed later are aware of them. + generated_attrs.to_tokens(&mut tokens); + self.vis.to_tokens(&mut tokens); self.sig.to_tokens(&mut tokens); From 81e10afa0dfb63df337ae359d44d4b78b3ae25c8 Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Fri, 19 Apr 2024 17:43:07 +0800 Subject: [PATCH 02/10] fixup! macros: append generated test attribute so others are aware of it --- .../tests/fail/macros_invalid_input.stderr | 8 ++--- tokio-macros/Cargo.toml | 2 +- tokio-macros/src/entry.rs | 30 ++++++++++++++----- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 8d84e23637b..048577650b7 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -76,7 +76,7 @@ error: Failed to parse value of `crate` as path: "456" 41 | #[tokio::test(crate = "456")] | ^^^^^ -error: second test attribute is supplied, try to order it after `tokio::test` +error: second test attribute is supplied, consider removing it or ordering it after `tokio::test` --> $DIR/macros_invalid_input.rs:45:1 | 45 | #[test] @@ -94,16 +94,16 @@ note: the lint level is defined here 1 | #![deny(duplicate_macro_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: second test attribute is supplied, try to order it after `tokio::test` +error: second test attribute is supplied, consider removing it or ordering it after `tokio::test` --> $DIR/macros_invalid_input.rs:49:1 | -49 | #[::core::prelude::v1::test::test] +49 | #[::core::prelude::v1::test] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: duplicated attribute --> $DIR/macros_invalid_input.rs:49:1 | -49 | #[::core::prelude::v1::test::test] +49 | #[::core::prelude::v1::test] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here diff --git a/tokio-macros/Cargo.toml b/tokio-macros/Cargo.toml index b40dc184050..ea9839c6d06 100644 --- a/tokio-macros/Cargo.toml +++ b/tokio-macros/Cargo.toml @@ -24,7 +24,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.60" quote = "1" -syn = { version = "2.0", features = ["full", "extra-traits"] } +syn = { version = "2.0", features = ["full"] } [dev-dependencies] tokio = { version = "1.0.0", path = "../tokio", features = ["full"] } diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index 7b23b5c8194..c352fd2b22b 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -1,7 +1,7 @@ use proc_macro2::{Span, TokenStream, TokenTree}; use quote::{quote, quote_spanned, ToTokens}; use syn::parse::{Parse, ParseStream, Parser}; -use syn::{braced, parse_quote, Attribute, Ident, Path, Signature, Visibility}; +use syn::{braced, Attribute, Ident, Path, Signature, Visibility}; // syn::AttributeArgs does not implement syn::Parse type AttributeArgs = syn::punctuated::Punctuated; @@ -443,6 +443,25 @@ pub(crate) fn main(args: TokenStream, item: TokenStream, rt_multi_thread: bool) } } +// Check whether given attribute is `#[test]` or `#[::core::prelude::v1::test]`. +fn is_test_attribute(attr: &Attribute) -> bool { + let syn::Meta::Path(ref path) = attr.meta else { + return false; + }; + let segments = ["core", "prelude", "v1", "test"]; + if path.leading_colon.is_none() { + return path.segments.len() == 1 + && path.segments[0].arguments.is_none() + && path.segments[0].ident == "test"; + } else if path.segments.len() != segments.len() { + return false; + } + path.segments + .iter() + .zip(segments.into_iter()) + .all(|(segment, path)| segment.arguments.is_none() && segment.ident == path) +} + pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) -> TokenStream { // If any of the steps for this macro fail, we still want to expand to an item that is as close // to the expected output as possible. This helps out IDEs such that completions and other @@ -451,13 +470,8 @@ pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) Ok(it) => it, Err(e) => return token_stream_with_error(item, e), }; - let test_attr: Attribute = parse_quote! { #[test] }; - let qualified_test_attr = parse_quote! { #[::core::prelude::v1::test] }; - let config = if let Some(attr) = input - .attrs() - .find(|attr| **attr == test_attr || **attr == qualified_test_attr) - { - let msg = "second test attribute is supplied, try to order it after `tokio::test`"; + let config = if let Some(attr) = input.attrs().find(|attr| is_test_attribute(*attr)) { + let msg = "second test attribute is supplied, consider removing it or ordering it after `tokio::test`"; Err(syn::Error::new_spanned(attr, msg)) } else { AttributeArgs::parse_terminated From 90afc4c17f0c419dfc1248a3d0ad4729be742aa1 Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Fri, 19 Apr 2024 21:37:09 +0800 Subject: [PATCH 03/10] fixup! fixup! macros: append generated test attribute so others are aware of it --- tests-build/tests/fail/macros_invalid_input.stderr | 8 ++++---- tokio-macros/src/entry.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 048577650b7..278bce21dac 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -76,7 +76,7 @@ error: Failed to parse value of `crate` as path: "456" 41 | #[tokio::test(crate = "456")] | ^^^^^ -error: second test attribute is supplied, consider removing it or ordering it after `tokio::test` +error: second test attribute is supplied, consider removing or changing the order of your test attributes --> $DIR/macros_invalid_input.rs:45:1 | 45 | #[test] @@ -94,17 +94,17 @@ note: the lint level is defined here 1 | #![deny(duplicate_macro_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: second test attribute is supplied, consider removing it or ordering it after `tokio::test` +error: second test attribute is supplied, consider removing or changing the order of your test attributes --> $DIR/macros_invalid_input.rs:49:1 | 49 | #[::core::prelude::v1::test] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: duplicated attribute --> $DIR/macros_invalid_input.rs:49:1 | 49 | #[::core::prelude::v1::test] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/macros_invalid_input.rs:1:9 diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index c352fd2b22b..1bdd5e08a9a 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -471,7 +471,7 @@ pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) Err(e) => return token_stream_with_error(item, e), }; let config = if let Some(attr) = input.attrs().find(|attr| is_test_attribute(*attr)) { - let msg = "second test attribute is supplied, consider removing it or ordering it after `tokio::test`"; + let msg = "second test attribute is supplied, consider removing or changing the order of your test attributes"; Err(syn::Error::new_spanned(attr, msg)) } else { AttributeArgs::parse_terminated From a9d060979244c600e91fde181d97a5fa5470ee6d Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Fri, 19 Apr 2024 21:46:57 +0800 Subject: [PATCH 04/10] fixup! fixup! fixup! macros: append generated test attribute so others are aware of it --- tokio-macros/src/entry.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index 1bdd5e08a9a..85cf69d090e 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -445,8 +445,9 @@ pub(crate) fn main(args: TokenStream, item: TokenStream, rt_multi_thread: bool) // Check whether given attribute is `#[test]` or `#[::core::prelude::v1::test]`. fn is_test_attribute(attr: &Attribute) -> bool { - let syn::Meta::Path(ref path) = attr.meta else { - return false; + let path = match &attr.meta { + syn::Meta::Path(path) => path, + _ => return false, }; let segments = ["core", "prelude", "v1", "test"]; if path.leading_colon.is_none() { @@ -458,7 +459,7 @@ fn is_test_attribute(attr: &Attribute) -> bool { } path.segments .iter() - .zip(segments.into_iter()) + .zip(segments) .all(|(segment, path)| segment.arguments.is_none() && segment.ident == path) } @@ -470,7 +471,7 @@ pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) Ok(it) => it, Err(e) => return token_stream_with_error(item, e), }; - let config = if let Some(attr) = input.attrs().find(|attr| is_test_attribute(*attr)) { + let config = if let Some(attr) = input.attrs().find(|attr| is_test_attribute(attr)) { let msg = "second test attribute is supplied, consider removing or changing the order of your test attributes"; Err(syn::Error::new_spanned(attr, msg)) } else { From a4828d4264dd1bc6f7a51c184a73578661e0dabf Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Fri, 19 Apr 2024 22:14:05 +0800 Subject: [PATCH 05/10] fixup! fixup! fixup! fixup! macros: append generated test attribute so others are aware of it --- tests-build/tests/fail/macros_invalid_input.stderr | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 278bce21dac..6c49ecae491 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -88,11 +88,6 @@ error: duplicated attribute 45 | #[test] | ^^^^^^^ | -note: the lint level is defined here - --> $DIR/macros_invalid_input.rs:1:9 - | -1 | #![deny(duplicate_macro_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: second test attribute is supplied, consider removing or changing the order of your test attributes --> $DIR/macros_invalid_input.rs:49:1 @@ -105,9 +100,3 @@ error: duplicated attribute | 49 | #[::core::prelude::v1::test] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/macros_invalid_input.rs:1:9 - | -1 | #![deny(duplicate_macro_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ From 4f23227f47e1bf14a51818ed4d1f2524af9cdb5a Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Fri, 19 Apr 2024 22:27:03 +0800 Subject: [PATCH 06/10] align macros_invalid_input.stderr --- tests-build/tests/fail/macros_invalid_input.stderr | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 6c49ecae491..18db1464b3c 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -82,21 +82,8 @@ error: second test attribute is supplied, consider removing or changing the orde 45 | #[test] | ^^^^^^^ -error: duplicated attribute - --> $DIR/macros_invalid_input.rs:45:1 - | -45 | #[test] - | ^^^^^^^ - | - error: second test attribute is supplied, consider removing or changing the order of your test attributes --> $DIR/macros_invalid_input.rs:49:1 | 49 | #[::core::prelude::v1::test] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: duplicated attribute - --> $DIR/macros_invalid_input.rs:49:1 - | -49 | #[::core::prelude::v1::test] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From d92065043dc50e3f9d425f15c65758c4f5308e8f Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Sun, 5 May 2024 22:29:24 +0800 Subject: [PATCH 07/10] assert that we append test attribute instead of prepend --- tests-build/tests/fail/macros_invalid_input.rs | 2 +- tests-build/tests/fail/macros_invalid_input.stderr | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests-build/tests/fail/macros_invalid_input.rs b/tests-build/tests/fail/macros_invalid_input.rs index e73459a575f..b5536b021a7 100644 --- a/tests-build/tests/fail/macros_invalid_input.rs +++ b/tests-build/tests/fail/macros_invalid_input.rs @@ -46,7 +46,7 @@ async fn test_crate_not_path_invalid() {} async fn test_has_second_test_attr() {} #[tokio::test] -#[::core::prelude::v1::test] +#[tokio::test] async fn test_has_generated_second_test_attr() {} fn main() {} diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 18db1464b3c..30e810102f9 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -83,7 +83,7 @@ error: second test attribute is supplied, consider removing or changing the orde | ^^^^^^^ error: second test attribute is supplied, consider removing or changing the order of your test attributes - --> $DIR/macros_invalid_input.rs:49:1 + --> $DIR/macros_invalid_input.rs:48:1 | -49 | #[::core::prelude::v1::test] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +48 | #[tokio::test] + | ^^^^^^^^^^^^^^ From 51c473c2836a1212ffc69b52a9f3fd4af25edfcd Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Sun, 5 May 2024 22:44:14 +0800 Subject: [PATCH 08/10] fix mismatch in macros_invalid_input.stderr --- tests-build/tests/fail/macros_invalid_input.stderr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index 30e810102f9..e43226f253c 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -87,3 +87,5 @@ error: second test attribute is supplied, consider removing or changing the orde | 48 | #[tokio::test] | ^^^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `tokio::test` (in Nightly builds, run with -Z macro-backtrace for more info) From 6d2a30f8c6a930fc660fe87eb3f96f591a148d70 Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Sun, 5 May 2024 23:32:27 +0800 Subject: [PATCH 09/10] reject more test attributes --- tokio-macros/src/entry.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index 85cf69d090e..f1c39fa6e70 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -443,24 +443,33 @@ pub(crate) fn main(args: TokenStream, item: TokenStream, rt_multi_thread: bool) } } -// Check whether given attribute is `#[test]` or `#[::core::prelude::v1::test]`. +// Check whether given attribute is a test attribute of forms: +// * `#[test]` +// * `#[core::prelude::*::test]` or `#[::core::prelude::*::test]` +// * `#[std::prelude::*::test]` or `#[::std::prelude::*::test]` fn is_test_attribute(attr: &Attribute) -> bool { let path = match &attr.meta { syn::Meta::Path(path) => path, _ => return false, }; - let segments = ["core", "prelude", "v1", "test"]; - if path.leading_colon.is_none() { - return path.segments.len() == 1 - && path.segments[0].arguments.is_none() - && path.segments[0].ident == "test"; - } else if path.segments.len() != segments.len() { + let candidates = [ + ["core", "prelude", "*", "test"], + ["std", "prelude", "*", "test"], + ]; + if path.leading_colon.is_none() + && path.segments.len() == 1 + && path.segments[0].arguments.is_none() + && path.segments[0].ident == "test" + { + return true; + } else if path.segments.len() != candidates[0].len() { return false; } - path.segments - .iter() - .zip(segments) - .all(|(segment, path)| segment.arguments.is_none() && segment.ident == path) + candidates.into_iter().any(|segments| { + path.segments.iter().zip(segments).all(|(segment, path)| { + segment.arguments.is_none() && (path == "*" || segment.ident == path) + }) + }) } pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) -> TokenStream { From 39c9a1dc0db2267d55b48c6a57f35ca612f1c9aa Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Mon, 6 May 2024 00:13:33 +0800 Subject: [PATCH 10/10] add test for test path combinations --- .../tests/fail/macros_invalid_input.rs | 16 +++++++++++ .../tests/fail/macros_invalid_input.stderr | 28 +++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tests-build/tests/fail/macros_invalid_input.rs b/tests-build/tests/fail/macros_invalid_input.rs index b5536b021a7..85b4924f225 100644 --- a/tests-build/tests/fail/macros_invalid_input.rs +++ b/tests-build/tests/fail/macros_invalid_input.rs @@ -45,6 +45,22 @@ async fn test_crate_not_path_invalid() {} #[test] async fn test_has_second_test_attr() {} +#[tokio::test] +#[::core::prelude::v1::test] +async fn test_has_second_test_attr_v1() {} + +#[tokio::test] +#[core::prelude::rust_2015::test] +async fn test_has_second_test_attr_rust_2015() {} + +#[tokio::test] +#[::std::prelude::rust_2018::test] +async fn test_has_second_test_attr_rust_2018() {} + +#[tokio::test] +#[std::prelude::rust_2021::test] +async fn test_has_second_test_attr_rust_2021() {} + #[tokio::test] #[tokio::test] async fn test_has_generated_second_test_attr() {} diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr index e43226f253c..11f95315cdf 100644 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -83,9 +83,33 @@ error: second test attribute is supplied, consider removing or changing the orde | ^^^^^^^ error: second test attribute is supplied, consider removing or changing the order of your test attributes - --> $DIR/macros_invalid_input.rs:48:1 + --> $DIR/macros_invalid_input.rs:49:1 | -48 | #[tokio::test] +49 | #[::core::prelude::v1::test] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: second test attribute is supplied, consider removing or changing the order of your test attributes + --> $DIR/macros_invalid_input.rs:53:1 + | +53 | #[core::prelude::rust_2015::test] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: second test attribute is supplied, consider removing or changing the order of your test attributes + --> $DIR/macros_invalid_input.rs:57:1 + | +57 | #[::std::prelude::rust_2018::test] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: second test attribute is supplied, consider removing or changing the order of your test attributes + --> $DIR/macros_invalid_input.rs:61:1 + | +61 | #[std::prelude::rust_2021::test] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: second test attribute is supplied, consider removing or changing the order of your test attributes + --> $DIR/macros_invalid_input.rs:64:1 + | +64 | #[tokio::test] | ^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `tokio::test` (in Nightly builds, run with -Z macro-backtrace for more info)