yewstack/yew · error · syn::Error

missing expression for `match`

Error message

missing expression for `match`

What it means

`HtmlMatch::parse` parses the scrutinee with `Expr::parse_without_eager_brace` (html_match.rs:53); if the result is an empty block `{}`, no expression was actually provided and this error is raised on the scrutinee's span (html_match.rs:56-61). It mirrors the equivalent guards for `if` and `while` inside `html!`.

Source

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

        deprecations: TokenStream,
    },
}

impl PeekValue<()> for HtmlMatch {
    fn peek(cursor: Cursor) -> Option<()> {
        let (ident, _) = cursor.ident()?;
        (ident == "match").then_some(())
    }
}

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() {

View on GitHub (pinned to 0e4a05472f)

Solutions

  1. Put the real expression before the brace body: `match msg { … }`
  2. Bind complex scrutinees to a variable before `html!` and match on that identifier
  3. If there is genuinely nothing to match on, use `if`/`else` instead

Example fix

// before
html! { match {} { _ => <p/> } }

// after
html! { match msg { Msg::Ping => <p/>, _ => <span/> } }
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: `html! { match {} { _ => <p/> } }` — an empty block where the matched expression should be, followed by the arm braces.

Common situations: A placeholder scrutinee left by a snippet, moving the real expression out during refactoring and leaving `{}` behind, or misunderstanding match syntax inside the macro.

Related errors


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