From ca777ca61af56c848d59afb0cf5bb3f946b73c59 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 20 Apr 2023 22:34:01 +0800 Subject: [PATCH 1/2] `FromQueryResult` proc_macro no longer add `TryGetable` trait bound to generic types --- .../src/derives/from_query_result.rs | 7 +----- tests/derive_tests.rs | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/sea-orm-macros/src/derives/from_query_result.rs b/sea-orm-macros/src/derives/from_query_result.rs index 765884aaf..0c9dd3b6f 100644 --- a/sea-orm-macros/src/derives/from_query_result.rs +++ b/sea-orm-macros/src/derives/from_query_result.rs @@ -6,7 +6,7 @@ use syn::{ext::IdentExt, parse_quote, Data, DataStruct, Field, Fields, GenericPa pub fn expand_derive_from_query_result( ident: Ident, data: Data, - mut generics: Generics, + generics: Generics, ) -> syn::Result { let fields = match data { Data::Struct(DataStruct { @@ -33,11 +33,6 @@ pub fn expand_derive_from_query_result( }) .collect(); - for param in &mut generics.params { - if let GenericParam::Type(type_param) = param { - type_param.bounds.push(parse_quote!(sea_orm::TryGetable)); - } - } let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); Ok(quote!( diff --git a/tests/derive_tests.rs b/tests/derive_tests.rs index 5e3738ff2..20e49d06b 100644 --- a/tests/derive_tests.rs +++ b/tests/derive_tests.rs @@ -7,26 +7,26 @@ struct SimpleTest { } #[derive(FromQueryResult)] -struct GenericTest { +struct GenericTest { _foo: i32, _bar: T, } #[derive(FromQueryResult)] -struct DoubleGenericTest { +struct DoubleGenericTest { _foo: T, _bar: F, } #[derive(FromQueryResult)] -struct BoundsGenericTest { +struct BoundsGenericTest { _foo: T, } #[derive(FromQueryResult)] struct WhereGenericTest where - T: Copy + Clone + 'static, + T: TryGetable + Copy + Clone + 'static, { _foo: T, } @@ -37,10 +37,22 @@ struct AlreadySpecifiedBoundsGenericTest { } #[derive(FromQueryResult)] -struct MixedGenericTest +struct MixedGenericTest where - F: Copy + Clone + 'static, + F: TryGetable + Copy + Clone + 'static, { _foo: T, _bar: F, } + +trait MyTrait { + type Item: TryGetable; +} + +#[derive(FromQueryResult)] +struct TraitAssociateTypeTest +where + T: MyTrait, +{ + _foo: T::Item, +} From 35ad102144b75e4d3cd4207601ca82a0ebddcc5b Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 20 Apr 2023 22:59:16 +0800 Subject: [PATCH 2/2] clippy --- sea-orm-macros/src/derives/from_query_result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea-orm-macros/src/derives/from_query_result.rs b/sea-orm-macros/src/derives/from_query_result.rs index 0c9dd3b6f..999db62fe 100644 --- a/sea-orm-macros/src/derives/from_query_result.rs +++ b/sea-orm-macros/src/derives/from_query_result.rs @@ -1,6 +1,6 @@ use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote, quote_spanned}; -use syn::{ext::IdentExt, parse_quote, Data, DataStruct, Field, Fields, GenericParam, Generics}; +use syn::{ext::IdentExt, Data, DataStruct, Field, Fields, Generics}; /// Method to derive a [QueryResult](sea_orm::QueryResult) pub fn expand_derive_from_query_result(