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

The `#[default_runtime]` macro only applies to item definitions it understands: struct, enum, type alias, or trait (parsed as DeriveInput, ItemTrait, or ItemType). Applying it to any other item (fn, mod, impl, const) makes parsing fail with this compile error.

Solutions

  1. Move the attribute onto a struct, enum, type, or trait definition
  2. Remove the attribute if no type in the file needs the default runtime
  3. If wrapping a function, look for the intended macro instead (e.g. tauri::command)

Example fix

// before
#[default_runtime]
fn init() {}
// after
#[default_runtime]
pub struct App<R: Runtime> { runtime: R }
Defensive patterns

Strategy: validation

Validate before calling

// Only apply #[default_runtime] to type definitions
// quick review checklist: the item under the attribute must start with struct/enum/type/trait

Prevention

When it happens

Trigger: Attaching `#[default_runtime]` to a function, module, impl block, or static instead of a type definition.

Common situations: Placing the attribute on the wrong item by mistake; using editor auto-import/snippets that attach the attribute to the preceding item.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/302d9e0a1311a219. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-macros/src/runtime.rs:27

  DeriveInput, Error, GenericParam, Ident, ItemTrait, ItemType, Token, Type, TypeParam, parse_quote,
};

#[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 460ec35447)