Skip to content

Commit

Permalink
fix: allow unused_lifetimes for pg_extern. (#1655)
Browse files Browse the repository at this point in the history
close #1649.

Signed-off-by: my-vegetable-has-exploded <wy1109468038@gmail.com>
  • Loading branch information
my-vegetable-has-exploded authored Apr 15, 2024
1 parent bce089e commit 7c67cf6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pgrx-macros/src/rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ pub fn item_fn_without_rewrite(mut func: ItemFn) -> syn::Result<proc_macro2::Tok

func.sig.ident = Ident::new(&format!("{}_inner", func.sig.ident), func.sig.ident.span());

// the wrapper_inner function declaration may contain lifetimes that are not used, since our input type is `FunctionCallInfo` mainly and return type is `Datum`
let unused_lifetimes = match generics.lifetimes().next() {
Some(_) => quote! {
#[allow(unused_lifetimes, clippy::extra_unused_lifetimes)]
},
None => quote! {},
};

let arg_list = build_arg_list(&sig, false)?;
let func_name = func.sig.ident.clone();

Expand Down Expand Up @@ -97,6 +105,7 @@ pub fn item_fn_without_rewrite(mut func: ItemFn) -> syn::Result<proc_macro2::Tok
#(#attrs)*
#vis #sig {
#[allow(non_snake_case)]
#unused_lifetimes
#func

#[allow(unused_unsafe)]
Expand Down
8 changes: 8 additions & 0 deletions pgrx-sql-entity-graph/src/pg_extern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ impl PgExtern {
self.func.sig.ident.span(),
);
let func_generics = &self.func.sig.generics;
// the wrapper function declaration may contain lifetimes that are not used, since our input type is `FunctionCallInfo` mainly and return type is `Datum`
let unused_lifetimes = match func_generics.lifetimes().next() {
Some(_) => quote! {
#[allow(unused_lifetimes, clippy::extra_unused_lifetimes)]
},
None => quote! {},
};
let is_raw = self.extern_attrs().contains(&Attribute::Raw);
// We use a `_` prefix to make functions with no args more satisfied during linting.
let fcinfo_ident = syn::Ident::new("_fcinfo", self.func.sig.ident.span());
Expand Down Expand Up @@ -459,6 +466,7 @@ impl PgExtern {
quote_spanned! { span=>
#[no_mangle]
#[doc(hidden)]
#unused_lifetimes
#[::pgrx::pgrx_macros::pg_guard]
pub unsafe extern "C" fn #func_name_wrapper #func_generics(#fcinfo_ident: ::pgrx::pg_sys::FunctionCallInfo) #return_ty {
#wrapped_contents
Expand Down

0 comments on commit 7c67cf6

Please sign in to comment.