浏览代码

Fix component macro with where clause (#3951)

Evan Almloff 2 月之前
父节点
当前提交
cbb91d694f
共有 2 个文件被更改,包括 17 次插入1 次删除
  1. 2 1
      packages/core-macro/src/component.rs
  2. 15 0
      packages/core-macro/tests/generics.rs

+ 2 - 1
packages/core-macro/src/component.rs

@@ -225,13 +225,14 @@ impl ComponentBody {
             ..
         } = sig;
 
+        let where_clause = &generics.where_clause;
         let struct_fields = inputs.iter().map(move |f| make_prop_struct_field(f, vis));
         let struct_ident = Ident::new(&format!("{ident}Props"), ident.span());
 
         parse_quote! {
             #[derive(Props, Clone, PartialEq)]
             #[allow(non_camel_case_types)]
-            #vis struct #struct_ident #generics {
+            #vis struct #struct_ident #generics #where_clause {
                 #(#struct_fields),*
             }
         }

+ 15 - 0
packages/core-macro/tests/generics.rs

@@ -1,3 +1,5 @@
+use std::fmt::Display;
+
 use dioxus::prelude::*;
 
 // This test just checks that props compile with generics
@@ -17,6 +19,9 @@ fn generic_props_compile() {
             TakesCloneManualWhere {
                 value: "hello world"
             }
+            GenericFnWhereClause {
+                value: "hello world"
+            }
         }
     }
 
@@ -61,4 +66,14 @@ fn generic_props_compile() {
     ) -> Element {
         rsx! {}
     }
+
+    #[component]
+    fn GenericFnWhereClause<T>(value: T) -> Element
+    where
+        T: Clone + PartialEq + Display + 'static,
+    {
+        rsx! {
+            p { "{value}" }
+        }
+    }
 }