yewstack/yew · error · syn::Error
unsupported literal
Error message
unsupported literal
What it means
`HtmlNode::parse` classifies each child literal; a token that lexes as a literal but cannot be parsed into a known kind lands in `Lit::Verbatim` and is rejected as 'unsupported literal' (html_node.rs:28-32). Typical inputs are numeric literals with unrecognized suffixes (e.g. `1u0`) — tokens rustc would also reject, but the macro reports them first with a span pinned to the literal itself.
Source
Thrown at packages/yew-macro/src/html_tree/html_node.rs:30
pub enum HtmlNode {
Literal(Box<Lit>),
Expression(Box<Expr>),
}
impl Parse for HtmlNode {
fn parse(input: ParseStream) -> Result<Self> {
let node = if HtmlNode::peek(input.cursor()).is_some() {
let lit = input.parse()?;
match lit {
Lit::ByteStr(lit) => {
return Err(syn::Error::new(
lit.span(),
"byte-strings can't be converted to HTML text
note: remove the `b` prefix or convert this to a `String`",
));
}
Lit::Verbatim(lit) => {
return Err(syn::Error::new(lit.span(), "unsupported literal"));
}
_ => (),
}
HtmlNode::Literal(Box::new(lit))
} else {
HtmlNode::Expression(Box::new(input.parse()?))
};
Ok(node)
}
}
impl PeekValue<()> for HtmlNode {
fn peek(cursor: Cursor) -> Option<()> {
cursor.literal().map(|_| ()).or_else(|| {
let (ident, _) = cursor.ident()?;
match ident.to_string().as_str() {
"true" | "false" => Some(()),View on GitHub (pinned to 0e4a05472f)
Solutions
- Fix the suffix to a valid one (`u8`, `i32`, `f64`, …) or remove it entirely
- If the child is meant to be displayed text, quote it: `{ "1" }`
- If the tokens come from your own macro, emit the number and suffix as separate, valid tokens instead of one malformed literal
Example fix
// before
html! { <p>{ 1u0 }</p> }
// after
html! { <p>{ 1u8 }</p> } Defensive patterns
Strategy: validation
Prevention
- Use only valid primitive suffixes on numeric literals in templates (`u8`, `i32`, `f64`, …) or none at all
- Quote values meant as display text: `{ "1" }` instead of a bare numeric token
- When generating `html!` input from another macro, emit separate well-formed tokens rather than concatenated literal-suffix hybrids
When it happens
Trigger: A child like `html! { 1u0 }` — an integer or float literal whose suffix is not a valid primitive suffix (`u8`, `i32`, `f64`, …), so syn cannot classify it.
Common situations: Typos in literal suffixes (`1u6`, `2.0f64x`), macro-generated code gluing a suffix onto a number, or pasting experimental literal syntax from elsewhere into a template.
Related errors
- byte-strings can't be converted to HTML text note: remove th
- string literals must not contain more than one class (hint:
- expected a valid closing tag for component note: found openi
- missing condition for `if` expression
- this `if` expression has a condition, but no block
AI-assisted analysis of yewstack/yew@0e4a05472f (2026-08-22).
Data as JSON: /api/errors/ddfcebae0bdd8da1.
Report an issue: GitHub.