From ad9c59c2b4c49941d512aa126c07d96a9f7a3281 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 19 Oct 2023 13:23:58 -0500 Subject: [PATCH 1/2] add an readable error when you name a prop key --- packages/core-macro/src/props/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs index c1931e497..1fca9baf7 100644 --- a/packages/core-macro/src/props/mod.rs +++ b/packages/core-macro/src/props/mod.rs @@ -467,7 +467,7 @@ fn type_from_inside_option(ty: &syn::Type, check_option_name: bool) -> Option<&s mod struct_info { use proc_macro2::TokenStream; - use quote::quote; + use quote::{quote, quote_spanned}; use syn::parse::Error; use syn::punctuated::Punctuated; use syn::Expr; @@ -701,6 +701,14 @@ Finally, call `.build()` to create the instance of `{name}`. } pub fn field_impl(&self, field: &FieldInfo) -> Result { + let FieldInfo { + name: field_name, + ty: field_type, + .. + } = field; + if field_name.to_string() == "key" { + return Err(Error::new_spanned(field_name, "Naming a prop `key` is not allowed because the name can conflict with the built in key attribute. See https://dioxuslabs.com/learn/0.4/reference/dynamic_rendering#rendering-lists for more information about keys")); + } let StructInfo { ref builder_name, .. } = *self; @@ -715,11 +723,6 @@ Finally, call `.build()` to create the instance of `{name}`. }); let reconstructing = self.included_fields().map(|f| f.name); - let FieldInfo { - name: field_name, - ty: field_type, - .. - } = field; let mut ty_generics: Vec = self .generics .params From 42eb4b5098c3980171e4690d482d2e7a8021a3ef Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 19 Oct 2023 15:48:06 -0500 Subject: [PATCH 2/2] fix clippy --- packages/core-macro/src/props/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs index 1fca9baf7..605983afc 100644 --- a/packages/core-macro/src/props/mod.rs +++ b/packages/core-macro/src/props/mod.rs @@ -467,7 +467,7 @@ fn type_from_inside_option(ty: &syn::Type, check_option_name: bool) -> Option<&s mod struct_info { use proc_macro2::TokenStream; - use quote::{quote, quote_spanned}; + use quote::quote; use syn::parse::Error; use syn::punctuated::Punctuated; use syn::Expr; @@ -706,7 +706,7 @@ Finally, call `.build()` to create the instance of `{name}`. ty: field_type, .. } = field; - if field_name.to_string() == "key" { + if *field_name == "key" { return Err(Error::new_spanned(field_name, "Naming a prop `key` is not allowed because the name can conflict with the built in key attribute. See https://dioxuslabs.com/learn/0.4/reference/dynamic_rendering#rendering-lists for more information about keys")); } let StructInfo {