diff --git a/sea-orm-macros/src/derives/from_query_result.rs b/sea-orm-macros/src/derives/from_query_result.rs index 765884aaf..999db62fe 100644 --- a/sea-orm-macros/src/derives/from_query_result.rs +++ b/sea-orm-macros/src/derives/from_query_result.rs @@ -1,12 +1,12 @@ 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( 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, +}