DioxusLabs/dioxus · error

cannot use receiver types in server function macro

Error message

cannot use receiver types in server function macro

What it means

The `ServerFnArg` parser rejects `self`/`&self` receiver parameters in `#[server]` functions at compile time. Server functions are free-standing RPCs generated from plain associated functions, so methods with receivers cannot be exposed as server functions.

Solutions

  1. Remove the `self` receiver from the server function; server functions must be free functions or associated functions without a receiver.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/fullstack-macro/src/lib.rs:1800 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/f75a956f80e1f31c. Report an issue: GitHub.

Appendix: source

Thrown at packages/fullstack-macro/src/lib.rs:1800

    /// The type of the server function argument.
    arg: syn::PatType,
}

impl ToTokens for ServerFnArg {
    fn to_tokens(&self, tokens: &mut TokenStream2) {
        let ServerFnArg { arg, .. } = self;
        tokens.extend(quote! {
            #arg
        });
    }
}

impl Parse for ServerFnArg {
    fn parse(input: ParseStream) -> Result<Self> {
        let arg: syn::FnArg = input.parse()?;
        let mut arg = match arg {
            FnArg::Receiver(_) => {
                return Err(syn::Error::new(
                    arg.span(),
                    "cannot use receiver types in server function macro",
                ));
            }
            FnArg::Typed(t) => t,
        };

        fn rename_path(path: Path, from_ident: Ident, to_ident: Ident) -> Path {
            if path.is_ident(&from_ident) {
                Path {
                    leading_colon: None,
                    segments: Punctuated::from_iter([PathSegment {
                        ident: to_ident,
                        arguments: PathArguments::None,
                    }]),
                }
            } else {
                path

View on GitHub (pinned to 24f6a829df)