Skip to content

Commit

Permalink
Type check the return type of the body of async functions (#1293)
Browse files Browse the repository at this point in the history
This nudges the compiler by supplying the expected return type of bodies of `async` functions when `command_attr`'s macros are applied, such as `#[command]` or `#[check]`. This aids the compiler in providing more useful error messages.
  • Loading branch information
arqunis committed Apr 15, 2021
1 parent badb448 commit fa0bdd8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions command_attr/src/lib.rs
Expand Up @@ -226,7 +226,10 @@ pub fn command(attr: TokenStream, input: TokenStream) -> TokenStream {
#visibility fn #name<'fut> (#(#args),*) -> ::serenity::futures::future::BoxFuture<'fut, #ret> {
use ::serenity::futures::future::FutureExt;

async move { #(#body)* }.boxed()
async move {
let output: #ret = { #(#body)* };
output
}.boxed()
}
})
.into()
Expand Down Expand Up @@ -518,7 +521,10 @@ pub fn help(attr: TokenStream, input: TokenStream) -> TokenStream {
pub fn #nn<'fut>(#(#args),*) -> ::serenity::futures::future::BoxFuture<'fut, #ret> {
use ::serenity::futures::future::FutureExt;

async move { #(#body)* }.boxed()
async move {
let output: #ret = { #(#body)* };
output
}.boxed()
}
})
.into()
Expand Down Expand Up @@ -794,7 +800,10 @@ pub fn check(_attr: TokenStream, input: TokenStream) -> TokenStream {
#visibility fn #n<'fut>(#(#args),*) -> ::serenity::futures::future::BoxFuture<'fut, #ret> {
use ::serenity::futures::future::FutureExt;

async move { #(#body)* }.boxed()
async move {
let output: #ret = { #(#body)* };
output
}.boxed()
}
})
.into()
Expand Down Expand Up @@ -929,7 +938,10 @@ pub fn hook(_attr: TokenStream, input: TokenStream) -> TokenStream {
#visibility fn #fun_name<'fut>(#(#args),*) -> ::serenity::futures::future::BoxFuture<'fut, #ret> {
use ::serenity::futures::future::FutureExt;

async move { #(#body)* }.boxed()
async move {
let output: #ret = { #(#body)* };
output
}.boxed()
}
})
.into()
Expand Down

0 comments on commit fa0bdd8

Please sign in to comment.