Rocket

A web framework for Rust. https://rocket.rs (mirror)
git clone git://git.thc420.xyz/Rocket
Log | Files | Refs | README

commit 2d924f0f51bdf8cc9f248a743691a4203f124008
parent e458df094ffa6e4a793a9b8257950a0409f71487
Author: Jeb Rosen <jeb@jebrosen.com>
Date:   Sat, 25 May 2019 16:27:04 -0700

Allow 'non_snake_case' for generated query params.

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

Fixes #1003.

Diffstat:
Mcore/codegen/src/attribute/route.rs | 4++++
Mcore/codegen/tests/route.rs | 9+++++++++
2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/core/codegen/src/attribute/route.rs b/core/codegen/src/attribute/route.rs @@ -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) => { diff --git 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()