diff --git a/core/codegen/src/attribute/route/mod.rs b/core/codegen/src/attribute/route/mod.rs index b162ff5af2..54f2cff087 100644 --- a/core/codegen/src/attribute/route/mod.rs +++ b/core/codegen/src/attribute/route/mod.rs @@ -75,37 +75,39 @@ fn query_decls(route: &Route) -> Option { #[allow(non_snake_case)] Some(quote! { - let mut __e = #_form::Errors::new(); - #(let mut #ident = #init_expr;)* - - for _f in #__req.query_fields() { - let _raw = (_f.name.source().as_str(), _f.value); - let _key = _f.name.key_lossy().as_str(); - match (_raw, _key) { - // Skip static parameters so doesn't see them. - #(((#raw_name, #raw_value), _) => { /* skip */ },)* - #((_, #matcher) => #push_expr,)* - _ => { /* in case we have no trailing, ignore all else */ }, + let (#(#ident),*) = { + let mut __e = #_form::Errors::new(); + #(let mut #ident = #init_expr;)* + + for _f in #__req.query_fields() { + let _raw = (_f.name.source().as_str(), _f.value); + let _key = _f.name.key_lossy().as_str(); + match (_raw, _key) { + // Skip static parameters so doesn't see them. + #(((#raw_name, #raw_value), _) => { /* skip */ },)* + #((_, #matcher) => #push_expr,)* + _ => { /* in case we have no trailing, ignore all else */ }, + } } - } - - #( - let #ident = match #finalize_expr { - #_Ok(_v) => #_Some(_v), - #_Err(_err) => { - __e.extend(_err.with_name(#_form::NameView::new(#name))); - #_None - }, - }; - )* - - if !__e.is_empty() { - #_log::warn_!("Query string failed to match route declaration."); - for _err in __e { #_log::warn_!("{}", _err); } - return #Outcome::Forward(#__data); - } - - #(let #ident = #ident.unwrap();)* + + #( + let #ident = match #finalize_expr { + #_Ok(_v) => #_Some(_v), + #_Err(_err) => { + __e.extend(_err.with_name(#_form::NameView::new(#name))); + #_None + }, + }; + )* + + if !__e.is_empty() { + #_log::warn_!("Query string failed to match route declaration."); + for _err in __e { #_log::warn_!("{}", _err); } + return #Outcome::Forward(#__data); + } + + (#(#ident.unwrap()),*) + }; }) } diff --git a/core/codegen/tests/async-routes.rs b/core/codegen/tests/async-routes.rs index 7354247d5d..3a9ff56416 100644 --- a/core/codegen/tests/async-routes.rs +++ b/core/codegen/tests/async-routes.rs @@ -12,6 +12,12 @@ async fn hello(_origin: &Origin<'_>) -> &'static str { "Hello, world!" } +#[get("/repeated_query?")] +async fn repeated_query(sort: Vec<&str>) -> &str { + noop().await; + sort[0] +} + #[catch(404)] async fn not_found(req: &Request<'_>) -> String { noop().await;