-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improve code generated by the insertable derive #3228
Improve code generated by the insertable derive #3228
Conversation
This commit changes the code generated by the insertable derive in such a way that error messages about field mismatches now point to the fields itself, instead to the derive.
8019195
to
a5ab9a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩 much cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpicks
@@ -87,7 +87,7 @@ pub fn derive(item: DeriveInput) -> TokenStream { | |||
{ | |||
type Values = <(#(#direct_field_ty,)*) as Insertable<#table_name::table>>::Values; | |||
|
|||
fn values(self) -> Self::Values { | |||
fn values(self) -> <(#(#direct_field_ty,)*) as Insertable<#table_name::table>>::Values { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does need to change as otherwise rustc emits for whatever reason 2 error message, where one is pointing to the derive itself, and the other one to the corresponding field.
@@ -105,8 +105,8 @@ pub fn derive(item: DeriveInput) -> TokenStream { | |||
{ | |||
type Values = <(#(#ref_field_ty,)*) as Insertable<#table_name::table>>::Values; | |||
|
|||
fn values(self) -> Self::Values { | |||
(#(#ref_field_assign,)*).values() | |||
fn values(self) -> <(#(#ref_field_ty,)*) as Insertable<#table_name::table>>::Values { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to change.
This commit changes the code generated by the insertable derive in such
a way that error messages about field mismatches now point to the fields
itself, instead to the derive.
See here for the old error message: https://github.com/weiznich/rust-foundation-community-grant/blob/77f131de301a4a113c45db15c66e6247a3e4bee9/test_cases/tests/diesel/bad_insertable_field.stderr