From 864ec522b81c5bac3c0a2ce24bf67a16dd9fa01b Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 15 Oct 2021 12:59:56 +0800 Subject: [PATCH] Add `#[automatically_derived]` to all derived implementations --- sea-orm-macros/src/derives/active_model.rs | 4 ++++ sea-orm-macros/src/derives/active_model_behavior.rs | 1 + sea-orm-macros/src/derives/column.rs | 4 ++++ sea-orm-macros/src/derives/entity.rs | 4 ++++ sea-orm-macros/src/derives/entity_model.rs | 3 +++ sea-orm-macros/src/derives/from_query_result.rs | 1 + sea-orm-macros/src/derives/into_active_model.rs | 1 + sea-orm-macros/src/derives/model.rs | 2 ++ sea-orm-macros/src/derives/primary_key.rs | 3 +++ sea-orm-macros/src/derives/relation.rs | 1 + 10 files changed, 24 insertions(+) diff --git a/sea-orm-macros/src/derives/active_model.rs b/sea-orm-macros/src/derives/active_model.rs index 85bdcb69..add31f20 100644 --- a/sea-orm-macros/src/derives/active_model.rs +++ b/sea-orm-macros/src/derives/active_model.rs @@ -68,12 +68,14 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result),* } + #[automatically_derived] impl std::default::Default for ActiveModel { fn default() -> Self { ::new() } } + #[automatically_derived] impl std::convert::From<::Model> for ActiveModel { fn from(m: ::Model) -> Self { Self { @@ -82,12 +84,14 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result for ::Model { fn into_active_model(self) -> ActiveModel { self.into() } } + #[automatically_derived] impl sea_orm::ActiveModelTrait for ActiveModel { type Entity = Entity; diff --git a/sea-orm-macros/src/derives/active_model_behavior.rs b/sea-orm-macros/src/derives/active_model_behavior.rs index 6b62b8d8..7ae9d375 100644 --- a/sea-orm-macros/src/derives/active_model_behavior.rs +++ b/sea-orm-macros/src/derives/active_model_behavior.rs @@ -4,6 +4,7 @@ use syn::Data; pub fn expand_derive_active_model_behavior(_ident: Ident, _data: Data) -> syn::Result { Ok(quote!( + #[automatically_derived] impl sea_orm::ActiveModelBehavior for ActiveModel {} )) } diff --git a/sea-orm-macros/src/derives/column.rs b/sea-orm-macros/src/derives/column.rs index 5fc471e9..7446340e 100644 --- a/sea-orm-macros/src/derives/column.rs +++ b/sea-orm-macros/src/derives/column.rs @@ -54,6 +54,7 @@ pub fn impl_default_as_str(ident: &Ident, data: &Data) -> syn::Result &str { match self { @@ -84,6 +85,7 @@ pub fn impl_col_from_str(ident: &Ident, data: &Data) -> syn::Result }); Ok(quote!( + #[automatically_derived] impl std::str::FromStr for #ident { type Err = sea_orm::ColumnFromStrErr; @@ -103,6 +105,7 @@ pub fn expand_derive_column(ident: &Ident, data: &Data) -> syn::Result &str { self.default_as_str() @@ -120,6 +123,7 @@ pub fn expand_derive_custom_column(ident: &Ident, data: &Data) -> syn::Result Option<&str> { #expanded_schema_name @@ -93,6 +94,7 @@ impl DeriveEntity { } = self; quote!( + #[automatically_derived] impl sea_orm::entity::EntityTrait for #ident { type Model = #model_ident; @@ -109,6 +111,7 @@ impl DeriveEntity { let ident = &self.ident; quote!( + #[automatically_derived] impl sea_orm::Iden for #ident { fn unquoted(&self, s: &mut dyn std::fmt::Write) { write!(s, "{}", self.as_str()).unwrap(); @@ -121,6 +124,7 @@ impl DeriveEntity { let ident = &self.ident; quote!( + #[automatically_derived] impl sea_orm::IdenStatic for #ident { fn as_str(&self) -> &str { ::table_name(self) diff --git a/sea-orm-macros/src/derives/entity_model.rs b/sea-orm-macros/src/derives/entity_model.rs index 107af606..3b0dac26 100644 --- a/sea-orm-macros/src/derives/entity_model.rs +++ b/sea-orm-macros/src/derives/entity_model.rs @@ -37,6 +37,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res #[derive(Copy, Clone, Default, Debug, sea_orm::prelude::DeriveEntity)] pub struct Entity; + #[automatically_derived] impl sea_orm::prelude::EntityName for Entity { fn schema_name(&self) -> Option<&str> { #schema_name @@ -273,6 +274,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res #primary_keys } + #[automatically_derived] impl PrimaryKeyTrait for PrimaryKey { type ValueType = #primary_key_types; @@ -290,6 +292,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec) -> syn::Res #columns_enum } + #[automatically_derived] impl sea_orm::prelude::ColumnTrait for Column { type EntityName = Entity; diff --git a/sea-orm-macros/src/derives/from_query_result.rs b/sea-orm-macros/src/derives/from_query_result.rs index ef24c18d..fcef9da3 100644 --- a/sea-orm-macros/src/derives/from_query_result.rs +++ b/sea-orm-macros/src/derives/from_query_result.rs @@ -29,6 +29,7 @@ pub fn expand_derive_from_query_result(ident: Ident, data: Data) -> syn::Result< .collect(); Ok(quote!( + #[automatically_derived] impl sea_orm::FromQueryResult for #ident { fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result { Ok(Self { diff --git a/sea-orm-macros/src/derives/into_active_model.rs b/sea-orm-macros/src/derives/into_active_model.rs index ad080e23..3d95e927 100644 --- a/sea-orm-macros/src/derives/into_active_model.rs +++ b/sea-orm-macros/src/derives/into_active_model.rs @@ -76,6 +76,7 @@ impl IntoActiveModel { }); quote!( + #[automatically_derived] impl sea_orm::IntoActiveModel<#active_model_ident> for #ident { fn into_active_model(self) -> #active_model_ident { #active_model_ident { diff --git a/sea-orm-macros/src/derives/model.rs b/sea-orm-macros/src/derives/model.rs index 29a597b9..85d690f2 100644 --- a/sea-orm-macros/src/derives/model.rs +++ b/sea-orm-macros/src/derives/model.rs @@ -123,6 +123,7 @@ impl DeriveModel { .collect(); quote!( + #[automatically_derived] impl sea_orm::FromQueryResult for #ident { fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result { Ok(Self { @@ -160,6 +161,7 @@ impl DeriveModel { let missing_field_msg = format!("field does not exist on {}", ident); quote!( + #[automatically_derived] impl sea_orm::ModelTrait for #ident { type Entity = #entity_ident; diff --git a/sea-orm-macros/src/derives/primary_key.rs b/sea-orm-macros/src/derives/primary_key.rs index e677e2e6..f699749f 100644 --- a/sea-orm-macros/src/derives/primary_key.rs +++ b/sea-orm-macros/src/derives/primary_key.rs @@ -31,12 +31,14 @@ pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result &str { match self { @@ -45,6 +47,7 @@ pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result, _>>()?; Ok(quote!( + #[automatically_derived] impl sea_orm::entity::RelationTrait for #ident { fn def(&self) -> sea_orm::entity::RelationDef { match self {