From b17a4c92c745271dba947412bf14b6e0ece1270f Mon Sep 17 00:00:00 2001 From: jasper Date: Tue, 11 Feb 2025 02:51:15 +0100 Subject: [PATCH] fix: allow non static lifetimes in component macro (#3571) --- leptos_macro/src/component.rs | 4 +--- leptos_macro/tests/component.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/leptos_macro/src/component.rs b/leptos_macro/src/component.rs index 2653f45edb..ecd064a5fc 100644 --- a/leptos_macro/src/component.rs +++ b/leptos_macro/src/component.rs @@ -144,8 +144,6 @@ impl ToTokens for Model { let (impl_generics, generics, where_clause) = body.sig.generics.split_for_impl(); - let lifetimes = body.sig.generics.lifetimes(); - let props_name = format_ident!("{name}Props"); let props_builder_name = format_ident!("{name}PropsBuilder"); let props_serialized_name = format_ident!("{name}PropsSerialized"); @@ -570,7 +568,7 @@ impl ToTokens for Model { #tracing_instrument_attr #vis fn #name #impl_generics ( #props_arg - ) #ret #(+ #lifetimes)* + ) #ret #where_clause { #body diff --git a/leptos_macro/tests/component.rs b/leptos_macro/tests/component.rs index d90dbeeefd..a3b474f99f 100644 --- a/leptos_macro/tests/component.rs +++ b/leptos_macro/tests/component.rs @@ -104,3 +104,18 @@ fn component_nostrip() { /> }; } + +#[component] +fn WithLifetime<'a>(data: &'a str) -> impl IntoView { + _ = data; + "static lifetime" +} + +#[test] +fn returns_static_lifetime() { + #[allow(unused)] + fn can_return_impl_intoview_from_body() -> impl IntoView { + let val = String::from("non_static_lifetime"); + WithLifetime(WithLifetimeProps::builder().data(&val).build()) + } +}