Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FromQueryResult proc_macro no longer add TryGetable trait bound to generic types #1603

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}