Allow 'non_snake_case' for generated query params.

Also adds '#[deny(non_snake_case)]' to the complete route generation
test for regressions.

Fixes #1003.
This commit is contained in:
Jeb Rosen 2019-05-25 16:27:04 -07:00 committed by Sergio Benitez
parent de076895db
commit b7afade412
2 changed files with 13 additions and 0 deletions

View File

@ -220,9 +220,11 @@ fn query_exprs(route: &Route) -> Option<TokenStream2> {
let decl = match segment.kind {
Kind::Single => quote_spanned! { span =>
#[allow(non_snake_case)]
let mut #ident: Option<#ty> = None;
},
Kind::Multi => quote_spanned! { span =>
#[allow(non_snake_case)]
let mut #trail = #SmallVec::<[#request::FormItem; 8]>::new();
},
Kind::Static => quote!()
@ -253,6 +255,7 @@ fn query_exprs(route: &Route) -> Option<TokenStream2> {
let builder = match segment.kind {
Kind::Single => quote_spanned! { span =>
#[allow(non_snake_case)]
let #ident = match #ident.or_else(<#ty as #request::FromFormValue>::default) {
Some(__v) => __v,
None => {
@ -262,6 +265,7 @@ fn query_exprs(route: &Route) -> Option<TokenStream2> {
};
},
Kind::Multi => quote_spanned! { span =>
#[allow(non_snake_case)]
let #ident = match <#ty as #request::FromQuery>::from_query(#Query(&#trail)) {
Ok(__v) => __v,
Err(__e) => {

View File

@ -1,5 +1,10 @@
#![feature(proc_macro_hygiene, decl_macro)]
// Rocket sometimes generates mangled identifiers that activate the
// non_snake_case lint. We deny the lint in this test to ensure that
// code generation uses #[allow(non_snake_case)] in the appropriate places.
#![deny(non_snake_case)]
#[macro_use] extern crate rocket;
use std::path::PathBuf;
@ -65,6 +70,10 @@ fn post2(
format!("({}) ({})", string, uri.to_string())
}
#[post("/<_unused_param>?<_unused_query>", data="<_unused_data>")]
fn test_unused_params(_unused_param: String, _unused_query: String, _unused_data: Data) {
}
#[test]
fn test_full_route() {
let rocket = rocket::ignite()