lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
1.98k stars 132 forks source link

Incorrect expression hygiene results in cryptic errors #382

Closed mattfbacon closed 1 year ago

mattfbacon commented 1 year ago

Consider the following invocation:

html! {
  (1 + 1)
}

This expands to

{
    extern crate alloc;
    extern crate maud;
    let mut __maud_output = alloc::string::String::with_capacity(7usize);
    {
        use ::maud::macro_private::*;
        match ChooseRenderOrDisplay(&1 + 1) { // <- the problem
            x => (&&x)
                .implements_render_or_display()
                .render_to(x.0, &mut __maud_output),
        }
    };
    maud::PreEscaped(__maud_output)
}

Clearly &1 + 1 should have been &(1 + 1).

(Also, the String size hint is wrong.)