Workaround 'rustc' bug, compiling more async code.

This commit implements a workaround for an [issue within rustc]. The
problem showed itself when using e.g. a `Vec<&str>` argument in an async
route handler (but not `&str`), which resulted in a "implementation of
`FromForm` is not general enough" error. The workaround itself works by
gathering all invocations of `FromForm`'s methods inside a block without
any `.await` points [ref].

[issue within rustc]: https://github.com/rust-lang/rust/issues/69663
[ref]: https://github.com/rust-lang/rust/issues/57478#issuecomment-501186084
This commit is contained in:
Jakub Dąbek 2021-08-21 19:46:04 +02:00 committed by Sergio Benitez
parent 7a54a1293e
commit 9177b20ff1
2 changed files with 34 additions and 26 deletions

View File

@ -75,6 +75,7 @@ fn query_decls(route: &Route) -> Option<TokenStream> {
#[allow(non_snake_case)]
Some(quote! {
let (#(#ident),*) = {
let mut __e = #_form::Errors::new();
#(let mut #ident = #init_expr;)*
@ -105,7 +106,8 @@ fn query_decls(route: &Route) -> Option<TokenStream> {
return #Outcome::Forward(#__data);
}
#(let #ident = #ident.unwrap();)*
(#(#ident.unwrap()),*)
};
})
}

View File

@ -12,6 +12,12 @@ async fn hello(_origin: &Origin<'_>) -> &'static str {
"Hello, world!"
}
#[get("/repeated_query?<sort>")]
async fn repeated_query(sort: Vec<&str>) -> &str {
noop().await;
sort[0]
}
#[catch(404)]
async fn not_found(req: &Request<'_>) -> String {
noop().await;