yewstack/yew · error · syn::Error

`match` expression must have at least one arm

Error message

`match` expression must have at least one arm

What it means

`HtmlMatch::parse` collects arms until the brace content is exhausted, then requires at least one arm (html_match.rs:72-80); an empty `{}` body yields this error on the brace span. Plain Rust also requires at least one match arm, but the macro reports it earlier while expanding `html!`, with the span pointing at the empty braces.

Source

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

        }

        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",
            ));
        }

        Ok(HtmlMatch {
            match_token,
            expr,
            _brace: brace,
            arms,
        })
    }
}

impl Parse for HtmlMatchArm {
    fn parse(input: ParseStream) -> syn::Result<Self> {
        let pat = Pat::parse_multi_with_leading_vert(input)?;

View on GitHub (pinned to 0e4a05472f)

Solutions

  1. Add the missing arms, typically ending with a catch-all: `_ => <em/>`
  2. Let exhaustiveness help: list each enum variant; the expanded code is a real `match`, so rustc flags gaps afterward
  3. If the match is unnecessary, replace it with a plain expression child

Example fix

// before
html! { match value {} }

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

Strategy: validation

Prevention

When it happens

Trigger: `html! { match value {} }` — braces present but zero arms inside.

Common situations: Scaffolding a match and not finishing it, deleting all arms during a refactor, or assuming a default arm exists implicitly.

Related errors


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