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

macros: inline format_args! idents #1532

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pgrx-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn pg_test(attr: TokenStream, item: TokenStream) -> TokenStream {
let res = pgrx_tests::run_test(#sql_funcname, #expected_error, crate::pg_test::postgresql_conf_options());
match res {
Ok(()) => (),
Err(e) => panic!("{:?}", e)
Err(e) => panic!("{e:?}")
}
}
});
Expand Down Expand Up @@ -184,12 +184,12 @@ pub fn pg_cast(attr: TokenStream, item: TokenStream) -> TokenStream {
{
"implicit" => cast = PgCast::Implicit,
"assignment" => cast = PgCast::Assignment,
other => panic!("Unrecognized pg_cast option: {}. ", other),
other => panic!("Unrecognized pg_cast option: {other}. "),
}
}
}
Err(err) => {
panic!("Failed to parse attribute to pg_cast: {}", err)
panic!("Failed to parse attribute to pg_cast: {err}")
}
}
// `pg_cast` does not support other `pg_extern` attributes for now, pass an empty attribute token stream.
Expand Down Expand Up @@ -715,7 +715,7 @@ fn impl_postgres_enum(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
let (name, _, _) = ::pgrx::enum_helper::lookup_enum_by_oid(unsafe { ::pgrx::pg_sys::Oid::from_datum(datum, is_null)? } );
match name.as_str() {
#from_datum
_ => panic!("invalid enum value: {}", name)
_ => panic!("invalid enum value: {name}")
}
}
}
Expand Down Expand Up @@ -795,8 +795,8 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
let name = &ast.ident;
let generics = &ast.generics;
let has_lifetimes = generics.lifetimes().next();
let funcname_in = Ident::new(&format!("{}_in", name).to_lowercase(), name.span());
let funcname_out = Ident::new(&format!("{}_out", name).to_lowercase(), name.span());
let funcname_in = Ident::new(&format!("{name}_in").to_lowercase(), name.span());
let funcname_out = Ident::new(&format!("{name}_out").to_lowercase(), name.span());
let mut args = parse_postgres_type_args(&ast.attrs);
let mut stream = proc_macro2::TokenStream::new();

Expand Down Expand Up @@ -905,7 +905,7 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
pub fn #funcname_in #generics(input: Option<&#lifetime ::core::ffi::CStr>) -> Option<#name #generics> {
input.map_or_else(|| {
for m in <#name as ::pgrx::inoutfuncs::JsonInOutFuncs>::NULL_ERROR_MESSAGE {
::pgrx::pg_sys::error!("{}", m);
::pgrx::pg_sys::error!("{m}");
}
None
}, |i| Some(<#name as ::pgrx::inoutfuncs::JsonInOutFuncs>::input(i)))
Expand All @@ -929,7 +929,7 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
pub fn #funcname_in #generics(input: Option<&#lifetime ::core::ffi::CStr>) -> Option<#name #generics> {
input.map_or_else(|| {
for m in <#name as ::pgrx::inoutfuncs::InOutFuncs>::NULL_ERROR_MESSAGE {
::pgrx::pg_sys::error!("{}", m);
::pgrx::pg_sys::error!("{m}");
}
None
}, |i| Some(<#name as ::pgrx::inoutfuncs::InOutFuncs>::input(i)))
Expand All @@ -952,7 +952,7 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
pub fn #funcname_in #generics(input: Option<&#lifetime ::core::ffi::CStr>) -> Option<::pgrx::datum::PgVarlena<#name #generics>> {
input.map_or_else(|| {
for m in <#name as ::pgrx::inoutfuncs::PgVarlenaInOutFuncs>::NULL_ERROR_MESSAGE {
::pgrx::pg_sys::error!("{}", m);
::pgrx::pg_sys::error!("{m}");
}
None
}, |i| Some(<#name as ::pgrx::inoutfuncs::PgVarlenaInOutFuncs>::input(i)))
Expand Down
16 changes: 8 additions & 8 deletions pgrx-macros/src/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(crate) fn deriving_postgres_hash(ast: DeriveInput) -> syn::Result<proc_macro
///
/// ["optimization hints"]: https://www.postgresql.org/docs/current/xoper-optimization.html
pub fn derive_pg_eq(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_eq", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_eq").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_operator(immutable, parallel_safe)]
Expand Down Expand Up @@ -120,7 +120,7 @@ pub fn derive_pg_eq(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro
///
/// See `derive_pg_eq` for the implications of this assumption.
pub fn derive_pg_ne(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_ne", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_ne").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_operator(immutable, parallel_safe)]
Expand All @@ -136,7 +136,7 @@ pub fn derive_pg_ne(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro
}

pub fn derive_pg_lt(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_lt", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_lt").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_operator(immutable, parallel_safe)]
Expand All @@ -153,7 +153,7 @@ pub fn derive_pg_lt(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro
}

pub fn derive_pg_gt(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_gt", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_gt").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_operator(immutable, parallel_safe)]
Expand All @@ -169,7 +169,7 @@ pub fn derive_pg_gt(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro
}

pub fn derive_pg_le(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_le", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_le").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_operator(immutable, parallel_safe)]
Expand All @@ -185,7 +185,7 @@ pub fn derive_pg_le(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro
}

pub fn derive_pg_ge(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_ge", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_ge").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_operator(immutable, parallel_safe)]
Expand All @@ -201,7 +201,7 @@ pub fn derive_pg_ge(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro
}

pub fn derive_pg_cmp(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_cmp", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_cmp").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_extern(immutable, parallel_safe)]
Expand All @@ -226,7 +226,7 @@ pub fn derive_pg_cmp(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macr
/// Postgres is no different: this hashing is for the explicit purpose of equality checks,
/// and it also needs to be able to reason from hash equality to actual equality.
pub fn derive_pg_hash(name: &Ident, path: &proc_macro2::TokenStream) -> proc_macro2::TokenStream {
let pg_name = Ident::new(&format!("{}_hash", name).to_lowercase(), name.span());
let pg_name = Ident::new(&format!("{name}_hash").to_lowercase(), name.span());
quote! {
#[allow(non_snake_case)]
#[::pgrx::pgrx_macros::pg_extern(immutable, parallel_safe)]
Expand Down
Loading