mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-03 00:00:05 +02:00
macros: fix type resolution error in #[tokio::main] (#4176)
This commit is contained in:
committed by
Eliza Weisman
parent
c9228bf751
commit
2bf613206a
@@ -12,6 +12,14 @@ async fn missing_return_type() {
|
|||||||
|
|
||||||
#[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
|
||||||
|
|
|
||||||
|
23 | Ok(Ok(());)
|
||||||
|
|
|
||||||
|
23 | Err(Ok(());)
|
||||||
|
|
|
||||||
|
*/
|
||||||
Ok(());
|
Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,12 +27,19 @@ error[E0308]: mismatched types
|
|||||||
found enum `Result<(), _>`
|
found enum `Result<(), _>`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/macros_type_mismatch.rs:14:31
|
--> $DIR/macros_type_mismatch.rs:23:5
|
||||||
|
|
|
|
||||||
14 | async fn extra_semicolon() -> Result<(), ()> {
|
14 | async fn extra_semicolon() -> Result<(), ()> {
|
||||||
| --------------- ^^^^^^^^^^^^^^ expected enum `Result`, found `()`
|
| -------------- expected `Result<(), ()>` because of return type
|
||||||
| |
|
...
|
||||||
| implicitly returns `()` as its body has no tail or `return` expression
|
23 | Ok(());
|
||||||
|
| ^^^^^^^ 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
|
||||||
|
|
|
||||||
|
23 | Ok(Ok(());)
|
||||||
|
|
|
||||||
|
23 | Err(Ok(());)
|
||||||
|
|
|
||||||
|
|||||||
@@ -339,15 +339,17 @@ fn parse_knobs(mut input: syn::ItemFn, is_test: bool, config: FinalConfig) -> To
|
|||||||
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() {
|
let (tail_return, tail_semicolon) = match body.stmts.last() {
|
||||||
Some(syn::Stmt::Semi(expr, _)) => (
|
Some(syn::Stmt::Semi(expr, _)) => match expr {
|
||||||
match expr {
|
syn::Expr::Return(_) => (quote! { return }, quote! { ; }),
|
||||||
syn::Expr::Return(_) => quote! { return },
|
_ => match &input.sig.output {
|
||||||
_ => quote! {},
|
syn::ReturnType::Type(_, ty) if matches!(&**ty, syn::Type::Tuple(ty) if ty.elems.is_empty()) =>
|
||||||
|
{
|
||||||
|
(quote! {}, quote! { ; }) // unit
|
||||||
|
}
|
||||||
|
syn::ReturnType::Default => (quote! {}, quote! { ; }), // unit
|
||||||
|
syn::ReturnType::Type(..) => (quote! {}, quote! {}), // ! or another
|
||||||
},
|
},
|
||||||
quote! {
|
},
|
||||||
;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
_ => (quote! {}, quote! {}),
|
_ => (quote! {}, quote! {}),
|
||||||
};
|
};
|
||||||
input.block = syn::parse2(quote_spanned! {last_stmt_end_span=>
|
input.block = syn::parse2(quote_spanned! {last_stmt_end_span=>
|
||||||
|
|||||||
@@ -30,3 +30,19 @@ fn trait_method() {
|
|||||||
}
|
}
|
||||||
().f()
|
().f()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/tokio-rs/tokio/issues/4175
|
||||||
|
#[tokio::main]
|
||||||
|
pub async fn issue_4175_main_1() -> ! {
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
#[tokio::main]
|
||||||
|
pub async fn issue_4175_main_2() -> std::io::Result<()> {
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
#[tokio::test]
|
||||||
|
pub async fn issue_4175_test() -> std::io::Result<()> {
|
||||||
|
return Ok(());
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user