yewstack/yew · error · syn::Error

this `match` expression has a scrutinee, but no body

Error message

this `match` expression has a scrutinee, but no body

What it means

After parsing the scrutinee, `HtmlMatch::parse` checks `input.is_empty()` (html_match.rs:65-70); if nothing follows the expression, the mandatory brace-delimited body is missing and the error points at the scrutinee span. `match` inside `html!` always requires its `{ arms }` body, unlike expression children which appear without braces.

Source

Thrown at packages/yew-macro/src/html_tree/html_match.rs:63

    }
}

impl Parse for HtmlMatch {
    fn parse(input: ParseStream) -> syn::Result<Self> {
        let match_token = input.parse::<Token![match]>()?;
        let expr = Box::new(input.call(Expr::parse_without_eager_brace)?);

        if let Expr::Block(syn::ExprBlock { block, .. }) = &*expr {
            if block.stmts.is_empty() {
                return Err(syn::Error::new(
                    expr.span(),
                    "missing expression for `match`",
                ));
            }
        }

        if input.is_empty() {
            return Err(syn::Error::new(
                expr.span(),
                "this `match` expression has a scrutinee, but no body",
            ));
        }

        let content;
        let brace = braced!(content in input);

        let mut arms = Vec::new();
        while !content.is_empty() {
            arms.push(content.parse::<HtmlMatchArm>()?);
        }

        if arms.is_empty() {
            return Err(syn::Error::new(
                brace.span.span(),
                "`match` expression must have at least one arm",
            ));

View on GitHub (pinned to 0e4a05472f)

Solutions

  1. Add the brace body with at least one arm: `match value { _ => <p/> }`
  2. Compute the chosen value in plain Rust before the macro and interpolate the result as `{ value }`
  3. Use `if`/`else` for a two-way choice where match arms add nothing

Example fix

// before
html! { match value }

// after
html! { match value { Some(v) => <p>{ v }</p>, None => <em/> } }
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: `html! { match value }` — a scrutinee with end-of-input right after it and no `{ … }` body.

Common situations: Writing `match` like a bare expression child and expecting following siblings to become the body, truncation while editing, or converting a Rust `match` statement into the macro and dropping the braces.

Related errors


AI-assisted analysis of yewstack/yew@0e4a05472f (2026-08-22). Data as JSON: /api/errors/1e3542ad164bb8ce. Report an issue: GitHub.