Skip to content

Commit ae1d909

Browse files
jebrosenjensim
authored andcommitted
macros: disambiguate the built-in #[test] attribute in macro expansion (tokio-rs#2503)
`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 33b7cd7 commit ae1d909

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
})
8+
.await
9+
.unwrap();
10+
}
11+
12+
#[tokio::test]
13+
async fn test_macro_is_resilient_to_shadowing() {
14+
tokio::spawn(async {
15+
assert_eq!(1 + 1, 2);
16+
})
17+
.await
18+
.unwrap();
19+
}

0 commit comments

Comments
 (0)