mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
macros: Use more consistent runtime names (#1628)
As discussed in #1620, the attribute names for `#[tokio::main]` and `#[tokio::test]` aren't great. Specifically, they both use `single_thread` and `multi_thread`, as opposed to names that match the runtime names: `current_thread` and `threadpool`. This PR changes the former to the latter. Fixes #1627.
This commit is contained in:
@@ -6,7 +6,7 @@ fn main_is_not_async() {}
|
|||||||
#[tokio::main(foo)]
|
#[tokio::main(foo)]
|
||||||
async fn main_attr_has_unknown_args() {}
|
async fn main_attr_has_unknown_args() {}
|
||||||
|
|
||||||
#[tokio::main(multi_thread::bar)]
|
#[tokio::main(threadpool::bar)]
|
||||||
async fn main_attr_has_path_args() {}
|
async fn main_attr_has_path_args() {}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ error: the async keyword is missing from the function declaration
|
|||||||
4 | fn main_is_not_async() {}
|
4 | fn main_is_not_async() {}
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: Unknown attribute foo is specified; expected `single_thread` or `multi_thread`
|
error: Unknown attribute foo is specified; expected `current_thread` or `threadpool`
|
||||||
--> $DIR/macros_invalid_input.rs:6:15
|
--> $DIR/macros_invalid_input.rs:6:15
|
||||||
|
|
|
|
||||||
6 | #[tokio::main(foo)]
|
6 | #[tokio::main(foo)]
|
||||||
@@ -13,8 +13,8 @@ error: Unknown attribute foo is specified; expected `single_thread` or `multi_th
|
|||||||
error: Must have specified ident
|
error: Must have specified ident
|
||||||
--> $DIR/macros_invalid_input.rs:9:15
|
--> $DIR/macros_invalid_input.rs:9:15
|
||||||
|
|
|
|
||||||
9 | #[tokio::main(multi_thread::bar)]
|
9 | #[tokio::main(threadpool::bar)]
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: the async keyword is missing from the function declaration
|
error: the async keyword is missing from the function declaration
|
||||||
--> $DIR/macros_invalid_input.rs:13:1
|
--> $DIR/macros_invalid_input.rs:13:1
|
||||||
@@ -28,7 +28,7 @@ error: the test function cannot accept arguments
|
|||||||
16 | async fn test_fn_has_args(_x: u8) {}
|
16 | async fn test_fn_has_args(_x: u8) {}
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: Unknown attribute foo is specified; expected `single_thread` or `multi_thread`
|
error: Unknown attribute foo is specified; expected `current_thread` or `threadpool`
|
||||||
--> $DIR/macros_invalid_input.rs:18:15
|
--> $DIR/macros_invalid_input.rs:18:15
|
||||||
|
|
|
|
||||||
18 | #[tokio::test(foo)]
|
18 | #[tokio::test(foo)]
|
||||||
|
|||||||
+12
-12
@@ -28,8 +28,8 @@ enum RuntimeType {
|
|||||||
///
|
///
|
||||||
/// ## Options:
|
/// ## Options:
|
||||||
///
|
///
|
||||||
/// - `single_thread` - Uses `current_thread`.
|
/// - `current_thread` - Uses the `current_thread` runtime.
|
||||||
/// - `multi_thread` - Uses multi-threaded runtime. Used by default.
|
/// - `threadpool` - Uses the multi-threaded `threadpool` runtime. Used by default.
|
||||||
///
|
///
|
||||||
/// ## Function arguments:
|
/// ## Function arguments:
|
||||||
///
|
///
|
||||||
@@ -40,7 +40,7 @@ enum RuntimeType {
|
|||||||
/// ### Select runtime
|
/// ### Select runtime
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #[tokio::main(single_thread)]
|
/// #[tokio::main(current_thread)]
|
||||||
/// async fn main() {
|
/// async fn main() {
|
||||||
/// println!("Hello world");
|
/// println!("Hello world");
|
||||||
/// }
|
/// }
|
||||||
@@ -87,10 +87,10 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
||||||
}
|
}
|
||||||
match ident.unwrap().to_string().to_lowercase().as_str() {
|
match ident.unwrap().to_string().to_lowercase().as_str() {
|
||||||
"multi_thread" => runtime = RuntimeType::Multi,
|
"threadpool" => runtime = RuntimeType::Multi,
|
||||||
"single_thread" => runtime = RuntimeType::Single,
|
"current_thread" => runtime = RuntimeType::Single,
|
||||||
name => {
|
name => {
|
||||||
let msg = format!("Unknown attribute {} is specified; expected `single_thread` or `multi_thread`", name);
|
let msg = format!("Unknown attribute {} is specified; expected `current_thread` or `threadpool`", name);
|
||||||
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,15 +126,15 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
///
|
///
|
||||||
/// ## Options:
|
/// ## Options:
|
||||||
///
|
///
|
||||||
/// - `single_thread` - Uses `current_thread`. Used by default.
|
/// - `current_thread` - Uses the `current_thread` runtime. Used by default.
|
||||||
/// - `multi_thread` - Uses multi-threaded runtime.
|
/// - `threadpool` - Uses multi-threaded runtime.
|
||||||
///
|
///
|
||||||
/// ## Usage
|
/// ## Usage
|
||||||
///
|
///
|
||||||
/// ### Select runtime
|
/// ### Select runtime
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// #[tokio::test(multi_thread)]
|
/// #[tokio::test(threadpool)]
|
||||||
/// async fn my_test() {
|
/// async fn my_test() {
|
||||||
/// assert!(true);
|
/// assert!(true);
|
||||||
/// }
|
/// }
|
||||||
@@ -189,10 +189,10 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
||||||
}
|
}
|
||||||
match ident.unwrap().to_string().to_lowercase().as_str() {
|
match ident.unwrap().to_string().to_lowercase().as_str() {
|
||||||
"multi_thread" => runtime = RuntimeType::Multi,
|
"threadpool" => runtime = RuntimeType::Multi,
|
||||||
"single_thread" => runtime = RuntimeType::Single,
|
"current_thread" => runtime = RuntimeType::Single,
|
||||||
name => {
|
name => {
|
||||||
let msg = format!("Unknown attribute {} is specified; expected `single_thread` or `multi_thread`", name);
|
let msg = format!("Unknown attribute {} is specified; expected `current_thread` or `threadpool`", name);
|
||||||
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
return syn::Error::new_spanned(path, msg).to_compile_error().into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user