Skip to content

Commit 9876735

Browse files
committed
macros: Disambiguate the built-in #[test] attribute in macro expansion.
`tokio::test` and related macros now use the absolute path `::core::prelude::v1::test` to refer to the built-in `test` macro. This absolute path was introduced in rust-lang/rust#62086.
1 parent 4748b25 commit 9876735

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

tokio-macros/src/entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn parse_knobs(
142142
let header = {
143143
if is_test {
144144
quote! {
145-
#[test]
145+
#[::core::prelude::v1::test]
146146
}
147147
} else {
148148
quote! {}
@@ -334,14 +334,14 @@ pub(crate) mod old {
334334

335335
let result = match runtime {
336336
Runtime::Threaded => quote! {
337-
#[test]
337+
#[::core::prelude::v1::test]
338338
#(#attrs)*
339339
#vis fn #name() #ret {
340340
tokio::runtime::Runtime::new().unwrap().block_on(async { #body })
341341
}
342342
},
343343
Runtime::Basic | Runtime::Auto => quote! {
344-
#[test]
344+
#[::core::prelude::v1::test]
345345
#(#attrs)*
346346
#vis fn #name() #ret {
347347
tokio::runtime::Builder::new()

tokio/tests/macros_test.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use tokio::test;
2+
3+
#[test]
4+
async fn test_macro_can_be_used_via_use() {
5+
tokio::spawn(async {
6+
assert_eq!(1 + 1, 2);
7+
}).await.unwrap();
8+
}
9+
10+
#[tokio::test]
11+
async fn test_macro_is_resilient_to_shadowing() {
12+
tokio::spawn(async {
13+
assert_eq!(1 + 1, 2);
14+
}).await.unwrap();
15+
}

0 commit comments

Comments
 (0)