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

fix: allow unused_lifetimes for pg_extern. #1655

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
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