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

Improve code generated by the insertable derive #3228

Merged
merged 2 commits into from
Jul 15, 2022

Conversation

weiznich
Copy link
Member

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

@weiznich weiznich requested a review from a team July 14, 2022 17:15
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.
@weiznich weiznich force-pushed the improve_insertable_error_messages branch from 8019195 to a5ab9a3 Compare July 14, 2022 18:26
Copy link
Contributor

@chusteven chusteven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩 much cleaner

Copy link
Member

@pksunkara pksunkara left a 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 {
Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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.

diesel_derives/src/insertable.rs Outdated Show resolved Hide resolved
@weiznich weiznich merged commit 5c0452e into diesel-rs:master Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants