Fix deriving props with a where clause and an owner (#2674)

This commit is contained in:
Evan Almloff 2024-07-22 22:48:39 +02:00 committed by GitHub
parent aa4a395884
commit 40f936d56a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 66 additions and 1 deletions

View file

@ -1397,12 +1397,13 @@ Finally, call `.build()` to create the instance of `{name}`.
let original_name = &self.name; let original_name = &self.name;
let vis = &self.vis; let vis = &self.vis;
let generics_with_bounds = &self.generics; let generics_with_bounds = &self.generics;
let where_clause = &self.generics.where_clause;
quote! { quote! {
#[doc(hidden)] #[doc(hidden)]
#[allow(dead_code, non_camel_case_types, missing_docs)] #[allow(dead_code, non_camel_case_types, missing_docs)]
#[derive(Clone)] #[derive(Clone)]
#vis struct #name #generics_with_bounds { #vis struct #name #generics_with_bounds #where_clause {
inner: #original_name #ty_generics, inner: #original_name #ty_generics,
owner: Owner, owner: Owner,
} }

View file

@ -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<T: Clone + PartialEq + 'static>(value: T) -> Element {
rsx! {}
}
#[derive(Props, Clone, PartialEq)]
struct TakesCloneManualProps<T: Clone + PartialEq + 'static> {
value: T,
}
fn TakesCloneManual<T: Clone + PartialEq>(props: TakesCloneManualProps<T>) -> Element {
rsx! {}
}
#[derive(Props, Clone, PartialEq)]
struct TakesCloneManualWhereProps<T>
where
T: Clone + PartialEq + 'static,
{
value: T,
}
fn TakesCloneManualWhere<T: Clone + PartialEq>(
props: TakesCloneManualWhereProps<T>,
) -> Element {
rsx! {}
}
#[derive(Props, Clone, PartialEq)]
struct TakesCloneManualWhereWithOwnerProps<T>
where
T: Clone + PartialEq + 'static,
{
value: EventHandler<T>,
}
fn TakesCloneManualWhereWithOwner<T: Clone + PartialEq>(
props: TakesCloneManualWhereWithOwnerProps<T>,
) -> Element {
rsx! {}
}
}