1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-23 04:52:28 +00:00

emit proper error message for async fn read_all(state: &State)

This commit is contained in:
Dominic 2020-05-04 20:30:15 +02:00
parent 110ef2be7a
commit 3de130e104
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -133,6 +133,11 @@ enum MethodArgumentType
impl MethodArgumentType impl MethodArgumentType
{ {
fn is_state_ref(&self) -> bool
{
matches!(self, Self::StateRef | Self::StateMutRef)
}
fn is_method_arg(&self) -> bool fn is_method_arg(&self) -> bool
{ {
matches!(self, Self::MethodArg(_)) matches!(self, Self::MethodArg(_))
@ -368,6 +373,10 @@ pub fn expand_method(method : Method, mut attrs : AttributeArgs, fun : ItemFn) -
let mut state_block = quote!(); let mut state_block = quote!();
if fun_is_async if fun_is_async
{ {
if let Some(arg) = args.iter().find(|arg| (*arg).ty.is_state_ref())
{
return Err(Error::new(arg.span(), "async fn must not take &State as an argument as State is not Sync"));
}
block = quote!(#block.await); block = quote!(#block.await);
} }
if is_no_content if is_no_content