mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
macros: fix wrong error messages (#4067)
This commit is contained in:
@@ -7,25 +7,11 @@ async fn missing_semicolon_or_return_type() {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn missing_return_type() {
|
async fn missing_return_type() {
|
||||||
/* TODO(taiki-e): one of help messages still wrong
|
|
||||||
help: consider using a semicolon here
|
|
||||||
|
|
|
||||||
16 | return Ok(());;
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn extra_semicolon() -> Result<(), ()> {
|
async fn extra_semicolon() -> Result<(), ()> {
|
||||||
/* TODO(taiki-e): help message still wrong
|
|
||||||
help: try using a variant of the expected enum
|
|
||||||
|
|
|
||||||
29 | Ok(Ok(());)
|
|
||||||
|
|
|
||||||
29 | Err(Ok(());)
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
Ok(());
|
Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,36 +16,23 @@ help: try adding a return type
|
|||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/macros_type_mismatch.rs:16:5
|
--> $DIR/macros_type_mismatch.rs:10:5
|
||||||
|
|
|
|
||||||
16 | return Ok(());
|
9 | async fn missing_return_type() {
|
||||||
|
| - help: try adding a return type: `-> Result<(), _>`
|
||||||
|
10 | return Ok(());
|
||||||
| ^^^^^^^^^^^^^^ expected `()`, found enum `Result`
|
| ^^^^^^^^^^^^^^ expected `()`, found enum `Result`
|
||||||
|
|
|
|
||||||
= note: expected unit type `()`
|
= note: expected unit type `()`
|
||||||
found enum `Result<(), _>`
|
found enum `Result<(), _>`
|
||||||
help: consider using a semicolon here
|
|
||||||
|
|
|
||||||
16 | return Ok(());;
|
|
||||||
| ^
|
|
||||||
help: try adding a return type
|
|
||||||
|
|
|
||||||
9 | async fn missing_return_type() -> Result<(), _> {
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/macros_type_mismatch.rs:29:5
|
--> $DIR/macros_type_mismatch.rs:14:31
|
||||||
|
|
|
|
||||||
20 | async fn extra_semicolon() -> Result<(), ()> {
|
14 | async fn extra_semicolon() -> Result<(), ()> {
|
||||||
| -------------- expected `Result<(), ()>` because of return type
|
| --------------- ^^^^^^^^^^^^^^ expected enum `Result`, found `()`
|
||||||
...
|
| |
|
||||||
29 | Ok(());
|
| implicitly returns `()` as its body has no tail or `return` expression
|
||||||
| ^^^^^^^ expected enum `Result`, found `()`
|
|
||||||
|
|
|
|
||||||
= note: expected enum `Result<(), ()>`
|
= note: expected enum `Result<(), ()>`
|
||||||
found unit type `()`
|
found unit type `()`
|
||||||
help: try using a variant of the expected enum
|
|
||||||
|
|
|
||||||
29 | Ok(Ok(());)
|
|
||||||
|
|
|
||||||
29 | Err(Ok(());)
|
|
||||||
|
|
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ fn compile_fail_full() {
|
|||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
t.pass("tests/pass/forward_args_and_output.rs");
|
t.pass("tests/pass/forward_args_and_output.rs");
|
||||||
|
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
t.pass("tests/pass/macros_main_return.rs");
|
||||||
|
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
t.pass("tests/pass/macros_main_loop.rs");
|
||||||
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
t.compile_fail("tests/fail/macros_invalid_input.rs");
|
t.compile_fail("tests/fail/macros_invalid_input.rs");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#[cfg(feature = "full")]
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_with_semicolon_without_return_type() {
|
||||||
|
#![deny(clippy::semicolon_if_nothing_returned)]
|
||||||
|
|
||||||
|
dbg!(0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
use tests_build::tokio;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), ()> {
|
||||||
|
loop {
|
||||||
|
if !never() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn never() -> bool {
|
||||||
|
std::time::Instant::now() > std::time::Instant::now()
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
use tests_build::tokio;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), ()> {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
@@ -323,15 +323,27 @@ fn parse_knobs(
|
|||||||
|
|
||||||
let body = &input.block;
|
let body = &input.block;
|
||||||
let brace_token = input.block.brace_token;
|
let brace_token = input.block.brace_token;
|
||||||
|
let (tail_return, tail_semicolon) = match body.stmts.last() {
|
||||||
|
Some(syn::Stmt::Semi(expr, _)) => (
|
||||||
|
match expr {
|
||||||
|
syn::Expr::Return(_) => quote! { return },
|
||||||
|
_ => quote! {},
|
||||||
|
},
|
||||||
|
quote! {
|
||||||
|
;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
_ => (quote! {}, quote! {}),
|
||||||
|
};
|
||||||
input.block = syn::parse2(quote_spanned! {last_stmt_end_span=>
|
input.block = syn::parse2(quote_spanned! {last_stmt_end_span=>
|
||||||
{
|
{
|
||||||
let body = async #body;
|
let body = async #body;
|
||||||
#[allow(clippy::expect_used)]
|
#[allow(clippy::expect_used)]
|
||||||
#rt
|
#tail_return #rt
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
.expect("Failed building the Runtime")
|
.expect("Failed building the Runtime")
|
||||||
.block_on(body)
|
.block_on(body)#tail_semicolon
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.expect("Parsing failure");
|
.expect("Parsing failure");
|
||||||
|
|||||||
Reference in New Issue
Block a user