From 40f936d56a56eed6f945f0ec5f3d2ed8a25dfada Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 22 Jul 2024 22:48:39 +0200 Subject: [PATCH] Fix deriving props with a where clause and an owner (#2674) --- packages/core-macro/src/props/mod.rs | 3 +- packages/core-macro/tests/generics.rs | 64 +++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 packages/core-macro/tests/generics.rs diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs index fda59c7ed..091c71fd8 100644 --- a/packages/core-macro/src/props/mod.rs +++ b/packages/core-macro/src/props/mod.rs @@ -1397,12 +1397,13 @@ Finally, call `.build()` to create the instance of `{name}`. let original_name = &self.name; let vis = &self.vis; let generics_with_bounds = &self.generics; + let where_clause = &self.generics.where_clause; quote! { #[doc(hidden)] #[allow(dead_code, non_camel_case_types, missing_docs)] #[derive(Clone)] - #vis struct #name #generics_with_bounds { + #vis struct #name #generics_with_bounds #where_clause { inner: #original_name #ty_generics, owner: Owner, } diff --git a/packages/core-macro/tests/generics.rs b/packages/core-macro/tests/generics.rs new file mode 100644 index 000000000..c846ba8e0 --- /dev/null +++ b/packages/core-macro/tests/generics.rs @@ -0,0 +1,64 @@ +use dioxus::prelude::*; + +// This test just checks that props compile with generics +// It will not actually run any code +#[test] +#[allow(unused)] +#[allow(non_snake_case)] +fn generic_props_compile() { + fn app() -> Element { + rsx! { + TakesClone { + value: "hello world" + } + TakesCloneManual { + value: "hello world" + } + TakesCloneManualWhere { + value: "hello world" + } + } + } + + #[component] + fn TakesClone(value: T) -> Element { + rsx! {} + } + + #[derive(Props, Clone, PartialEq)] + struct TakesCloneManualProps { + value: T, + } + + fn TakesCloneManual(props: TakesCloneManualProps) -> Element { + rsx! {} + } + + #[derive(Props, Clone, PartialEq)] + struct TakesCloneManualWhereProps + where + T: Clone + PartialEq + 'static, + { + value: T, + } + + fn TakesCloneManualWhere( + props: TakesCloneManualWhereProps, + ) -> Element { + rsx! {} + } + + #[derive(Props, Clone, PartialEq)] + struct TakesCloneManualWhereWithOwnerProps + where + T: Clone + PartialEq + 'static, + { + value: EventHandler, + } + + fn TakesCloneManualWhereWithOwner( + props: TakesCloneManualWhereWithOwnerProps, + ) -> Element { + rsx! {} + } +}