From d36b7269261d329dd7d7fcd4d5098f3fca167364 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 12 May 2021 11:17:33 -0300 Subject: [PATCH] fix(macros): collision when command is named `cmd` (#1802) --- .changes/fix-command-named-cmd.md | 5 +++++ core/tauri-macros/src/command/handler.rs | 6 +++--- examples/commands/src-tauri/src/commands.rs | 3 +++ examples/commands/src-tauri/src/main.rs | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changes/fix-command-named-cmd.md diff --git a/.changes/fix-command-named-cmd.md b/.changes/fix-command-named-cmd.md new file mode 100644 index 00000000000..59e50df9011 --- /dev/null +++ b/.changes/fix-command-named-cmd.md @@ -0,0 +1,5 @@ +--- +"tauri-macros": patch +--- + +Fixes a name collision when the command function is named `cmd`. diff --git a/core/tauri-macros/src/command/handler.rs b/core/tauri-macros/src/command/handler.rs index 24e1f164497..ac52a5ad2e9 100644 --- a/core/tauri-macros/src/command/handler.rs +++ b/core/tauri-macros/src/command/handler.rs @@ -52,11 +52,11 @@ impl From for proc_macro::TokenStream { }: Handler, ) -> Self { quote::quote!(move |invoke| { - let cmd = invoke.message.command(); - match cmd { + let __tauri_cmd__ = invoke.message.command(); + match __tauri_cmd__ { #(stringify!(#commands) => #wrappers!(#paths, invoke),)* _ => { - invoke.resolver.reject(format!("command {} not found", cmd)) + invoke.resolver.reject(format!("command {} not found", __tauri_cmd__)) }, } }) diff --git a/examples/commands/src-tauri/src/commands.rs b/examples/commands/src-tauri/src/commands.rs index 6daf0cf6163..a80f0a97036 100644 --- a/examples/commands/src-tauri/src/commands.rs +++ b/examples/commands/src-tauri/src/commands.rs @@ -4,6 +4,9 @@ use tauri::{command, State}; +#[command] +pub fn cmd(_argument: String) {} + #[command] pub fn simple_command(argument: String) { println!("{}", argument); diff --git a/examples/commands/src-tauri/src/main.rs b/examples/commands/src-tauri/src/main.rs index a0af5fd8ab2..3108bdc73cf 100644 --- a/examples/commands/src-tauri/src/main.rs +++ b/examples/commands/src-tauri/src/main.rs @@ -9,6 +9,7 @@ // we move some basic commands to a separate module just to show it works mod commands; +use commands::cmd; use serde::Deserialize; use tauri::{command, Params, State, Window}; @@ -167,6 +168,7 @@ fn main() { force_async_with_result, commands::simple_command, commands::stateful_command, + cmd, async_simple_command, future_simple_command, async_stateful_command,