{"record":{"id":"80d41d2fddebcba1","repo":"yewstack/yew","slug":"break-continue-and-return-in-a-match-arm-c","errorCode":null,"errorMessage":"`break`, `continue`, and `return` in a match arm cannot be followed by HTML as their value. Wrap the arm body in braces, e.g. `_ => { return ::yew::html!(<span/>) }`.","messagePattern":"`break`, `continue`, and `return` in a match arm cannot be followed by HTML as their value\\. Wrap the arm body in braces, e\\.g\\. `_ => (.+?)`\\.","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-macro/src/html_tree/html_match.rs","lineNumber":153,"sourceCode":"            }\n        }\n\n        let comma: Option<Token![,]> = input.parse()?;\n\n        // An unbraced `break`/`continue`/`return` body followed by more tokens\n        // past the optional comma is almost always an attempt to give the\n        // keyword an HTML value, which Rust does not accept as an expression.\n        // Without this check the next-arm parser runs on the trailing `<...>`\n        // and fails inside `Pat::parse` with a misleading \"expected `>`\".\n        if comma.is_none() && !input.is_empty() {\n            if let HtmlMatchArmBody::Unbraced { tree, .. } = &body {\n                if matches!(\n                    &**tree,\n                    super::HtmlTree::Break(_)\n                        | super::HtmlTree::Continue(_)\n                        | super::HtmlTree::Return(_)\n                ) {\n                    return Err(syn::Error::new(\n                        input.span(),\n                        \"`break`, `continue`, and `return` in a match arm cannot be followed by \\\n                         HTML as their value. Wrap the arm body in braces, e.g. `_ => { return \\\n                         ::yew::html!(<span/>) }`.\",\n                    ));\n                }\n            }\n        }\n\n        Ok(HtmlMatchArm {\n            pat,\n            guard,\n            fat_arrow_token,\n            body,\n            comma,\n        })\n    }\n}","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-macro/src/html_tree/html_match.rs#L135-L171","documentation":"Inside a `html!` match arm, `break`/`continue`/`return` are parsed as divergent control-flow trees; if HTML tokens follow such an expression in the same arm, the macro cannot give the arm a value and rejects it (html_match.rs:145-157). The help text shows the fix: wrap the arm body in braces and make the HTML an explicit `html!` call.","triggerScenarios":"An arm body like `None => return fallback() <li/>` — a `return`, `break`, or `continue` expression directly followed by more HTML tokens within the same match arm inside `html!`.","commonSituations":"Early-exit arms while rendering lists or guard clauses ('if none, bail out of the render'), or transplanting plain Rust match code that used `?`/`return` into an `html!` template.","solutions":["Wrap the arm body in braces with an explicit macro call, exactly as the help shows: `_ => { return ::yew::html!(<span/>) }`","Move the early exit out of `html!`: bail or compute in plain Rust before invoking the macro","Give the arm a real value (`None => <em/>`) instead of diverging mid-template"],"exampleFix":"// before\nhtml! {\n    match item {\n        Some(i) => <li>{ i }</li>,\n        None => return empty()\n                 <li/>,\n    }\n}\n\n// after\nhtml! {\n    match item {\n        Some(i) => <li>{ i }</li>,\n        None => { return ::yew::html!(<li/>) },\n    }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap any arm body that starts with `return`/`break`/`continue` in braces with an explicit `html!` call inside","Hoist early exits out of the template: compute or bail in plain Rust before invoking `html!`","Give every arm a renderable value; treat divergence as a code smell inside markup"],"tags":["rust","yew","html-macro","match-expression","control-flow"],"backgroundTag":"match-arm-control-flow","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}