From ec8f82be1b03bff9149df52c18084cdd76cee589 Mon Sep 17 00:00:00 2001 From: damszew Date: Fri, 12 Apr 2024 08:09:10 +0200 Subject: [PATCH 1/2] fix: Do not warn about `non_local_definitions` --- src/lib.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5ed7ca0..eeaf3d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,19 +161,16 @@ fn expand_sql_types(ast: &syn::DeriveInput) -> TokenStream { // since our query doesn't take varargs it's fine for the DB to cache it let query_id_impl = gen_query_id(&name); - wrap_impls_in_const( - name, - "e! { - #to_sql_impl - #as_expr_impl + wrap_impls_in_const("e! { + #to_sql_impl + #as_expr_impl - #from_sql_impl + #from_sql_impl - #queryable_impl + #queryable_impl - #query_id_impl - }, - ) + #query_id_impl + }) } fn gen_tosql(name: &syn::Ident, wrapped_ty: &syn::Type) -> TokenStream { @@ -279,15 +276,9 @@ fn gen_query_id(name: &syn::Ident) -> TokenStream { } } -/// This guarantees that items we generate don't polute the module scope -/// -/// We use the const name as a form of documentation of the generated code -fn wrap_impls_in_const(ty_name: &syn::Ident, item: &TokenStream) -> TokenStream { - let name = ty_name.to_string().to_uppercase(); - let dummy_const = syn::Ident::new( - &format!("_IMPL_DIESEL_NEW_TYPE_FOR_{}", name), - Span::call_site(), - ); +/// This guarantees that items we generate don't pollute the module scope +fn wrap_impls_in_const(item: &TokenStream) -> TokenStream { + let dummy_const = syn::Ident::new("_", Span::call_site()); quote! { const #dummy_const: () = { #item From f558bc707f86ab7233062d487e6cecac8fe4bbbd Mon Sep 17 00:00:00 2001 From: damszew Date: Fri, 12 Apr 2024 08:11:56 +0200 Subject: [PATCH 2/2] chore: Clippy fixes --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index eeaf3d1..8179427 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,17 +149,17 @@ fn expand_sql_types(ast: &syn::DeriveInput) -> TokenStream { }; // Required to be able to insert/read from the db, don't allow searching - let to_sql_impl = gen_tosql(&name, &wrapped_ty); - let as_expr_impl = gen_asexpressions(&name, &wrapped_ty); + let to_sql_impl = gen_tosql(name, wrapped_ty); + let as_expr_impl = gen_asexpressions(name, wrapped_ty); // raw deserialization - let from_sql_impl = gen_from_sql(&name, &wrapped_ty); + let from_sql_impl = gen_from_sql(name, wrapped_ty); // querying - let queryable_impl = gen_queryable(&name, &wrapped_ty); + let queryable_impl = gen_queryable(name, wrapped_ty); // since our query doesn't take varargs it's fine for the DB to cache it - let query_id_impl = gen_query_id(&name); + let query_id_impl = gen_query_id(name); wrap_impls_in_const("e! { #to_sql_impl