leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.97k stars 627 forks source link

Breaking change in view macro between 0.6.10 and 0.6.11 #2541

Closed luxalpa closed 4 months ago

luxalpa commented 5 months ago

Describe the bug

The following code used to work in 0.6.10 but it no longer compiles in 0.6.11:

#[component]
pub fn App() -> impl IntoView {
    view! {
        <ContextMenu entries=&vec![1, 2, 3] />
    }
}

#[component]
pub fn ContextMenu<'a>(entries: &'a [i32]) -> impl IntoView {
   todo!()
}

It fails with:

temporary value is freed at the end of this statement creates a temporary value which is freed while still in use

The issue was introduced in https://github.com/leptos-rs/leptos/commit/36b2f919ddaf6a713375d5581b3b3f4ffd65dc1e#diff-6f48ef5e16ec5da899bcfd306b73e8399beabcbb88d57ab0b1b33d663b2ec179L193

Basically, the macro used to generate code like this:

{ ::leptos::component_view(&ContextMenu, ::leptos::component_props_builder(&ContextMenu).entries(#[allow(unused_braces)] { &vec![1, 2, 3] }).build()) }

and then changed to this:

let props = ::leptos::component_props_builder(&ContextMenu).entries(#[allow(unused_braces)] {
    &vec![1, 2, 3]
});
#[allow(clippy::let_unit_value, clippy::unit_arg)] let props = props.build();
#[allow(unreachable_code)] ::leptos::component_view(#[allow(clippy::needless_borrows_for_generic_args)] &ContextMenu, props)