From c25a0d300f0bb0ab9fbe1eb6ea5d25b8df4ef85f Mon Sep 17 00:00:00 2001 From: jeb Date: Mon, 24 Sep 2018 23:13:46 -0700 Subject: [PATCH] Construct `rocket_param_` idents from the function arguments instead of the route string. --- codegen/src/decorators/route.rs | 8 ++++--- codegen/tests/run-pass/route_ident_hygiene.rs | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 codegen/tests/run-pass/route_ident_hygiene.rs diff --git a/codegen/src/decorators/route.rs b/codegen/src/decorators/route.rs index 85e03fdc93..fcce67c278 100644 --- a/codegen/src/decorators/route.rs +++ b/codegen/src/decorators/route.rs @@ -142,16 +142,18 @@ impl RouteGenerateExt for RouteParams { let mut declared_set = HashSet::new(); for (i, param) in self.path_params(ecx).enumerate() { declared_set.insert(param.ident().name); - let ty = match self.annotated_fn.find_input(¶m.ident().name) { - Some(arg) => strip_ty_lifetimes(arg.ty.clone()), + let arg = match self.annotated_fn.find_input(¶m.ident().name) { + Some(arg) => arg, None => { self.missing_declared_err(ecx, param.inner()); continue; } }; + let ty = strip_ty_lifetimes(arg.ty.clone()); + let ident = arg.ident().expect("function argument ident").prepend(PARAM_PREFIX); + // Note: the `None` case shouldn't happen if a route is matched. - let ident = param.ident().prepend(PARAM_PREFIX); let expr = match param { Param::Single(_) => quote_expr!(ecx, match __req.get_param_str($i) { Some(s) => <$ty as ::rocket::request::FromParam>::from_param(s), diff --git a/codegen/tests/run-pass/route_ident_hygiene.rs b/codegen/tests/run-pass/route_ident_hygiene.rs new file mode 100644 index 0000000000..f803e3cd7b --- /dev/null +++ b/codegen/tests/run-pass/route_ident_hygiene.rs @@ -0,0 +1,22 @@ +#![feature(plugin)] +#![plugin(rocket_codegen)] + +extern crate rocket; + +#[get("/easy/")] +fn easy(id: i32) -> String { + format!("id: {}", id) +} + +macro_rules! make_handler { + () => { + #[get("/hard/")] + fn hard(id: i32) -> String { + format!("id: {}", id) + } + } +} + +make_handler!(); + +fn main() { }