Skip to content

Commit

Permalink
Fix deriving props with a where clause and an owner (#2674)
Browse files Browse the repository at this point in the history
  • Loading branch information
ealmloff authored Jul 22, 2024
1 parent aa4a395 commit 40f936d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core-macro/src/props/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
64 changes: 64 additions & 0 deletions packages/core-macro/tests/generics.rs
Original file line number Diff line number Diff line change
@@ -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! {}
}
}

0 comments on commit 40f936d

Please sign in to comment.