tauri-apps/tauri · error · syn::Error
expected string literal for rename
Error message
expected string literal for rename
What it means
The `rename` attribute on a #[tauri::command] renames a function argument and must be given a string literal value. If the name-value expression is not an ExprLit with a Lit::Str, this syn::Error is raised at compile time.
Solutions
- Pass a plain string literal: rename = "newName"
- If the name must be computed, write the literal directly rather than referencing a const
- Remove rename if the goal was something else and use rename_all for bulk case renaming
Example fix
// before
#[tauri::command(rename_all = "camelCase", rename = MY_NAME)]
fn cmd(MY_NAME: String) {}
// after
#[tauri::command(rename_all = "camelCase", rename = "myName")]
fn cmd(my_name: String) {} Defensive patterns
Strategy: validation
Prevention
- Always pass a string literal to rename = "..."
- Don't reference constants or expressions in rename
- Use rename_all for bulk case conversion and rename for individual arguments
When it happens
Trigger: Writing rename with a non-string or non-literal value, e.g. rename = 42, rename = some_const, or rename without a value (path form).
Common situations: Attempting to rename to a computed/constant identifier; typos omitting the quotes; confusing rename with rename_all and passing multiple values.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- unexpected input, expected one of `rename_all`, `rename`…
- unexpected list input
- expected "camelCase" or "snake_case"
- only named, wildcard, struct, and tuple struct arguments…
- parsed syn::Path has no segment
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/f971c426a1fd5953.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri-macros/src/command/wrapper.rs:87
"snake_case" => ArgumentCase::Snake,
"camelCase" => ArgumentCase::Camel,
_ => {
return Err(syn::Error::new(
s.span(),
"expected \"camelCase\" or \"snake_case\"",
));
}
};
}
} else if v.path.is_ident("rename") {
if let Expr::Lit(ExprLit {
lit: Lit::Str(s), ..
}) = v.value
{
let lit = s.value();
wrapper_attributes.rename = RenamePolicy::Rename(quote!(#lit));
} else {
return Err(syn::Error::new(
v.span(),
"expected string literal for rename",
));
}
} else if v.path.is_ident("root") {
if let Expr::Lit(ExprLit {
lit: Lit::Str(s),
attrs: _,
}) = v.value
{
let lit = s.value();
wrapper_attributes.root = if lit == "crate" {
quote!($crate)
} else {
let ident = Ident::new(&lit, Span::call_site());
quote!(#ident)
};View on GitHub (pinned to 460ec35447)