Skip to content

Commit

Permalink
FromQueryResult proc_macro no longer add TryGetable trait bound t…
Browse files Browse the repository at this point in the history
…o generic types (#1603)

* `FromQueryResult` proc_macro no longer add `TryGetable` trait bound to generic types

* clippy
  • Loading branch information
billy1624 committed Apr 24, 2023
1 parent f2cd67f commit a26449c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
9 changes: 2 additions & 7 deletions sea-orm-macros/src/derives/from_query_result.rs
Original file line number Diff line number Diff line change
@@ -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<TokenStream> {
let fields = match data {
Data::Struct(DataStruct {
Expand All @@ -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!(
Expand Down
24 changes: 18 additions & 6 deletions tests/derive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ struct SimpleTest {
}

#[derive(FromQueryResult)]
struct GenericTest<T> {
struct GenericTest<T: TryGetable> {
_foo: i32,
_bar: T,
}

#[derive(FromQueryResult)]
struct DoubleGenericTest<T, F> {
struct DoubleGenericTest<T: TryGetable, F: TryGetable> {
_foo: T,
_bar: F,
}

#[derive(FromQueryResult)]
struct BoundsGenericTest<T: Copy + Clone + 'static> {
struct BoundsGenericTest<T: TryGetable + Copy + Clone + 'static> {
_foo: T,
}

#[derive(FromQueryResult)]
struct WhereGenericTest<T>
where
T: Copy + Clone + 'static,
T: TryGetable + Copy + Clone + 'static,
{
_foo: T,
}
Expand All @@ -37,10 +37,22 @@ struct AlreadySpecifiedBoundsGenericTest<T: TryGetable> {
}

#[derive(FromQueryResult)]
struct MixedGenericTest<T: Clone, F>
struct MixedGenericTest<T: TryGetable + Clone, F>
where
F: Copy + Clone + 'static,
F: TryGetable + Copy + Clone + 'static,
{
_foo: T,
_bar: F,
}

trait MyTrait {
type Item: TryGetable;
}

#[derive(FromQueryResult)]
struct TraitAssociateTypeTest<T>
where
T: MyTrait,
{
_foo: T::Item,
}

0 comments on commit a26449c

Please sign in to comment.