-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#[tokio::main] allowing arbitrary return values from main #4635
Comments
Thoughts? @taiki-e |
Good catch! The repro will be expanded to the following: fn main() {
let body = async { return 1; ; };
#[allow(clippy :: expect_used)]
tokio::runtime::Builder::new_multi_thread().enable_all().build().expect("Failed building the Runtime").block_on(body);
} The heuristic to analyze the last expression and emit a semicolon without tokio/tokio-macros/src/entry.rs Lines 386 to 399 in b4d82c3
|
The simplest fix for this is to remove all heuristics introduced in #4067 and relevant subsequent PRs. However, it improved diagnostics, so I'm considering the approach that fixes the problem without regressions on the diagnostics. Probably, using let (tail_return, tail_semicolon) = match body.stmts.last() {
Some(syn::Stmt::Semi(syn::Expr::Return(_), _)) => (quote! { return }, quote! { ; }),
Some(syn::Stmt::Semi(..)) | Some(syn::Stmt::Local(..)) | None => {
match &input.sig.output {
syn::ReturnType::Type(_, ty) if matches!(&**ty, syn::Type::Tuple(ty) if ty.elems.is_empty()) =>
{
- (quote! {}, quote! { ; }) // unit
+ (quote! { let () = }, quote! { ; }) // unit
}
- syn::ReturnType::Default => (quote! {}, quote! { ; }), // unit
+ syn::ReturnType::Default => (quote! { let () = }, quote! { ; }), // unit
syn::ReturnType::Type(..) => (quote! {}, quote! {}), // ! or another
}
}
_ => (quote! {}, quote! {}),
}; |
filed #4636 |
Version
Platform
Linux x86_64
Description
The following code compiles playground link
The following don't compile, as expected
The text was updated successfully, but these errors were encountered: