Fix component macro with where clause (#3951)
This commit is contained in:
1 parent
589440b9cb
commit
cbb91d694f
2 files changed
+17
-1
No files matched your search
@@ -225,13 +225,14 @@ impl ComponentBody {
|
|||||||
..
|
..
|
||||||
} = sig;
|
} = sig;
|
||||||
|
|
||||||
|
let where_clause = &generics.where_clause;
|
||||||
let struct_fields = inputs.iter().map(move |f| make_prop_struct_field(f, vis));
|
let struct_fields = inputs.iter().map(move |f| make_prop_struct_field(f, vis));
|
||||||
let struct_ident = Ident::new(&format!("{ident}Props"), ident.span());
|
let struct_ident = Ident::new(&format!("{ident}Props"), ident.span());
|
||||||
|
|
||||||
parse_quote! {
|
parse_quote! {
|
||||||
#[derive(Props, Clone, PartialEq)]
|
#[derive(Props, Clone, PartialEq)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#vis struct #struct_ident #generics {
|
#vis struct #struct_ident #generics #where_clause {
|
||||||
#(#struct_fields),*
|
#(#struct_fields),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
// This test just checks that props compile with generics
|
// This test just checks that props compile with generics
|
||||||
@@ -17,6 +19,9 @@ fn generic_props_compile() {
|
|||||||
TakesCloneManualWhere {
|
TakesCloneManualWhere {
|
||||||
value: "hello world"
|
value: "hello world"
|
||||||
}
|
}
|
||||||
|
GenericFnWhereClause {
|
||||||
|
value: "hello world"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,4 +66,14 @@ fn generic_props_compile() {
|
|||||||
) -> Element {
|
) -> Element {
|
||||||
rsx! {}
|
rsx! {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
fn GenericFnWhereClause<T>(value: T) -> Element
|
||||||
|
where
|
||||||
|
T: Clone + PartialEq + Display + 'static,
|
||||||
|
{
|
||||||
|
rsx! {
|
||||||
|
p { "{value}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user