From 8522e3607335dbdf5b67a34ecd027cc2032df31b Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 10:48:55 +0200 Subject: [PATCH 01/28] Change span --- diesel_derives/src/as_changeset.rs | 4 ++-- diesel_derives/src/insertable.rs | 8 ++++---- diesel_derives/src/queryable_by_name.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index 44ba64c6cb04..43e5c7d05a79 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -1,4 +1,4 @@ -use proc_macro2::TokenStream; +use proc_macro2::{TokenStream, Span}; use quote::{quote, quote_spanned}; use syn::spanned::Spanned as _; use syn::{parse_quote, DeriveInput, Expr, Path, Result, Type}; @@ -172,7 +172,7 @@ pub fn derive(item: DeriveInput) -> Result { fn field_changeset_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); quote_spanned!(span=> #lifetime #field_ty) } diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index 44af578a38d4..b8fcfcd54517 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -2,7 +2,7 @@ use crate::attrs::AttributeSpanWrapper; use crate::field::Field; use crate::model::Model; use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; -use proc_macro2::TokenStream; +use proc_macro2::{TokenStream, Span}; use quote::quote; use quote::quote_spanned; use syn::parse_quote; @@ -177,7 +177,7 @@ fn derive_into_single_table( fn field_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); quote_spanned!(span=> #lifetime #field_ty) } @@ -193,7 +193,7 @@ fn field_ty_serialize_as( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(ty); @@ -242,7 +242,7 @@ fn field_ty( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(&field.ty); diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index 7848e20ed58c..1a873eaf2fba 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -1,4 +1,4 @@ -use proc_macro2::TokenStream; +use proc_macro2::{TokenStream, Span}; use quote::quote; use syn::{parse_quote, parse_quote_spanned, DeriveInput, Ident, LitStr, Result, Type}; @@ -45,7 +45,7 @@ pub fn derive(item: DeriveInput) -> Result { for field in model.fields() { let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); - let span = field.span; + let span = Span::mixed_site().located_at(field.span); let field_ty = field.ty_for_deserialize(); if field.embed() { where_clause From 5bcad578133a7d73db355e175716146c76352b9b Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 10:54:39 +0200 Subject: [PATCH 02/28] Removes allow unused_qualifications to see if change works --- diesel_derives/src/util.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/diesel_derives/src/util.rs b/diesel_derives/src/util.rs index 3fb06b246435..f780bf37ad65 100644 --- a/diesel_derives/src/util.rs +++ b/diesel_derives/src/util.rs @@ -93,10 +93,8 @@ where } pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream { - // #[allow(unused_qualifications)] can be removed if https://github.com/rust-lang/rust/issues/130277 gets done quote! { #[allow(unused_imports)] - #[allow(unused_qualifications)] const _: () = { // This import is not actually redundant. When using diesel_derives // inside of diesel, `diesel` doesn't exist as an extern crate, and From 8545b0302558cc1670ceedd34d40453fb7c0ace4 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 11:34:24 +0200 Subject: [PATCH 03/28] Testing --- diesel_derives/src/as_changeset.rs | 2 +- diesel_derives/src/insertable.rs | 6 +++--- diesel_derives/src/queryable_by_name.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index 43e5c7d05a79..80cf3cf67201 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -172,7 +172,7 @@ pub fn derive(item: DeriveInput) -> Result { fn field_changeset_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = Span::mixed_site().located_at(field.span); + let span = field.span; quote_spanned!(span=> #lifetime #field_ty) } diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index b8fcfcd54517..a55de8a2514c 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -177,7 +177,7 @@ fn derive_into_single_table( fn field_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = Span::mixed_site().located_at(field.span); + let span = field.span; quote_spanned!(span=> #lifetime #field_ty) } @@ -193,7 +193,7 @@ fn field_ty_serialize_as( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = Span::mixed_site().located_at(field.span); + let span = field.span; if treat_none_as_default_value { let inner_ty = inner_of_option_ty(ty); @@ -242,7 +242,7 @@ fn field_ty( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = Span::mixed_site().located_at(field.span); + let span = field.span; if treat_none_as_default_value { let inner_ty = inner_of_option_ty(&field.ty); diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index 1a873eaf2fba..968d7c3427fc 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -45,7 +45,7 @@ pub fn derive(item: DeriveInput) -> Result { for field in model.fields() { let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); - let span = Span::mixed_site().located_at(field.span); + let span = field.span; let field_ty = field.ty_for_deserialize(); if field.embed() { where_clause From fac96f6e9ea34b616e95369a6a242b7da2f02910 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 11:49:54 +0200 Subject: [PATCH 04/28] Testing seems to positive --- diesel_derives/src/as_changeset.rs | 2 +- diesel_derives/src/insertable.rs | 6 +++--- diesel_derives/src/queryable_by_name.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index 80cf3cf67201..02fbd793c7dc 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -172,7 +172,7 @@ pub fn derive(item: DeriveInput) -> Result { fn field_changeset_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); quote_spanned!(span=> #lifetime #field_ty) } diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index a55de8a2514c..52e355c3d811 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -177,7 +177,7 @@ fn derive_into_single_table( fn field_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); quote_spanned!(span=> #lifetime #field_ty) } @@ -193,7 +193,7 @@ fn field_ty_serialize_as( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(ty); @@ -242,7 +242,7 @@ fn field_ty( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(&field.ty); diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index 968d7c3427fc..b48b566815bd 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -45,7 +45,7 @@ pub fn derive(item: DeriveInput) -> Result { for field in model.fields() { let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); - let span = field.span; + let span = Span::mixed_site().located_at(field.span); let field_ty = field.ty_for_deserialize(); if field.embed() { where_clause From a7b7751924c978655dac12bf94371762f8810017 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 12:07:20 +0200 Subject: [PATCH 05/28] Puts back allow unused_qualifications as per discussion with Ten0 --- diesel_derives/src/util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/diesel_derives/src/util.rs b/diesel_derives/src/util.rs index f780bf37ad65..7d130162db0a 100644 --- a/diesel_derives/src/util.rs +++ b/diesel_derives/src/util.rs @@ -96,6 +96,7 @@ pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream { quote! { #[allow(unused_imports)] const _: () = { + #[allow(unused_qualifications)] // This import is not actually redundant. When using diesel_derives // inside of diesel, `diesel` doesn't exist as an extern crate, and // to work around that it contains a private From 491a00d5bac83f46177d9b3e2f650a053006abac Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 13:56:57 +0200 Subject: [PATCH 06/28] Adds comments to explain the allow --- diesel_derives/src/util.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diesel_derives/src/util.rs b/diesel_derives/src/util.rs index 7d130162db0a..0f25d8465ce4 100644 --- a/diesel_derives/src/util.rs +++ b/diesel_derives/src/util.rs @@ -93,6 +93,8 @@ where } pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream { + // allow(unused_qualifications) is here as it hard to unsure the span is correctly set. Should stay until it is + // checked by CI. See https://github.com/rust-lang/rust/issues/130277 for more details. quote! { #[allow(unused_imports)] const _: () = { From f6cba14f677cafd46acb58263f4ea99a0a099a9a Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 13:59:46 +0200 Subject: [PATCH 07/28] Fix added space in multi replace --- diesel_derives/src/as_changeset.rs | 2 +- diesel_derives/src/insertable.rs | 6 +++--- diesel_derives/src/queryable_by_name.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index 02fbd793c7dc..43e5c7d05a79 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -172,7 +172,7 @@ pub fn derive(item: DeriveInput) -> Result { fn field_changeset_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = Span::mixed_site().located_at(field.span); + let span = Span::mixed_site().located_at(field.span); quote_spanned!(span=> #lifetime #field_ty) } diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index 52e355c3d811..b8fcfcd54517 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -177,7 +177,7 @@ fn derive_into_single_table( fn field_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = Span::mixed_site().located_at(field.span); + let span = Span::mixed_site().located_at(field.span); quote_spanned!(span=> #lifetime #field_ty) } @@ -193,7 +193,7 @@ fn field_ty_serialize_as( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = Span::mixed_site().located_at(field.span); + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(ty); @@ -242,7 +242,7 @@ fn field_ty( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = Span::mixed_site().located_at(field.span); + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(&field.ty); diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index b48b566815bd..1a873eaf2fba 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -45,7 +45,7 @@ pub fn derive(item: DeriveInput) -> Result { for field in model.fields() { let where_clause = generics.where_clause.get_or_insert(parse_quote!(where)); - let span = Span::mixed_site().located_at(field.span); + let span = Span::mixed_site().located_at(field.span); let field_ty = field.ty_for_deserialize(); if field.embed() { where_clause From 1573b6f69e20b1eee7c99a9c0c0f7d15767dafa7 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 14:00:46 +0200 Subject: [PATCH 08/28] come on... --- diesel_derives/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel_derives/src/util.rs b/diesel_derives/src/util.rs index 0f25d8465ce4..51e243a9990b 100644 --- a/diesel_derives/src/util.rs +++ b/diesel_derives/src/util.rs @@ -97,8 +97,8 @@ pub fn wrap_in_dummy_mod(item: TokenStream) -> TokenStream { // checked by CI. See https://github.com/rust-lang/rust/issues/130277 for more details. quote! { #[allow(unused_imports)] + #[allow(unused_qualifications)] const _: () = { - #[allow(unused_qualifications)] // This import is not actually redundant. When using diesel_derives // inside of diesel, `diesel` doesn't exist as an extern crate, and // to work around that it contains a private From 8f624fc9e77043bc9fe24f2dd07300e7eacc9872 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 14:22:40 +0200 Subject: [PATCH 09/28] Orders the imports --- diesel_derives/src/as_changeset.rs | 2 +- diesel_derives/src/insertable.rs | 2 +- diesel_derives/src/queryable_by_name.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index 43e5c7d05a79..a18da437ce27 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -1,4 +1,4 @@ -use proc_macro2::{TokenStream, Span}; +use proc_macro2::{Span, TokenStream}; use quote::{quote, quote_spanned}; use syn::spanned::Spanned as _; use syn::{parse_quote, DeriveInput, Expr, Path, Result, Type}; diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index b8fcfcd54517..16623dce4158 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -2,7 +2,7 @@ use crate::attrs::AttributeSpanWrapper; use crate::field::Field; use crate::model::Model; use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; -use proc_macro2::{TokenStream, Span}; +use proc_macro2::{Span, TokenStream}; use quote::quote; use quote::quote_spanned; use syn::parse_quote; diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index 1a873eaf2fba..27a76715e1e4 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -1,4 +1,4 @@ -use proc_macro2::{TokenStream, Span}; +use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::{parse_quote, parse_quote_spanned, DeriveInput, Ident, LitStr, Result, Type}; From 4fc94ac9c647530de9fa9c07da1bb97fa871af59 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 14:25:00 +0200 Subject: [PATCH 10/28] Trying to see what breaks the tests --- diesel_derives/src/insertable.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index 16623dce4158..02b660f33c7a 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -177,7 +177,7 @@ fn derive_into_single_table( fn field_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = Span::mixed_site().located_at(field.span); + let span = field.span; quote_spanned!(span=> #lifetime #field_ty) } @@ -193,7 +193,7 @@ fn field_ty_serialize_as( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = Span::mixed_site().located_at(field.span); + let span = field.span; if treat_none_as_default_value { let inner_ty = inner_of_option_ty(ty); @@ -242,7 +242,7 @@ fn field_ty( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = Span::mixed_site().located_at(field.span); + let span = field.span; if treat_none_as_default_value { let inner_ty = inner_of_option_ty(&field.ty); From 3cc8e263e31f35975bbe7f82d55cc0c07465a4af Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 14:29:07 +0200 Subject: [PATCH 11/28] dumb-dumb --- diesel_derives/src/insertable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index 02b660f33c7a..44af578a38d4 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -2,7 +2,7 @@ use crate::attrs::AttributeSpanWrapper; use crate::field::Field; use crate::model::Model; use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; -use proc_macro2::{Span, TokenStream}; +use proc_macro2::TokenStream; use quote::quote; use quote::quote_spanned; use syn::parse_quote; From c06a29e1cb8d6524f6d8e3031f4d6392fba6713d Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 15:35:48 +0200 Subject: [PATCH 12/28] Does this work ? --- diesel_derives/src/insertable.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index 44af578a38d4..7d8f514b16d3 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -1,13 +1,14 @@ -use crate::attrs::AttributeSpanWrapper; -use crate::field::Field; -use crate::model::Model; -use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; -use proc_macro2::TokenStream; -use quote::quote; -use quote::quote_spanned; -use syn::parse_quote; -use syn::spanned::Spanned as _; -use syn::{DeriveInput, Expr, Path, Result, Type}; +use { + crate::{ + attrs::AttributeSpanWrapper, + field::Field, + model::Model, + util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}, + }, + proc_macro2::{Span, TokenStream}, + quote::{quote, quote_spanned}, + syn::{parse_quote, spanned::Spanned as _, DeriveInput, Expr, Path, Result, Type}, +}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, true)?; @@ -118,7 +119,10 @@ fn derive_into_single_table( treat_none_as_default_value, )?); - generate_borrowed_insert = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of Insertable for borrowed structs + generate_borrowed_insert = false; // as soon as we hit one field with + // #[diesel(serialize_as)] there is no point in + // generating the impl of Insertable for borrowed + // structs } (Some(AttributeSpanWrapper { attribute_span, .. }), true) => { return Err(syn::Error::new( @@ -177,7 +181,7 @@ fn derive_into_single_table( fn field_ty_embed(field: &Field, lifetime: Option) -> TokenStream { let field_ty = &field.ty; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); quote_spanned!(span=> #lifetime #field_ty) } From 42a6fb99e9439f043e0978784915fbea411f3ff0 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Mon, 16 Sep 2024 15:44:49 +0200 Subject: [PATCH 13/28] How about... this ! --- diesel_derives/src/insertable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index 7d8f514b16d3..a4f7aa9f00ab 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -197,7 +197,7 @@ fn field_ty_serialize_as( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(ty); From f51f54ebdb60e1b87a27ac4942359c37e5f1ab36 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 10:24:30 +0200 Subject: [PATCH 14/28] This should fail --- diesel_derives/src/insertable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index a4f7aa9f00ab..e291f01ab143 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -246,7 +246,7 @@ fn field_ty( treat_none_as_default_value: bool, ) -> Result { let column_name = field.column_name()?.to_ident()?; - let span = field.span; + let span = Span::mixed_site().located_at(field.span); if treat_none_as_default_value { let inner_ty = inner_of_option_ty(&field.ty); From 4a0134ae0cb27e7248c3e3a4ee3ce089fece0e34 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 10:34:14 +0200 Subject: [PATCH 15/28] Better error message --- .../tests/fail/derive/bad_insertable.stderr | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr index da908ef0f94b..b25d68cfaf9c 100644 --- a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr +++ b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr @@ -79,6 +79,9 @@ error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied error[E0277]: the trait bound `std::string::String: diesel::Expression` is not satisfied --> tests/fail/derive/bad_insertable.rs:12:5 | +10 | #[derive(Insertable)] + | ---------- in this derive macro expansion +11 | struct User { 12 | id: String, | ^^ the trait `diesel::Expression` is not implemented for `std::string::String`, which is required by `std::string::String: AsExpression` | @@ -93,10 +96,14 @@ error[E0277]: the trait bound `std::string::String: diesel::Expression` is not s (T0, T1, T2, T3, T4, T5, T6, T7) and $N others = note: required for `std::string::String` to implement `AsExpression` + = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied --> tests/fail/derive/bad_insertable.rs:13:5 | +10 | #[derive(Insertable)] + | ---------- in this derive macro expansion +... 13 | name: i32, | ^^^^ the trait `diesel::Expression` is not implemented for `i32`, which is required by `i32: AsExpression` | @@ -111,10 +118,14 @@ error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied (T0, T1, T2, T3, T4, T5, T6, T7) and $N others = note: required for `i32` to implement `AsExpression` + = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `std::string::String: diesel::Expression` is not satisfied --> tests/fail/derive/bad_insertable.rs:12:5 | +10 | #[derive(Insertable)] + | ---------- in this derive macro expansion +11 | struct User { 12 | id: String, | ^^ the trait `diesel::Expression` is not implemented for `std::string::String`, which is required by `&'insert std::string::String: AsExpression` | @@ -130,10 +141,14 @@ error[E0277]: the trait bound `std::string::String: diesel::Expression` is not s and $N others = note: required for `&'insert std::string::String` to implement `diesel::Expression` = note: required for `&'insert std::string::String` to implement `AsExpression` + = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied --> tests/fail/derive/bad_insertable.rs:13:5 | +10 | #[derive(Insertable)] + | ---------- in this derive macro expansion +... 13 | name: i32, | ^^^^ the trait `diesel::Expression` is not implemented for `i32`, which is required by `&'insert i32: AsExpression` | @@ -149,3 +164,4 @@ error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied and $N others = note: required for `&'insert i32` to implement `diesel::Expression` = note: required for `&'insert i32` to implement `AsExpression` + = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info) \ No newline at end of file From 098ecf4125b421c146aa4c06e6834c2f38d032df Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 10:37:57 +0200 Subject: [PATCH 16/28] Use previous formating --- diesel_derives/src/insertable.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index e291f01ab143..c8ea72bf6216 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -1,14 +1,13 @@ -use { - crate::{ - attrs::AttributeSpanWrapper, - field::Field, - model::Model, - util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}, - }, - proc_macro2::{Span, TokenStream}, - quote::{quote, quote_spanned}, - syn::{parse_quote, spanned::Spanned as _, DeriveInput, Expr, Path, Result, Type}, -}; +use crate::attrs::AttributeSpanWrapper; +use crate::field::Field; +use crate::model::Model; +use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; +use proc_macro2::{Span,TokenStream}; +use quote::quote; +use quote::quote_spanned; +use syn::parse_quote; +use syn::spanned::Spanned as _; +use syn::{DeriveInput, Expr, Path, Result, Type}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, true)?; @@ -119,10 +118,7 @@ fn derive_into_single_table( treat_none_as_default_value, )?); - generate_borrowed_insert = false; // as soon as we hit one field with - // #[diesel(serialize_as)] there is no point in - // generating the impl of Insertable for borrowed - // structs + generate_borrowed_insert = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of Insertable for borrowed structs } (Some(AttributeSpanWrapper { attribute_span, .. }), true) => { return Err(syn::Error::new( From 41021570898113fe6fa4e76ad6b0057ead2eea09 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 10:39:07 +0200 Subject: [PATCH 17/28] Too many spaces --- diesel_derives/src/insertable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index c8ea72bf6216..c561fc5bb5e6 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -118,7 +118,7 @@ fn derive_into_single_table( treat_none_as_default_value, )?); - generate_borrowed_insert = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of Insertable for borrowed structs + generate_borrowed_insert = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of Insertable for borrowed structs } (Some(AttributeSpanWrapper { attribute_span, .. }), true) => { return Err(syn::Error::new( From fe3570ee266aec34480b6dd6dcc5d44ec7881e51 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 10:39:58 +0200 Subject: [PATCH 18/28] formating --- diesel_derives/src/insertable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel_derives/src/insertable.rs b/diesel_derives/src/insertable.rs index c561fc5bb5e6..16623dce4158 100644 --- a/diesel_derives/src/insertable.rs +++ b/diesel_derives/src/insertable.rs @@ -2,7 +2,7 @@ use crate::attrs::AttributeSpanWrapper; use crate::field::Field; use crate::model::Model; use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; -use proc_macro2::{Span,TokenStream}; +use proc_macro2::{Span, TokenStream}; use quote::quote; use quote::quote_spanned; use syn::parse_quote; From 95aaeb1e5349fce92fa43fecc71ea1c7dc612d7d Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 10:53:54 +0200 Subject: [PATCH 19/28] Trying to understand the error formatting wanted --- diesel_compile_tests/tests/fail/derive/bad_insertable.stderr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr index b25d68cfaf9c..79d30b3c80d6 100644 --- a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr +++ b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr @@ -164,4 +164,5 @@ error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied and $N others = note: required for `&'insert i32` to implement `diesel::Expression` = note: required for `&'insert i32` to implement `AsExpression` - = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info) \ No newline at end of file + = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more + info) \ No newline at end of file From 4d918cc5ba4581d524b262dd5e38a39a6f1b1370 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 10:57:54 +0200 Subject: [PATCH 20/28] last change seemed to have no effect --- diesel_compile_tests/tests/fail/derive/bad_insertable.stderr | 1 + 1 file changed, 1 insertion(+) diff --git a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr index 79d30b3c80d6..99c201e5adef 100644 --- a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr +++ b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr @@ -165,4 +165,5 @@ error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied = note: required for `&'insert i32` to implement `diesel::Expression` = note: required for `&'insert i32` to implement `AsExpression` = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more + info) \ No newline at end of file From 6a97ede8ed52170e98b3ce8fb10d6a4c084ffe15 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Tue, 17 Sep 2024 11:01:42 +0200 Subject: [PATCH 21/28] trial and error, but mostly error --- diesel_compile_tests/tests/fail/derive/bad_insertable.stderr | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr index 99c201e5adef..34d625522c72 100644 --- a/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr +++ b/diesel_compile_tests/tests/fail/derive/bad_insertable.stderr @@ -164,6 +164,4 @@ error[E0277]: the trait bound `i32: diesel::Expression` is not satisfied and $N others = note: required for `&'insert i32` to implement `diesel::Expression` = note: required for `&'insert i32` to implement `AsExpression` - = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more - - info) \ No newline at end of file + = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info) From b9fcc6b2ad8d0b4fbeb3ada2831f22a71fe67ab7 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Wed, 18 Sep 2024 17:27:41 +0200 Subject: [PATCH 22/28] Tried to put mixed_span everywhere --- diesel_derives/src/field.rs | 11 ++++++----- diesel_derives/src/queryable_by_name.rs | 20 ++++++++++++-------- diesel_derives/src/selectable.rs | 16 +++++++--------- diesel_derives/src/table.rs | 8 ++++---- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/diesel_derives/src/field.rs b/diesel_derives/src/field.rs index 492bc9f5cfcb..f5f8c192483b 100644 --- a/diesel_derives/src/field.rs +++ b/diesel_derives/src/field.rs @@ -1,6 +1,7 @@ -use proc_macro2::{Span, TokenStream}; -use syn::spanned::Spanned; -use syn::{Expr, Field as SynField, Ident, Index, Result, Type}; +use { + proc_macro2::{Span, TokenStream}, + syn::{spanned::Spanned, Expr, Field as SynField, Ident, Index, Result, Type}, +}; use crate::attrs::{parse_attributes, AttributeSpanWrapper, FieldAttr, SqlIdentifier}; @@ -119,10 +120,10 @@ impl Field { None => FieldName::Unnamed(index.into()), }; - let span = match name { + let span = Span::mixed_site().located_at(match name { FieldName::Named(ref ident) => ident.span(), FieldName::Unnamed(_) => ty.span(), - }; + }); Ok(Self { ty: ty.clone(), diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index 27a76715e1e4..3bfdb340442c 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -1,11 +1,15 @@ -use proc_macro2::{Span, TokenStream}; -use quote::quote; -use syn::{parse_quote, parse_quote_spanned, DeriveInput, Ident, LitStr, Result, Type}; +use { + proc_macro2::{Span, TokenStream}, + quote::quote, + syn::{parse_quote, parse_quote_spanned, DeriveInput, Ident, LitStr, Result, Type}, +}; -use crate::attrs::AttributeSpanWrapper; -use crate::field::{Field, FieldName}; -use crate::model::Model; -use crate::util::wrap_in_dummy_mod; +use crate::{ + attrs::AttributeSpanWrapper, + field::{Field, FieldName}, + model::Model, + util::wrap_in_dummy_mod, +}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, false)?; @@ -63,7 +67,7 @@ pub fn derive(item: DeriveInput) -> Result { let field_check_bound = model.fields().iter().filter(|f| !f.embed()).flat_map(|f| { backends.iter().map(move |b| { let field_ty = f.ty_for_deserialize(); - let span = f.span; + let span = Span::mixed_site().located_at(f.span); let ty = sql_type(f, model).unwrap(); quote::quote_spanned! {span => #field_ty: diesel::deserialize::FromSqlRow<#ty, #b> diff --git a/diesel_derives/src/selectable.rs b/diesel_derives/src/selectable.rs index 7f85863b1121..22bf04057aff 100644 --- a/diesel_derives/src/selectable.rs +++ b/diesel_derives/src/selectable.rs @@ -1,12 +1,10 @@ -use proc_macro2::TokenStream; -use quote::quote; -use syn::spanned::Spanned; -use syn::DeriveInput; -use syn::{parse_quote, Result}; +use { + proc_macro2::{Span, TokenStream}, + quote::quote, + syn::{parse_quote, spanned::Spanned, DeriveInput, Result}, +}; -use crate::field::Field; -use crate::model::Model; -use crate::util::wrap_in_dummy_mod; +use crate::{field::Field, model::Model, util::wrap_in_dummy_mod}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, false)?; @@ -51,7 +49,7 @@ pub fn derive(item: DeriveInput) -> Result { .filter(|(f, _)| !f.embed()) .flat_map(|(f, ty)| { backends.iter().map(move |b| { - let span = f.ty.span(); + let span = Span::mixed_site().located_at(f.ty.span()); let field_ty = to_field_ty_bound(f.ty_for_deserialize())?; Ok(syn::parse_quote_spanned! {span => #field_ty: diesel::deserialize::FromSqlRow, #b> diff --git a/diesel_derives/src/table.rs b/diesel_derives/src/table.rs index 90ee6d161290..9a46b84bbea1 100644 --- a/diesel_derives/src/table.rs +++ b/diesel_derives/src/table.rs @@ -1,5 +1,5 @@ use diesel_table_macro_syntax::{ColumnDef, TableDecl}; -use proc_macro2::TokenStream; +use proc_macro2::{Span, TokenStream}; use syn::parse_quote; use syn::Ident; @@ -76,7 +76,7 @@ pub(crate) fn expand(input: TableDecl) -> TokenStream { } message += "\t}\n}"; - let span = input.table_name.span(); + let span = Span::mixed_site().located_at(input.table_name.span()); return quote::quote_spanned! {span=> compile_error!(#message); }; @@ -129,7 +129,7 @@ pub(crate) fn expand(input: TableDecl) -> TokenStream { let reexport_column_from_dsl = input.column_defs.iter().map(|c| { let column_name = &c.column_name; if c.column_name == *table_name { - let span = c.column_name.span(); + let span = Span::mixed_site().located_at(c.column_name.span()); let message = format!( "Column `{column_name}` cannot be named the same as it's table.\n\ You may use `#[sql_name = \"{column_name}\"]` to reference the table's \ @@ -684,7 +684,7 @@ fn generate_op_impl(op: &str, tpe: &syn::Ident) -> TokenStream { fn expand_column_def(column_def: &ColumnDef) -> TokenStream { // TODO get a better span here as soon as that's // possible using stable rust - let span = column_def.column_name.span(); + let span = Span::mixed_site().located_at(column_def.column_name.span()); let meta = &column_def.meta; let column_name = &column_def.column_name; let sql_name = &column_def.sql_name; From 57c2db28b087e5bcca7ecc0a66fd32e44cef22ea Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Fri, 4 Oct 2024 11:04:09 +0200 Subject: [PATCH 23/28] updating queryable --- diesel_derives/src/queryable.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/diesel_derives/src/queryable.rs b/diesel_derives/src/queryable.rs index 72903241dedf..858ca9753edd 100644 --- a/diesel_derives/src/queryable.rs +++ b/diesel_derives/src/queryable.rs @@ -1,10 +1,10 @@ -use proc_macro2::{Span, TokenStream}; -use quote::quote; -use syn::{parse_quote, DeriveInput, Ident, Index, Result}; +use { + proc_macro2::{Span, TokenStream}, + quote::quote, + syn::{parse_quote, DeriveInput, Ident, Index, Result}, +}; -use crate::field::Field; -use crate::model::Model; -use crate::util::wrap_in_dummy_mod; +use crate::{field::Field, model::Model, util::wrap_in_dummy_mod}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, true)?; @@ -22,7 +22,7 @@ pub fn derive(item: DeriveInput) -> Result { }); let sql_type = &(0..model.fields().len()) .map(|i| { - let i = Ident::new(&format!("__ST{i}"), Span::call_site()); + let i = Ident::new(&format!("__ST{i}"), Span::mixed_site()); quote!(#i) }) .collect::>(); @@ -33,7 +33,7 @@ pub fn derive(item: DeriveInput) -> Result { .params .push(parse_quote!(__DB: diesel::backend::Backend)); for id in 0..model.fields().len() { - let ident = Ident::new(&format!("__ST{id}"), Span::call_site()); + let ident = Ident::new(&format!("__ST{id}"), Span::mixed_site()); generics.params.push(parse_quote!(#ident)); } { From 9269b2a7d6d33680c95f8e3781da65b75ea3a170 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Fri, 4 Oct 2024 11:12:11 +0200 Subject: [PATCH 24/28] wip --- diesel_derives/src/as_changeset.rs | 26 ++++++++++++++++---------- diesel_derives/src/as_expression.rs | 18 ++++++++++-------- diesel_derives/src/associations.rs | 2 +- diesel_derives/src/model.rs | 4 ++-- diesel_derives/src/sql_type.rs | 4 ++-- diesel_derives/src/table.rs | 12 ++++++------ diesel_derives/src/util.rs | 4 ++-- dsl_auto_type/src/auto_type/mod.rs | 2 +- 8 files changed, 40 insertions(+), 32 deletions(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index a18da437ce27..7f2dc806a6cb 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -1,12 +1,15 @@ -use proc_macro2::{Span, TokenStream}; -use quote::{quote, quote_spanned}; -use syn::spanned::Spanned as _; -use syn::{parse_quote, DeriveInput, Expr, Path, Result, Type}; +use { + proc_macro2::{Span, TokenStream}, + quote::{quote, quote_spanned}, + syn::{parse_quote, spanned::Spanned as _, DeriveInput, Expr, Path, Result, Type}, +}; -use crate::attrs::AttributeSpanWrapper; -use crate::field::Field; -use crate::model::Model; -use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; +use crate::{ + attrs::AttributeSpanWrapper, + field::Field, + model::Model, + util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}, +}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, false)?; @@ -27,7 +30,7 @@ pub fn derive(item: DeriveInput) -> Result { if fields_for_update.is_empty() { return Err(syn::Error::new( - proc_macro2::Span::call_site(), + proc_macro2::Span::mixed_site(), "Deriving `AsChangeset` on a structure that only contains primary keys isn't supported.\n\ help: If you want to change the primary key of a row, you should do so with `.set(table::id.eq(new_id))`.\n\ note: `#[derive(AsChangeset)]` never changes the primary key of a row." @@ -83,7 +86,10 @@ pub fn derive(item: DeriveInput) -> Result { treat_none_as_null, )?); - generate_borrowed_changeset = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of AsChangeset for borrowed structs + generate_borrowed_changeset = false; // as soon as we hit one field with + // #[diesel(serialize_as)] there is no point in + // generating the impl of AsChangeset for + // borrowed structs } (Some(AttributeSpanWrapper { attribute_span, .. }), true) => { return Err(syn::Error::new( diff --git a/diesel_derives/src/as_expression.rs b/diesel_derives/src/as_expression.rs index 19f133416dab..bbebe551dd05 100644 --- a/diesel_derives/src/as_expression.rs +++ b/diesel_derives/src/as_expression.rs @@ -1,18 +1,20 @@ -use proc_macro2::TokenStream; -use quote::quote; -use syn::parse_quote; -use syn::DeriveInput; -use syn::Result; +use { + proc_macro2::TokenStream, + quote::quote, + syn::{parse_quote, DeriveInput, Result}, +}; -use crate::model::Model; -use crate::util::{ty_for_foreign_derive, wrap_in_dummy_mod}; +use crate::{ + model::Model, + util::{ty_for_foreign_derive, wrap_in_dummy_mod}, +}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, true, false)?; if model.sql_types.is_empty() { return Err(syn::Error::new( - proc_macro2::Span::call_site(), + proc_macro2::Span::mixed_site(), "At least one `sql_type` is needed for deriving `AsExpression` on a structure.", )); } diff --git a/diesel_derives/src/associations.rs b/diesel_derives/src/associations.rs index 6dd7d00b9f8a..65be4cf481b9 100644 --- a/diesel_derives/src/associations.rs +++ b/diesel_derives/src/associations.rs @@ -13,7 +13,7 @@ pub fn derive(item: DeriveInput) -> Result { if model.belongs_to.is_empty() { return Err(syn::Error::new( - proc_macro2::Span::call_site(), + proc_macro2::Span::mixed_site(), "At least one `belongs_to` is needed for deriving `Associations` on a structure.", )); } diff --git a/diesel_derives/src/model.rs b/diesel_derives/src/model.rs index d6f72520faef..6820741ada8f 100644 --- a/diesel_derives/src/model.rs +++ b/diesel_derives/src/model.rs @@ -52,7 +52,7 @@ impl Model { }) => Some(unnamed), _ if !allow_unit_structs => { return Err(syn::Error::new( - proc_macro2::Span::call_site(), + proc_macro2::Span::mixed_site(), "This derive can only be used on non-unit structs", )); } @@ -60,7 +60,7 @@ impl Model { }; let mut table_names = vec![]; - let mut primary_key_names = vec![Ident::new("id", Span::call_site())]; + let mut primary_key_names = vec![Ident::new("id", Span::mixed_site())]; let mut treat_none_as_default_value = None; let mut treat_none_as_null = None; let mut belongs_to = vec![]; diff --git a/diesel_derives/src/sql_type.rs b/diesel_derives/src/sql_type.rs index 2e6f00d65464..e7a4e132383f 100644 --- a/diesel_derives/src/sql_type.rs +++ b/diesel_derives/src/sql_type.rs @@ -41,7 +41,7 @@ fn sqlite_tokens(item: &DeriveInput, model: &Model) -> Option { model .sqlite_type .as_ref() - .map(|sqlite_type| Ident::new(&sqlite_type.name.value(), Span::call_site())) + .map(|sqlite_type| Ident::new(&sqlite_type.name.value(), Span::mixed_site())) .and_then(|ty| { if cfg!(not(feature = "sqlite")) { return None; @@ -67,7 +67,7 @@ fn mysql_tokens(item: &DeriveInput, model: &Model) -> Option { model .mysql_type .as_ref() - .map(|mysql_type| Ident::new(&mysql_type.name.value(), Span::call_site())) + .map(|mysql_type| Ident::new(&mysql_type.name.value(), Span::mixed_site())) .and_then(|ty| { if cfg!(not(feature = "mysql")) { return None; diff --git a/diesel_derives/src/table.rs b/diesel_derives/src/table.rs index 9a46b84bbea1..c89dcce06b48 100644 --- a/diesel_derives/src/table.rs +++ b/diesel_derives/src/table.rs @@ -46,10 +46,10 @@ pub(crate) fn expand(input: TableDecl) -> TokenStream { let primary_key: TokenStream = match input.primary_keys.as_ref() { None if column_names.contains(&&syn::Ident::new( DEFAULT_PRIMARY_KEY_NAME, - proc_macro2::Span::call_site(), + proc_macro2::Span::mixed_site(), )) => { - let id = syn::Ident::new(DEFAULT_PRIMARY_KEY_NAME, proc_macro2::Span::call_site()); + let id = syn::Ident::new(DEFAULT_PRIMARY_KEY_NAME, proc_macro2::Span::mixed_site()); parse_quote! { #id } @@ -527,15 +527,15 @@ fn generate_valid_grouping_for_table_columns(table: &TableDecl) -> Vec Result Data::Struct(ref body) => match body.fields.iter().next() { Some(field) => Ok(field.ty.clone()), None => Err(syn::Error::new( - proc_macro2::Span::call_site(), + proc_macro2::Span::mixed_site(), "foreign_derive requires at least one field", )), }, _ => Err(syn::Error::new( - proc_macro2::Span::call_site(), + proc_macro2::Span::mixed_site(), "foreign_derive can only be used with structs", )), } diff --git a/dsl_auto_type/src/auto_type/mod.rs b/dsl_auto_type/src/auto_type/mod.rs index 0cc8a20384cb..098bdc4452e9 100644 --- a/dsl_auto_type/src/auto_type/mod.rs +++ b/dsl_auto_type/src/auto_type/mod.rs @@ -66,7 +66,7 @@ pub(crate) fn auto_type_impl( (false, true, _) => false, (true, true, _) => { return Err(syn::Error::new( - Span::call_site(), + Span::mixed_site(), "type_alias and no_type_alias are mutually exclusive", ) .into()) From d0b565839e395f16f4d618031c520f6ac4c3a654 Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Fri, 4 Oct 2024 11:17:25 +0200 Subject: [PATCH 25/28] fix auto formatting --- diesel_derives/src/as_changeset.rs | 25 ++++++++++--------------- diesel_derives/src/as_expression.rs | 18 ++++++++---------- diesel_derives/src/field.rs | 7 +++---- diesel_derives/src/queryable.rs | 12 ++++++------ diesel_derives/src/queryable_by_name.rs | 18 +++++++----------- diesel_derives/src/selectable.rs | 15 +++++++++------ 6 files changed, 43 insertions(+), 52 deletions(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index 7f2dc806a6cb..d29d5d1d7930 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -1,14 +1,12 @@ -use { - proc_macro2::{Span, TokenStream}, - quote::{quote, quote_spanned}, - syn::{parse_quote, spanned::Spanned as _, DeriveInput, Expr, Path, Result, Type}, -}; - -use crate::{ - attrs::AttributeSpanWrapper, - field::Field, - model::Model, - util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}, +use proc_macro2::{Span, TokenStream}; +use quote::{quote, quote_spanned}; +use syn::spanned::Spanned as _; +use syn::{parse_quote, DeriveInput, Expr, Path, Result, Type}; + +use crate::attrs::AttributeSpanWrapper; +use crate::field::Field; +use crate::model::Model; +use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; }; pub fn derive(item: DeriveInput) -> Result { @@ -86,10 +84,7 @@ pub fn derive(item: DeriveInput) -> Result { treat_none_as_null, )?); - generate_borrowed_changeset = false; // as soon as we hit one field with - // #[diesel(serialize_as)] there is no point in - // generating the impl of AsChangeset for - // borrowed structs + generate_borrowed_changeset = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of AsChangeset for borrowed structs } (Some(AttributeSpanWrapper { attribute_span, .. }), true) => { return Err(syn::Error::new( diff --git a/diesel_derives/src/as_expression.rs b/diesel_derives/src/as_expression.rs index bbebe551dd05..892392123245 100644 --- a/diesel_derives/src/as_expression.rs +++ b/diesel_derives/src/as_expression.rs @@ -1,13 +1,11 @@ -use { - proc_macro2::TokenStream, - quote::quote, - syn::{parse_quote, DeriveInput, Result}, -}; - -use crate::{ - model::Model, - util::{ty_for_foreign_derive, wrap_in_dummy_mod}, -}; +use proc_macro2::{Span, TokenStream}; +use quote::quote; +use syn::parse_quote; +use syn::DeriveInput; +use syn::Result; + +use crate::model::Model; +use crate::util::{ty_for_foreign_derive, wrap_in_dummy_mod}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, true, false)?; diff --git a/diesel_derives/src/field.rs b/diesel_derives/src/field.rs index f5f8c192483b..a3cf11f909e2 100644 --- a/diesel_derives/src/field.rs +++ b/diesel_derives/src/field.rs @@ -1,7 +1,6 @@ -use { - proc_macro2::{Span, TokenStream}, - syn::{spanned::Spanned, Expr, Field as SynField, Ident, Index, Result, Type}, -}; +use proc_macro2::{Span, TokenStream}; +use syn::spanned::Spanned; +use syn::{Expr, Field as SynField, Ident, Index, Result, Type}; use crate::attrs::{parse_attributes, AttributeSpanWrapper, FieldAttr, SqlIdentifier}; diff --git a/diesel_derives/src/queryable.rs b/diesel_derives/src/queryable.rs index 858ca9753edd..f8312854272a 100644 --- a/diesel_derives/src/queryable.rs +++ b/diesel_derives/src/queryable.rs @@ -1,10 +1,10 @@ -use { - proc_macro2::{Span, TokenStream}, - quote::quote, - syn::{parse_quote, DeriveInput, Ident, Index, Result}, -}; +use proc_macro2::{Span, TokenStream}; +use quote::quote; +use syn::{parse_quote, DeriveInput, Ident, Index, Result}; -use crate::{field::Field, model::Model, util::wrap_in_dummy_mod}; +use crate::field::Field; +use crate::model::Model; +use crate::util::wrap_in_dummy_mod; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, true)?; diff --git a/diesel_derives/src/queryable_by_name.rs b/diesel_derives/src/queryable_by_name.rs index 3bfdb340442c..8eddd6bf2e51 100644 --- a/diesel_derives/src/queryable_by_name.rs +++ b/diesel_derives/src/queryable_by_name.rs @@ -1,15 +1,11 @@ -use { - proc_macro2::{Span, TokenStream}, - quote::quote, - syn::{parse_quote, parse_quote_spanned, DeriveInput, Ident, LitStr, Result, Type}, -}; +use proc_macro2::{Span, TokenStream}; +use quote::quote; +use syn::{parse_quote, parse_quote_spanned, DeriveInput, Ident, LitStr, Result, Type}; -use crate::{ - attrs::AttributeSpanWrapper, - field::{Field, FieldName}, - model::Model, - util::wrap_in_dummy_mod, -}; +use crate::attrs::AttributeSpanWrapper; +use crate::field::{Field, FieldName}; +use crate::model::Model; +use crate::util::wrap_in_dummy_mod; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, false)?; diff --git a/diesel_derives/src/selectable.rs b/diesel_derives/src/selectable.rs index 22bf04057aff..3fd9dba2f2c9 100644 --- a/diesel_derives/src/selectable.rs +++ b/diesel_derives/src/selectable.rs @@ -1,9 +1,12 @@ -use { - proc_macro2::{Span, TokenStream}, - quote::quote, - syn::{parse_quote, spanned::Spanned, DeriveInput, Result}, -}; - +use proc_macro2::{Span TokenStream}; +use quote::quote; +use syn::spanned::Spanned; +use syn::DeriveInput; +use syn::{parse_quote, Result}; + +use crate::field::Field; +use crate::model::Model; +use crate::util::wrap_in_dummy_mod; use crate::{field::Field, model::Model, util::wrap_in_dummy_mod}; pub fn derive(item: DeriveInput) -> Result { From 32bc3b9c9395df6e5c2f6bbf0d90ac92ac2b35bc Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Fri, 4 Oct 2024 11:19:46 +0200 Subject: [PATCH 26/28] oops --- diesel_derives/src/as_changeset.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/diesel_derives/src/as_changeset.rs b/diesel_derives/src/as_changeset.rs index d29d5d1d7930..52ad7dc5b398 100644 --- a/diesel_derives/src/as_changeset.rs +++ b/diesel_derives/src/as_changeset.rs @@ -7,7 +7,6 @@ use crate::attrs::AttributeSpanWrapper; use crate::field::Field; use crate::model::Model; use crate::util::{inner_of_option_ty, is_option_ty, wrap_in_dummy_mod}; -}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, false)?; From 0878050ec23f18765ebea741b939926fab18a32d Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Fri, 4 Oct 2024 11:21:12 +0200 Subject: [PATCH 27/28] unused --- diesel_derives/src/as_expression.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diesel_derives/src/as_expression.rs b/diesel_derives/src/as_expression.rs index 892392123245..16fe19686a5c 100644 --- a/diesel_derives/src/as_expression.rs +++ b/diesel_derives/src/as_expression.rs @@ -1,4 +1,4 @@ -use proc_macro2::{Span, TokenStream}; +use proc_macro2::TokenStream; use quote::quote; use syn::parse_quote; use syn::DeriveInput; From acd1e81ecb47154b472d65a7610d5539d61c247e Mon Sep 17 00:00:00 2001 From: Sindbad-Walter Date: Fri, 4 Oct 2024 11:24:33 +0200 Subject: [PATCH 28/28] wip --- diesel_derives/src/selectable.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diesel_derives/src/selectable.rs b/diesel_derives/src/selectable.rs index 3fd9dba2f2c9..0559320d2c08 100644 --- a/diesel_derives/src/selectable.rs +++ b/diesel_derives/src/selectable.rs @@ -1,4 +1,4 @@ -use proc_macro2::{Span TokenStream}; +use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::spanned::Spanned; use syn::DeriveInput; @@ -7,7 +7,6 @@ use syn::{parse_quote, Result}; use crate::field::Field; use crate::model::Model; use crate::util::wrap_in_dummy_mod; -use crate::{field::Field, model::Model, util::wrap_in_dummy_mod}; pub fn derive(item: DeriveInput) -> Result { let model = Model::from_item(&item, false, false)?;