From 8626cf5ba89f0360a1fe487f07fb8085572bd5ef Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 27 Dec 2019 22:56:10 -0800 Subject: [PATCH] Tweak macro to only accept literals --- examples/realworld-postgres/src/main.rs | 2 +- src/lib.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/realworld-postgres/src/main.rs b/examples/realworld-postgres/src/main.rs index 3768bf2b..5b698b47 100644 --- a/examples/realworld-postgres/src/main.rs +++ b/examples/realworld-postgres/src/main.rs @@ -57,7 +57,7 @@ async fn register(mut req: Request) -> Response { INSERT INTO users ( username, email, password ) VALUES ( $1, $2, $3 ) RETURNING id, username, email - "#, + "#, &*body.username, &*body.email, &*hash, diff --git a/src/lib.rs b/src/lib.rs index add86005..a5475520 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,10 +143,10 @@ macro_rules! query ( // the emitted item for `#[proc_macro_hack]` doesn't look great in docs // plus this might let IDEs hint at the syntax // `#[allow(dead_code)]` to silence the `enum ProcMacroHack` error - ($query:expr) => (#[allow(dead_code)] { + ($query:literal) => (#[allow(dead_code)] { $crate::query_!($query) }); - ($query:expr, $($args:tt)*) => (#[allow(dead_code)]{ + ($query:literal, $($args:tt)*) => (#[allow(dead_code)]{ #![allow(dead_code)] $crate::query_!($query, $($args)*) }) @@ -196,10 +196,10 @@ macro_rules! query ( #[cfg(feature = "macros")] #[macro_export] macro_rules! query_file ( - ($query:expr) => (#[allow(dead_code)]{ + ($query:literal) => (#[allow(dead_code)]{ $crate::query_file_!($query) }); - ($query:expr, $($args:tt)*) => (#[allow(dead_code)]{ + ($query:literal, $($args:tt)*) => (#[allow(dead_code)]{ $crate::query_file_!($query, $($args)*) }) ); @@ -255,10 +255,10 @@ macro_rules! query_file ( #[cfg(feature = "macros")] #[macro_export] macro_rules! query_as ( - ($out_struct:path, $query:expr) => (#[allow(dead_code)] { + ($out_struct:path, $query:literal) => (#[allow(dead_code)] { $crate::query_as_!($out_struct, $query) }); - ($out_struct:path, $query:expr, $($args:tt)*) => (#[allow(dead_code)] { + ($out_struct:path, $query:literal, $($args:tt)*) => (#[allow(dead_code)] { $crate::query_as_!($out_struct, $query, $($args)*) }) ); @@ -298,10 +298,10 @@ macro_rules! query_as ( #[cfg(feature = "macros")] #[macro_export] macro_rules! query_file_as ( - ($out_struct:path, $query:expr) => (#[allow(dead_code)] { + ($out_struct:path, $query:literal) => (#[allow(dead_code)] { $crate::query_file_as_!($out_struct, $query) }); - ($out_struct:path, $query:expr, $($args:tt)*) => (#[allow(dead_code)] { + ($out_struct:path, $query:literal, $($args:tt)*) => (#[allow(dead_code)] { $crate::query_file_as_!($out_struct, $query, $($args)*) }) );