Fix expansion of sqlx(flatten) (#2023)

Given a generic type like `A<B>` before `sqlx` would produce
`A<B>::from_row(row)` which is invalid syntax.
Now it produces `<A<B> as ::sqlx::FromRow<'a, R>>`.
This also fixes a bug for non-generic types where an inherent method
might have been called instead of the `::sqlx::FromRow::from_row` method
because UFCS wasn't used.
This commit is contained in:
RustyYato 2022-09-02 17:52:05 -07:00 committed by GitHub
parent 04884f1a1a
commit c5f3513f7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,7 +74,7 @@ fn expand_derive_from_row_struct(
let expr: Expr = if attributes.flatten {
predicates.push(parse_quote!(#ty: ::sqlx::FromRow<#lifetime, R>));
parse_quote!(#ty::from_row(row))
parse_quote!(<#ty as ::sqlx::FromRow<#lifetime, R>>::from_row(row))
} else {
predicates.push(parse_quote!(#ty: ::sqlx::decode::Decode<#lifetime, R::Database>));
predicates.push(parse_quote!(#ty: ::sqlx::types::Type<R::Database>));