From 1f713392eeff2f9e7fed96627a0a3d8052c77c3f Mon Sep 17 00:00:00 2001 From: Joey de Waal Date: Fri, 23 Aug 2024 23:22:04 +0200 Subject: [PATCH 1/2] fix: non-snake-case fields warning --- sqlx-macros-core/src/query/mod.rs | 3 +++ sqlx-macros-core/src/query/output.rs | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sqlx-macros-core/src/query/mod.rs b/sqlx-macros-core/src/query/mod.rs index 1536eebaa1..4423fc1bde 100644 --- a/sqlx-macros-core/src/query/mod.rs +++ b/sqlx-macros-core/src/query/mod.rs @@ -301,11 +301,14 @@ where let mut record_tokens = quote! { #[derive(Debug)] + #[allow(non_snake_case)] struct #record_name { #(#record_fields)* } }; + + record_tokens.extend(output::quote_query_as::( &input, &record_name, diff --git a/sqlx-macros-core/src/query/output.rs b/sqlx-macros-core/src/query/output.rs index 596a52e877..a3b7e47ff9 100644 --- a/sqlx-macros-core/src/query/output.rs +++ b/sqlx-macros-core/src/query/output.rs @@ -143,15 +143,25 @@ pub fn quote_query_as( // binding to a `let` avoids confusing errors about // "try expression alternatives have incompatible types" // it doesn't seem to hurt inference in the other branches + #[allow(non_snake_case)] let #var_name = row.try_get_unchecked::<#type_, _>(#i)?.into(); }, // type was overridden to be a wildcard so we fallback to the runtime check - (true, ColumnType::Wildcard) => quote! ( let #var_name = row.try_get(#i)?; ), + (true, ColumnType::Wildcard) => quote! ( + #[allow(non_snake_case)] + let #var_name = row.try_get(#i)?; + ), (true, ColumnType::OptWildcard) => { - quote! ( let #var_name = row.try_get::<::std::option::Option<_>, _>(#i)?; ) + quote! ( + #[allow(non_snake_case)] + let #var_name = row.try_get::<::std::option::Option<_>, _>(#i)?; + ) } // macro is the `_unchecked!()` variant so this will die in decoding if it's wrong - (false, _) => quote!( let #var_name = row.try_get_unchecked(#i)?; ), + (false, _) => quote!( + #[allow(non_snake_case)] + let #var_name = row.try_get_unchecked(#i)?; + ), } }, ); From 2bfaa6f664739b5ffd25847f40503a8bda0a6582 Mon Sep 17 00:00:00 2001 From: Joey de Waal Date: Fri, 23 Aug 2024 23:32:55 +0200 Subject: [PATCH 2/2] cargo fmt --- sqlx-macros-core/src/query/mod.rs | 2 -- sqlx-macros-core/src/query/output.rs | 18 +++++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sqlx-macros-core/src/query/mod.rs b/sqlx-macros-core/src/query/mod.rs index 4423fc1bde..09acff9bd2 100644 --- a/sqlx-macros-core/src/query/mod.rs +++ b/sqlx-macros-core/src/query/mod.rs @@ -307,8 +307,6 @@ where } }; - - record_tokens.extend(output::quote_query_as::( &input, &record_name, diff --git a/sqlx-macros-core/src/query/output.rs b/sqlx-macros-core/src/query/output.rs index a3b7e47ff9..5e7cc5058d 100644 --- a/sqlx-macros-core/src/query/output.rs +++ b/sqlx-macros-core/src/query/output.rs @@ -148,20 +148,20 @@ pub fn quote_query_as( }, // type was overridden to be a wildcard so we fallback to the runtime check (true, ColumnType::Wildcard) => quote! ( - #[allow(non_snake_case)] - let #var_name = row.try_get(#i)?; - ), + #[allow(non_snake_case)] + let #var_name = row.try_get(#i)?; + ), (true, ColumnType::OptWildcard) => { quote! ( - #[allow(non_snake_case)] - let #var_name = row.try_get::<::std::option::Option<_>, _>(#i)?; - ) + #[allow(non_snake_case)] + let #var_name = row.try_get::<::std::option::Option<_>, _>(#i)?; + ) } // macro is the `_unchecked!()` variant so this will die in decoding if it's wrong (false, _) => quote!( - #[allow(non_snake_case)] - let #var_name = row.try_get_unchecked(#i)?; - ), + #[allow(non_snake_case)] + let #var_name = row.try_get_unchecked(#i)?; + ), } }, );