From 2d924f0f51bdf8cc9f248a743691a4203f124008 Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Sat, 25 May 2019 16:27:04 -0700 Subject: [PATCH] Allow 'non_snake_case' for generated query params. Also adds '#[deny(non_snake_case)]' to the complete route generation test for regressions. Fixes #1003. --- core/codegen/src/attribute/route.rs | 4 ++++ core/codegen/tests/route.rs | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/core/codegen/src/attribute/route.rs b/core/codegen/src/attribute/route.rs index 6246811a..638ab031 100644 --- a/core/codegen/src/attribute/route.rs +++ b/core/codegen/src/attribute/route.rs @@ -220,9 +220,11 @@ fn query_exprs(route: &Route) -> Option { 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 { 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 { }; }, 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) => { diff --git a/core/codegen/tests/route.rs b/core/codegen/tests/route.rs index 90c86c09..c418e232 100644 --- a/core/codegen/tests/route.rs +++ b/core/codegen/tests/route.rs @@ -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()