tauri-apps/tauri · error · syn::Error
default_runtime only supports `struct`, `enum`, `type`, or `
Error message
default_runtime only supports `struct`, `enum`, `type`, or `trait` definitions
What it means
#[default_runtime] (tauri-macros, re-exported by tauri; syntax like #[default_runtime(crate::Wry, wry)]) injects a default for the last generic parameter of an item so downstream users can omit the runtime type. The parser tries the input as DeriveInput (struct/enum), then ItemTrait, then ItemType; if all three fail — the item is a fn, impl, module, union, use — it reports 'default_runtime only supports `struct`, `enum`, `type`, or `trait` definitions'.
Source
Thrown at crates/tauri-macros/src/runtime.rs:27
parse_quote, DeriveInput, Error, GenericParam, Ident, ItemTrait, ItemType, Token, Type, TypeParam,
};
#[derive(Clone)]
pub(crate) enum Input {
Derive(DeriveInput),
Trait(ItemTrait),
Type(ItemType),
}
impl Parse for Input {
fn parse(input: ParseStream) -> syn::Result<Self> {
input
.parse::<DeriveInput>()
.map(Self::Derive)
.or_else(|_| input.parse().map(Self::Trait))
.or_else(|_| input.parse().map(Self::Type))
.map_err(|_| {
Error::new(
input.span(),
"default_runtime only supports `struct`, `enum`, `type`, or `trait` definitions",
)
})
}
}
impl Input {
fn last_param_mut(&mut self) -> Option<&mut GenericParam> {
match self {
Input::Derive(d) => d.generics.params.last_mut(),
Input::Trait(t) => t.generics.params.last_mut(),
Input::Type(t) => t.generics.params.last_mut(),
}
}
}
impl ToTokens for Input {View on GitHub (pinned to 52e4b6e71d)
Solutions
- Move the attribute onto the struct/enum definition, trait, or type alias that actually carries the runtime generic
- Ensure that item has at least one generic parameter — the macro defaults the last one and asserts on its presence
- For functions, spell the runtime parameter explicitly instead of relying on the macro
Example fix
// before
#[default_runtime(crate::Wry, wry)]
impl<R: Runtime> App<R> { /* ... */ }
// after - annotate the type that owns the generic
#[default_runtime(crate::Wry, wry)]
struct App<R: Runtime> { /* ... */ } Defensive patterns
Strategy: validation
Prevention
- Apply #[default_runtime(...)] only to struct, enum, type alias, or trait definitions
- Ensure the annotated item has a generic parameter — the last one is defaulted
- Do not expect defaults on functions or impl blocks; specify the runtime explicitly there
When it happens
Trigger: Annotating an impl block, fn, mod, union, or use item with #[default_runtime]; the attribute only makes sense on definitions that own the generic parameter list being defaulted.
Common situations: Trying to get a defaulted runtime on associated functions or impls instead of the type definition; the attribute left behind after refactoring a type into something else; pasting it at the wrong nesting level.
Related errors
- unexpected list input
- expected "camelCase" or "snake_case"
- expected string literal for rename
- unexpected input, expected one of `rename_all`, `rename`, `r
- unable to use self as a command function parameter
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/302d9e0a1311a219.
Report an issue: GitHub.