diff --git a/pgrx-macros/src/lib.rs b/pgrx-macros/src/lib.rs index 3b0cd07ad..8e2ccb244 100644 --- a/pgrx-macros/src/lib.rs +++ b/pgrx-macros/src/lib.rs @@ -102,8 +102,7 @@ pub fn pg_test(attr: TokenStream, item: TokenStream) -> TokenStream { }; let sql_funcname = func.sig.ident.to_string(); - let test_func_name = - Ident::new(&format!("pg_{}", func.sig.ident.to_string()), func.span()); + let test_func_name = Ident::new(&format!("pg_{}", func.sig.ident), func.span()); let attributes = func.attrs; let mut att_stream = proc_macro2::TokenStream::new(); @@ -1053,7 +1052,7 @@ Functions inside the `impl` may use the [`#[pgrx]`](macro@pgrx) attribute. pub fn pg_aggregate(_attr: TokenStream, item: TokenStream) -> TokenStream { // We don't care about `_attr` as we can find it in the `ItemMod`. fn wrapped(item_impl: ItemImpl) -> Result { - let sql_graph_entity_item = PgAggregate::new(item_impl.into())?; + let sql_graph_entity_item = PgAggregate::new(item_impl)?; Ok(sql_graph_entity_item.to_token_stream().into()) } diff --git a/pgrx-macros/src/rewriter.rs b/pgrx-macros/src/rewriter.rs index 84683cdc0..8ba132e16 100644 --- a/pgrx-macros/src/rewriter.rs +++ b/pgrx-macros/src/rewriter.rs @@ -68,8 +68,7 @@ impl PgGuardRewriter { // nor do we need a visibility beyond "private" func.vis = Visibility::Inherited; - func.sig.ident = - Ident::new(&format!("{}_inner", func.sig.ident.to_string()), func.sig.ident.span()); + func.sig.ident = Ident::new(&format!("{}_inner", func.sig.ident), func.sig.ident.span()); let arg_list = PgGuardRewriter::build_arg_list(&sig, false)?; let func_name = PgGuardRewriter::build_func_name(&func.sig); diff --git a/pgrx-pg-sys/build.rs b/pgrx-pg-sys/build.rs index c1cf65777..3fa3e4bf6 100644 --- a/pgrx-pg-sys/build.rs +++ b/pgrx-pg-sys/build.rs @@ -155,7 +155,7 @@ fn main() -> eyre::Result<()> { } else { let mut found = Vec::new(); for pgver in SUPPORTED_VERSIONS() { - if let Some(_) = env_tracked(&format!("CARGO_FEATURE_PG{}", pgver.major)) { + if env_tracked(&format!("CARGO_FEATURE_PG{}", pgver.major)).is_some() { found.push(pgver); } } @@ -175,7 +175,7 @@ fn main() -> eyre::Result<()> { return Err(eyre!( "Multiple `pg$VERSION` features found.\n`--no-default-features` may be required.\nFound: {}", versions - .into_iter() + .iter() .map(|version| format!("pg{}", version.major)) .collect::>() .join(", ") @@ -254,7 +254,7 @@ fn emit_rerun_if_changed() { println!("cargo:rerun-if-changed=cshim"); if let Ok(pgrx_config) = Pgrx::config_toml() { - println!("cargo:rerun-if-changed={}", pgrx_config.display().to_string()); + println!("cargo:rerun-if-changed={}", pgrx_config.display()); } } @@ -268,7 +268,7 @@ fn generate_bindings( include_h.push("include"); include_h.push(format!("pg{}.h", major_version)); - let bindgen_output = get_bindings(major_version, &pg_config, &include_h) + let bindgen_output = get_bindings(major_version, pg_config, &include_h) .wrap_err_with(|| format!("bindgen failed for pg{}", major_version))?; let oids = extract_oids(&bindgen_output); @@ -350,8 +350,8 @@ fn write_rs_file( let mut contents = header; contents.extend(code); - std::fs::write(&file, contents.to_string())?; - rust_fmt(&file) + std::fs::write(file, contents.to_string())?; + rust_fmt(file) } /// Given a token stream representing a file, apply a series of transformations to munge @@ -405,7 +405,7 @@ fn rewrite_oid_consts( oids: &BTreeMap>, ) -> Vec { items - .into_iter() + .iter() .map(|item| match item { Item::Const(ItemConst { ident, ty, expr, .. }) if ty.to_token_stream().to_string() == "u32" && oids.get(ident) == Some(expr) => @@ -699,7 +699,7 @@ fn get_bindings( } else { let bindings = run_bindgen(major_version, pg_config, include_h)?; if let Some(path) = env_tracked("PGRX_PG_SYS_EXTRA_OUTPUT_PATH") { - std::fs::write(&path, &bindings)?; + std::fs::write(path, &bindings)?; } bindings }; @@ -719,7 +719,7 @@ fn run_bindgen( binder = add_derives(binder); let bindings = binder .header(include_h.display().to_string()) - .clang_args(&extra_bindgen_clang_args(pg_config)?) + .clang_args(extra_bindgen_clang_args(pg_config)?) .clang_args(pg_target_include_flags(major_version, pg_config)?) .detect_include_paths(target_env_tracked("PGRX_BINDGEN_NO_DETECT_INCLUDES").is_none()) .parse_callbacks(Box::new(PgrxOverrides::default())) @@ -833,7 +833,7 @@ fn build_shim(shim_src: &PathBuf, shim_dst: &PathBuf, pg_config: &PgConfig) -> e eprintln!("libpgrx_cshim={}", libpgrx_cshim.display()); // then build the shim for the version feature currently being built - build_shim_for_version(&shim_src, &shim_dst, pg_config)?; + build_shim_for_version(shim_src, shim_dst, pg_config)?; // no matter what, tell rustc to link to the library that was built for the feature we're currently building let envvar_name = format!("CARGO_FEATURE_PG{}", major_version); @@ -1042,7 +1042,7 @@ fn apply_pg_guard(items: &Vec) -> eyre::Result { let abi = &block.abi; let (mut extern_funcs, mut others) = (Vec::new(), Vec::new()); - block.items.iter().cloned().filter(|item| !is_blocklisted_item(item)).for_each( + block.items.iter().filter(|&item| !is_blocklisted_item(item)).cloned().for_each( |item| match item { ForeignItem::Fn(func) => extern_funcs.push(func), item => others.push(item), @@ -1078,6 +1078,6 @@ fn rust_fmt(path: &PathBuf) -> eyre::Result<()> { { Err(e).wrap_err("Failed to run `rustfmt`, is it installed?") } - Err(e) => Err(e.into()), + Err(e) => Err(e), } } diff --git a/pgrx-pg-sys/src/include.rs b/pgrx-pg-sys/src/include.rs index 7002dcfdf..1592e288b 100644 --- a/pgrx-pg-sys/src/include.rs +++ b/pgrx-pg-sys/src/include.rs @@ -4,6 +4,7 @@ #[cfg(all(feature = "pg12", not(docsrs)))] pub(crate) mod pg12 { + #![allow(clippy::all)] include!(concat!(env!("OUT_DIR"), "/pg12.rs")); } #[cfg(all(feature = "pg12", docsrs))] @@ -11,6 +12,7 @@ pub(crate) mod pg12; #[cfg(all(feature = "pg13", not(docsrs)))] pub(crate) mod pg13 { + #![allow(clippy::all)] include!(concat!(env!("OUT_DIR"), "/pg13.rs")); } #[cfg(all(feature = "pg13", docsrs))] @@ -18,6 +20,7 @@ pub(crate) mod pg13; #[cfg(all(feature = "pg14", not(docsrs)))] pub(crate) mod pg14 { + #![allow(clippy::all)] include!(concat!(env!("OUT_DIR"), "/pg14.rs")); } #[cfg(all(feature = "pg14", docsrs))] @@ -25,6 +28,7 @@ pub(crate) mod pg14; #[cfg(all(feature = "pg15", not(docsrs)))] pub(crate) mod pg15 { + #![allow(clippy::all)] include!(concat!(env!("OUT_DIR"), "/pg15.rs")); } #[cfg(all(feature = "pg15", docsrs))] @@ -32,6 +36,7 @@ pub(crate) mod pg15; #[cfg(all(feature = "pg16", not(docsrs)))] pub(crate) mod pg16 { + #[allow(clippy::all)] include!(concat!(env!("OUT_DIR"), "/pg16.rs")); } #[cfg(all(feature = "pg16", docsrs))] diff --git a/pgrx-pg-sys/src/port.rs b/pgrx-pg-sys/src/port.rs index a926a9835..8f52834ce 100644 --- a/pgrx-pg-sys/src/port.rs +++ b/pgrx-pg-sys/src/port.rs @@ -197,8 +197,7 @@ pub unsafe fn BufferGetBlock(buffer: crate::Buffer) -> crate::Block { if BufferIsLocal(buffer) { *crate::LocalBufferBlockPointers.offset(((-buffer) - 1) as isize) } else { - crate::BufferBlocks - .offset((((buffer as crate::Size) - 1) * crate::BLCKSZ as usize) as isize) + crate::BufferBlocks.add(((buffer as crate::Size) - 1) * crate::BLCKSZ as usize) as crate::Block } } diff --git a/pgrx-pg-sys/src/submodules/datum.rs b/pgrx-pg-sys/src/submodules/datum.rs index 951af9375..c9c81aa78 100644 --- a/pgrx-pg-sys/src/submodules/datum.rs +++ b/pgrx-pg-sys/src/submodules/datum.rs @@ -214,7 +214,7 @@ impl TryFrom for Datum { impl From for Option { #[inline] fn from(nd: NullableDatum) -> Option { - Some(Datum::try_from(nd).ok()?) + Datum::try_from(nd).ok() } } @@ -259,6 +259,6 @@ mod test { let val: usize = 123456; let datum = Datum::from(val); - assert_eq!(datum.value() as usize, val); + assert_eq!({ datum.value() }, val); } } diff --git a/pgrx-pg-sys/src/submodules/errcodes.rs b/pgrx-pg-sys/src/submodules/errcodes.rs index 231bd2ebb..b1b0a6637 100644 --- a/pgrx-pg-sys/src/submodules/errcodes.rs +++ b/pgrx-pg-sys/src/submodules/errcodes.rs @@ -1280,15 +1280,15 @@ impl From for PgSqlErrorCode { #[allow(non_snake_case)] #[inline] const fn PGSIXBIT(ch: i32) -> i32 { - (((ch) - '0' as i32) & 0x3F) as i32 + ((ch) - '0' as i32) & 0x3F } #[allow(non_snake_case)] #[inline] const fn MAKE_SQLSTATE(ch1: char, ch2: char, ch3: char, ch4: char, ch5: char) -> i32 { - (PGSIXBIT(ch1 as i32) + PGSIXBIT(ch1 as i32) + (PGSIXBIT(ch2 as i32) << 6) + (PGSIXBIT(ch3 as i32) << 12) + (PGSIXBIT(ch4 as i32) << 18) - + (PGSIXBIT(ch5 as i32) << 24)) as i32 + + (PGSIXBIT(ch5 as i32) << 24) } diff --git a/pgrx-pg-sys/src/submodules/ffi.rs b/pgrx-pg-sys/src/submodules/ffi.rs index c74f45543..9fe6975a7 100644 --- a/pgrx-pg-sys/src/submodules/ffi.rs +++ b/pgrx-pg-sys/src/submodules/ffi.rs @@ -123,7 +123,7 @@ unsafe fn pg_guard_ffi_boundary_impl T>(f: F) -> T { pg_sys::PG_exception_stack = prev_exception_stack; pg_sys::error_context_stack = prev_error_context_stack; - return result; + result } else { // we're back here b/c of a longjmp originating in Postgres @@ -148,13 +148,13 @@ unsafe fn pg_guard_ffi_boundary_impl T>(f: F) -> T { .is_null() .then(|| String::from("")) .unwrap_or_else(|| CStr::from_ptr(errdata.message).to_string_lossy().to_string()); - let detail = errdata.detail.is_null().then(|| None).unwrap_or_else(|| { + let detail = errdata.detail.is_null().then_some(None).unwrap_or_else(|| { Some(CStr::from_ptr(errdata.detail).to_string_lossy().to_string()) }); - let hint = errdata.hint.is_null().then(|| None).unwrap_or_else(|| { + let hint = errdata.hint.is_null().then_some(None).unwrap_or_else(|| { Some(CStr::from_ptr(errdata.hint).to_string_lossy().to_string()) }); - let funcname = errdata.funcname.is_null().then(|| None).unwrap_or_else(|| { + let funcname = errdata.funcname.is_null().then_some(None).unwrap_or_else(|| { Some(CStr::from_ptr(errdata.funcname).to_string_lossy().to_string()) }); let file = diff --git a/pgrx-pg-sys/src/submodules/htup.rs b/pgrx-pg-sys/src/submodules/htup.rs index d8cfdbd05..8aeff2dff 100644 --- a/pgrx-pg-sys/src/submodules/htup.rs +++ b/pgrx-pg-sys/src/submodules/htup.rs @@ -393,13 +393,11 @@ unsafe fn fastgetattr( } else { nocachegetattr(tup, attnum, tupleDesc) } + } else if att_isnull(attnum - 1, (*(*tup).t_data).t_bits.as_ptr()) { + *isnull = true; + Datum::from(0) // a NULL pointer } else { - if att_isnull(attnum - 1, (*(*tup).t_data).t_bits.as_ptr()) { - *isnull = true; - Datum::from(0) // a NULL pointer - } else { - nocachegetattr(tup, attnum, tupleDesc) - } + nocachegetattr(tup, attnum, tupleDesc) } } } diff --git a/pgrx-pg-sys/src/submodules/panic.rs b/pgrx-pg-sys/src/submodules/panic.rs index b1b851042..e77853a16 100644 --- a/pgrx-pg-sys/src/submodules/panic.rs +++ b/pgrx-pg-sys/src/submodules/panic.rs @@ -224,7 +224,7 @@ impl ErrorReportWithLevel { /// Returns the name of the function that generated this error report, if we were able to figure it out pub fn function_name(&self) -> Option<&str> { - self.inner.location.funcname.as_ref().map(|s| s.as_str()) + self.inner.location.funcname.as_deref() } /// Returns the context message of this error report, if any @@ -282,12 +282,12 @@ impl ErrorReport { /// Returns the detail message of this error report pub fn detail(&self) -> Option<&str> { - self.detail.as_ref().map(|s| s.as_str()) + self.detail.as_deref() } /// Returns the hint message of this error report pub fn hint(&self) -> Option<&str> { - self.hint.as_ref().map(|s| s.as_str()) + self.hint.as_deref() } /// Report this [PgErrorReport], which will ultimately be reported by Postgres at the specified [PgLogLevel] diff --git a/pgrx/src/bgworkers.rs b/pgrx/src/bgworkers.rs index fdd8723bd..47dae8f5b 100644 --- a/pgrx/src/bgworkers.rs +++ b/pgrx/src/bgworkers.rs @@ -455,7 +455,7 @@ impl BackgroundWorkerBuilder { } /// What is the type of this BackgroundWorker - pub fn set_type(mut self: Self, input: &str) -> Self { + pub fn set_type(mut self, input: &str) -> Self { self.bgw_type = input.to_string(); self } @@ -464,7 +464,7 @@ impl BackgroundWorkerBuilder { /// /// `startup` allows specifying shared memory initialization startup hook. Ignored /// if [`BackgroundWorkerBuilder::load_dynamic`] is used. - pub fn enable_shmem_access(mut self: Self, startup: Option) -> Self { + pub fn enable_shmem_access(mut self, startup: Option) -> Self { self.bgw_flags = self.bgw_flags | BGWflags::BGWORKER_SHMEM_ACCESS; self.shared_memory_startup_fn = startup; self @@ -474,7 +474,7 @@ impl BackgroundWorkerBuilder { /// /// If set, then the configured start time becomes `BgWorkerStartTIme::RecoveryFinished` /// as accessing SPI prior to possible database recovery is not possible - pub fn enable_spi_access(mut self: Self) -> Self { + pub fn enable_spi_access(mut self) -> Self { self.bgw_flags = self.bgw_flags | BGWflags::BGWORKER_SHMEM_ACCESS | BGWflags::BGWORKER_BACKEND_DATABASE_CONNECTION; @@ -483,7 +483,7 @@ impl BackgroundWorkerBuilder { } /// When should this BackgroundWorker be started by Postgres? - pub fn set_start_time(mut self: Self, input: BgWorkerStartTime) -> Self { + pub fn set_start_time(mut self, input: BgWorkerStartTime) -> Self { self.bgw_start_time = input; self } @@ -491,7 +491,7 @@ impl BackgroundWorkerBuilder { /// the interval, in seconds, that postgres should wait before restarting the process, /// in case it crashes. It can be `Some(any positive duration value), or /// `None`, indicating not to restart the process in case of a crash. - pub fn set_restart_time(mut self: Self, input: Option) -> Self { + pub fn set_restart_time(mut self, input: Option) -> Self { self.bgw_restart_time = input; self } @@ -499,7 +499,7 @@ impl BackgroundWorkerBuilder { /// What is the library name that contains the "main" function? /// /// Typically, this will just be your extension's name - pub fn set_library(mut self: Self, input: &str) -> Self { + pub fn set_library(mut self, input: &str) -> Self { self.bgw_library_name = input.to_string(); self } @@ -522,7 +522,7 @@ impl BackgroundWorkerBuilder { /// pub extern "C" fn background_worker_main(_arg: pg_sys::Datum) { /// } /// ``` - pub fn set_function(mut self: Self, input: &str) -> Self { + pub fn set_function(mut self, input: &str) -> Self { self.bgw_function_name = input.to_string(); self } @@ -557,15 +557,15 @@ impl BackgroundWorkerBuilder { /// .set_argument(42i32.into_datum()) /// .load(); /// ``` - pub fn set_argument(mut self: Self, input: Option) -> Self { - self.bgw_main_arg = pg_sys::Datum::from(input.unwrap_or(0.into())); + pub fn set_argument(mut self, input: Option) -> Self { + self.bgw_main_arg = input.unwrap_or(0.into()); self } /// extra data to be passed to the background worker. Unlike bgw_main_arg, this /// data is not passed as an argument to the worker's main function, but it can be /// accessed via the `BackgroundWorker` struct. - pub fn set_extra(mut self: Self, input: &str) -> Self { + pub fn set_extra(mut self, input: &str) -> Self { self.bgw_extra = input.to_string(); self } @@ -575,14 +575,14 @@ impl BackgroundWorkerBuilder { /// postmaster startup time, or when the backend registering the worker does not wish /// to wait for the worker to start up. Otherwise, it should be initialized to /// `pgrx::pg_sys::MyProcPid` - pub fn set_notify_pid(mut self: Self, input: i32) -> Self { + pub fn set_notify_pid(mut self, input: i32) -> Self { self.bgw_notify_pid = input; self } /// Once properly configured, call `load()` to get the BackgroundWorker registered and /// started at the proper time by Postgres. - pub fn load(self: Self) { + pub fn load(self) { let mut bgw: pg_sys::BackgroundWorker = (&self).into(); unsafe { @@ -597,7 +597,7 @@ impl BackgroundWorkerBuilder { } /// Once properly configured, call `load_dynamic()` to get the BackgroundWorker registered and started dynamically. - pub fn load_dynamic(self: Self) -> DynamicBackgroundWorker { + pub fn load_dynamic(self) -> DynamicBackgroundWorker { let mut bgw: pg_sys::BackgroundWorker = (&self).into(); let mut handle: *mut pg_sys::BackgroundWorkerHandle = null_mut(); @@ -612,8 +612,8 @@ impl BackgroundWorkerBuilder { /// This conversion is useful only in limited context outside of pgrx, such as when this structure is required /// by other libraries and the worker is not to be started by pgrx itself. In this case, /// the builder is useful for building this structure. -impl<'a> Into for &'a BackgroundWorkerBuilder { - fn into(self) -> pg_sys::BackgroundWorker { +impl<'a> From<&'a BackgroundWorkerBuilder> for pg_sys::BackgroundWorker { + fn from(builder: &'a BackgroundWorkerBuilder) -> Self { #[cfg(any( feature = "pg12", feature = "pg13", @@ -622,19 +622,19 @@ impl<'a> Into for &'a BackgroundWorkerBuilder { feature = "pg16" ))] let bgw = pg_sys::BackgroundWorker { - bgw_name: RpgffiChar::from(&self.bgw_name[..]).0, - bgw_type: RpgffiChar::from(&self.bgw_type[..]).0, - bgw_flags: self.bgw_flags.bits(), - bgw_start_time: self.bgw_start_time as u32, - bgw_restart_time: match self.bgw_restart_time { + bgw_name: RpgffiChar::from(&builder.bgw_name[..]).0, + bgw_type: RpgffiChar::from(&builder.bgw_type[..]).0, + bgw_flags: builder.bgw_flags.bits(), + bgw_start_time: builder.bgw_start_time as u32, + bgw_restart_time: match builder.bgw_restart_time { None => -1, Some(d) => d.as_secs() as i32, }, - bgw_library_name: RpgffiChar::from(&self.bgw_library_name[..]).0, - bgw_function_name: RpgffiChar::from(&self.bgw_function_name[..]).0, - bgw_main_arg: self.bgw_main_arg, - bgw_extra: RpgffiChar128::from(&self.bgw_extra[..]).0, - bgw_notify_pid: self.bgw_notify_pid, + bgw_library_name: RpgffiChar::from(&builder.bgw_library_name[..]).0, + bgw_function_name: RpgffiChar::from(&builder.bgw_function_name[..]).0, + bgw_main_arg: builder.bgw_main_arg, + bgw_extra: RpgffiChar128::from(&builder.bgw_extra[..]).0, + bgw_notify_pid: builder.bgw_notify_pid, }; bgw diff --git a/pgrx/src/fcinfo.rs b/pgrx/src/fcinfo.rs index 967dab066..2d214f4bc 100644 --- a/pgrx/src/fcinfo.rs +++ b/pgrx/src/fcinfo.rs @@ -165,7 +165,7 @@ unsafe fn get_nullable_datum( let fcinfo = unsafe { fcinfo.as_mut() }.unwrap(); unsafe { let nargs = fcinfo.nargs; - fcinfo.args.as_slice(nargs as usize)[num].clone() + fcinfo.args.as_slice(nargs as usize)[num] } } @@ -218,10 +218,7 @@ pub unsafe fn pg_get_collation(fcinfo: pg_sys::FunctionCallInfo) -> pg_sys::Oid pub unsafe fn pg_getarg_pointer(fcinfo: pg_sys::FunctionCallInfo, num: usize) -> Option<*mut T> { unsafe { // SAFETY: The user has asserted that `fcinfo` is valid - match pg_getarg_datum(fcinfo, num) { - Some(datum) => Some(datum.cast_mut_ptr::()), - None => None, - } + pg_getarg_datum(fcinfo, num).map(|datum| datum.cast_mut_ptr::()) } } @@ -249,10 +246,7 @@ pub unsafe fn pg_getarg_cstr<'a>( fcinfo: pg_sys::FunctionCallInfo, num: usize, ) -> Option<&'a core::ffi::CStr> { - match pg_getarg_pointer(fcinfo, num) { - Some(ptr) => Some(unsafe { core::ffi::CStr::from_ptr(ptr) }), - None => None, - } + pg_getarg_pointer(fcinfo, num).map(|ptr| unsafe { core::ffi::CStr::from_ptr(ptr) }) } /// Indicates that a `PG_FUNCTION_INFO_V1` function is returning a SQL "void". @@ -326,7 +320,7 @@ pub unsafe fn direct_function_call( // TODO: this could take an iterator, but it would break turbofish :( args: &[Option], ) -> Option { - direct_function_call_as_datum(func, args).map_or(None, |d| R::from_datum(d, false)) + direct_function_call_as_datum(func, args).and_then(|d| R::from_datum(d, false)) } /// Akin to [direct_function_call], but specifically for calling those functions declared with the @@ -360,7 +354,7 @@ pub unsafe fn direct_pg_extern_function_call( func: unsafe extern "C" fn(pg_sys::FunctionCallInfo) -> pg_sys::Datum, args: &[Option], ) -> Option { - direct_pg_extern_function_call_as_datum(func, args).map_or(None, |d| R::from_datum(d, false)) + direct_pg_extern_function_call_as_datum(func, args).and_then(|d| R::from_datum(d, false)) } /// Same as [direct_function_call] but instead returns the direct `Option` instead @@ -396,7 +390,7 @@ unsafe fn direct_function_call_as_datum_internal( fcinfo.nargs = nargs; let arg_slice = fcinfo.args.as_mut_slice(args.len()); - for (i, &arg) in args.into_iter().enumerate() { + for (i, &arg) in args.iter().enumerate() { arg_slice[i].isnull = arg.is_none(); arg_slice[i].value = arg.unwrap_or(pg_sys::Datum::from(0)); } @@ -405,7 +399,7 @@ unsafe fn direct_function_call_as_datum_internal( let result = if fcinfo.isnull { None } else { Some(result) }; pg_sys::pfree(fcinfo_ptr.cast()); - return result; + result } /// Same as [direct_pg_extern_function_call] but instead returns the direct `Option` instead diff --git a/pgrx/src/fn_call.rs b/pgrx/src/fn_call.rs index 383547bfd..547762880 100644 --- a/pgrx/src/fn_call.rs +++ b/pgrx/src/fn_call.rs @@ -51,7 +51,7 @@ unsafe impl FnCallArg for Arg { match self { Arg::Null => Ok(None), Arg::Value(v) => Ok(Clone::clone(v).into_datum()), - Arg::Default => create_default_value(&pg_proc, argnum), + Arg::Default => create_default_value(pg_proc, argnum), } } @@ -342,7 +342,7 @@ fn lookup_fn(fname: &str, args: &[&dyn FnCallArg]) -> Result { let nargs: i16 = arg_types.len().try_into().map_err(|_| FnCallError::TooManyArguments)?; // parse the function name into its possibly-qualified name parts - let ident_parts = parse_sql_ident(&fname)?; + let ident_parts = parse_sql_ident(fname)?; ident_parts .iter_deny_null() .map(|part| { diff --git a/pgrx/src/heap_tuple.rs b/pgrx/src/heap_tuple.rs index b39032e96..46a991e17 100644 --- a/pgrx/src/heap_tuple.rs +++ b/pgrx/src/heap_tuple.rs @@ -159,7 +159,7 @@ impl<'a> PgHeapTuple<'a, AllocatedByPostgres> { // from incorrect assignment from the `trigger_data.tg_trigtuple/tg_newtuple` fields above. // // IOW, we are double-checking that we're using those fields correctly - assert_eq!(tuple.is_null(), false, "encountered unexpected NULL trigger tuple"); + assert!(!tuple.is_null(), "encountered unexpected NULL trigger tuple"); unsafe { // SAFETY: The caller has asserted that `trigger_data` is valid, and that means its @@ -222,7 +222,7 @@ impl<'a> PgHeapTuple<'a, AllocatedByRust> { ) -> Result, PgHeapTupleError> { PgTryBuilder::new(|| { let tuple_desc = PgTupleDesc::for_composite_type_by_oid(typoid) - .ok_or_else(|| PgHeapTupleError::NotACompositeType(typoid))?; + .ok_or(PgHeapTupleError::NotACompositeType(typoid))?; let natts = tuple_desc.len(); unsafe { @@ -381,8 +381,7 @@ impl<'a> PgHeapTuple<'a, AllocatedByRust> { } } - let mut datums = - (0..self.tupdesc.len()).map(|i| pg_sys::Datum::from(i)).collect::>(); + let mut datums = (0..self.tupdesc.len()).map(pg_sys::Datum::from).collect::>(); let mut nulls = (0..self.tupdesc.len()).map(|_| false).collect::>(); let mut do_replace = (0..self.tupdesc.len()).map(|_| false).collect::>(); diff --git a/pgrx/src/layout.rs b/pgrx/src/layout.rs index ae7c87bba..b0bdd47aa 100644 --- a/pgrx/src/layout.rs +++ b/pgrx/src/layout.rs @@ -104,7 +104,6 @@ impl Align { #[inline] pub(crate) fn pad(self, size: usize) -> usize { - let size = size as usize; let align = self.as_usize(); (size + (align - 1)) & !(align - 1) } diff --git a/pgrx/src/list/old_list.rs b/pgrx/src/list/old_list.rs index 551bec8ae..34fe2ad97 100644 --- a/pgrx/src/list/old_list.rs +++ b/pgrx/src/list/old_list.rs @@ -162,17 +162,17 @@ impl PgList { #[inline] pub fn iter_ptr(&self) -> impl Iterator + '_ { - PgListIteratorPtr { list: &self, pos: 0 } + PgListIteratorPtr { list: self, pos: 0 } } #[inline] pub fn iter_oid(&self) -> impl Iterator + '_ { - PgListIteratorOid { list: &self, pos: 0 } + PgListIteratorOid { list: self, pos: 0 } } #[inline] pub fn iter_int(&self) -> impl Iterator + '_ { - PgListIteratorInt { list: &self, pos: 0 } + PgListIteratorInt { list: self, pos: 0 } } /// Add a pointer value to the end of this list diff --git a/pgrx/src/pg_catalog/pg_proc.rs b/pgrx/src/pg_catalog/pg_proc.rs index 273031a09..ed4157a5a 100644 --- a/pgrx/src/pg_catalog/pg_proc.rs +++ b/pgrx/src/pg_catalog/pg_proc.rs @@ -230,7 +230,7 @@ impl PgProc { self.get_attr::>(pg_sys::Anum_pg_proc_proargmodes) .unwrap_or_else(|| vec!['i' as i8; self.proargnames().len()]) .into_iter() - .map(|mode| ProArgMode::from(mode)) + .map(ProArgMode::from) .collect::>() } diff --git a/pgrx/src/rel.rs b/pgrx/src/rel.rs index 6442248d4..9a9ff0125 100644 --- a/pgrx/src/rel.rs +++ b/pgrx/src/rel.rs @@ -217,7 +217,7 @@ impl PgRelation { /// assert_eq!(tupdesc.len(), 12); /// ``` pub fn tuple_desc(&self) -> PgTupleDesc { - PgTupleDesc::from_relation(&self) + PgTupleDesc::from_relation(self) } /// Number of tuples in this relation (not always up-to-date) @@ -336,14 +336,10 @@ impl Deref for PgRelation { impl Drop for PgRelation { fn drop(&mut self) { - if !self.boxed.is_null() { - if self.need_close { - match self.lockmode { - None => unsafe { pg_sys::RelationClose(self.boxed.as_ptr()) }, - Some(lockmode) => unsafe { - pg_sys::relation_close(self.boxed.as_ptr(), lockmode) - }, - } + if !self.boxed.is_null() && self.need_close { + match self.lockmode { + None => unsafe { pg_sys::RelationClose(self.boxed.as_ptr()) }, + Some(lockmode) => unsafe { pg_sys::relation_close(self.boxed.as_ptr(), lockmode) }, } } } diff --git a/pgrx/src/spi/client.rs b/pgrx/src/spi/client.rs index fef6b10d0..a1f6f093f 100644 --- a/pgrx/src/spi/client.rs +++ b/pgrx/src/spi/client.rs @@ -95,7 +95,7 @@ impl<'conn> SpiClient<'conn> { /// /// See [`SpiCursor`] docs for usage details. pub fn open_cursor>(&self, query: Q, args: Q::Arguments) -> SpiCursor<'conn> { - query.open_cursor(&self, args) + query.open_cursor(self, args) } /// Set up a cursor that will execute the specified update (mutating) query diff --git a/pgrx/src/spi/cursor.rs b/pgrx/src/spi/cursor.rs index 4e1815341..9b7fd6ca1 100644 --- a/pgrx/src/spi/cursor.rs +++ b/pgrx/src/spi/cursor.rs @@ -79,7 +79,7 @@ impl SpiCursor<'_> { } // SAFETY: SPI functions to create/find cursors fail via elog, so self.ptr is valid if we successfully set it unsafe { pg_sys::SPI_cursor_fetch(self.ptr.as_mut(), true, count) } - Ok(SpiClient::prepare_tuple_table(SpiOkCodes::Fetch as i32)?) + SpiClient::prepare_tuple_table(SpiOkCodes::Fetch as i32) } /// Consume the cursor, returning its name diff --git a/pgrx/src/spi/query.rs b/pgrx/src/spi/query.rs index ebab9dabc..3a2145c1e 100644 --- a/pgrx/src/spi/query.rs +++ b/pgrx/src/spi/query.rs @@ -117,7 +117,7 @@ impl<'conn> Query<'conn> for &str { }, }; - Ok(SpiClient::prepare_tuple_table(status_code)?) + SpiClient::prepare_tuple_table(status_code) } fn open_cursor(self, _client: &SpiClient<'conn>, args: Self::Arguments) -> SpiCursor<'conn> { @@ -254,7 +254,7 @@ impl<'conn: 'stmt, 'stmt> Query<'conn> for &'stmt PreparedStatement<'conn> { ) }; - Ok(SpiClient::prepare_tuple_table(status_code)?) + SpiClient::prepare_tuple_table(status_code) } fn open_cursor(self, _client: &SpiClient<'conn>, args: Self::Arguments) -> SpiCursor<'conn> { diff --git a/pgrx/src/spi/tuple.rs b/pgrx/src/spi/tuple.rs index 83c458901..f049b0223 100644 --- a/pgrx/src/spi/tuple.rs +++ b/pgrx/src/spi/tuple.rs @@ -380,7 +380,7 @@ impl<'conn> SpiHeapTupleData<'conn> { pub fn get_datum_by_ordinal(&self, ordinal: usize) -> SpiResult<&SpiHeapTupleDataEntry<'conn>> { // Wrapping because `self.entries.get(...)` will bounds check. let index = ordinal.wrapping_sub(1); - self.entries.get(index).ok_or_else(|| SpiError::SpiError(SpiErrorCodes::NoAttribute)) + self.entries.get(index).ok_or(SpiError::SpiError(SpiErrorCodes::NoAttribute)) } /// Get a raw Datum from this HeapTuple by its field name. @@ -475,7 +475,7 @@ impl<'conn> SpiHeapTupleDataEntry<'conn> { false, self.type_oid, ) - .map_err(|e| SpiError::DatumError(e)) + .map_err(SpiError::DatumError) }, None => Ok(None), } diff --git a/pgrx/src/stringinfo.rs b/pgrx/src/stringinfo.rs index fc54925ba..1beabbee8 100644 --- a/pgrx/src/stringinfo.rs +++ b/pgrx/src/stringinfo.rs @@ -29,7 +29,7 @@ impl From> for &'static core: unsafe { core::ffi::CStr::from_bytes_with_nul_unchecked(std::slice::from_raw_parts( ptr as *const u8, - (len + 1) as usize, // +1 to get the trailing null byte + len + 1, // +1 to get the trailing null byte )) } } diff --git a/pgrx/src/toast.rs b/pgrx/src/toast.rs index 76798a957..2dcb160f7 100644 --- a/pgrx/src/toast.rs +++ b/pgrx/src/toast.rs @@ -48,8 +48,8 @@ impl Deref for Toast { fn deref(&self) -> &Self::Target { match self { - Toast::Stale(t) => &t, - Toast::Fresh(t) => &t, + Toast::Stale(t) => t, + Toast::Fresh(t) => t, } } } diff --git a/pgrx/src/tupdesc.rs b/pgrx/src/tupdesc.rs index 315c6f1a9..9a5398ee9 100644 --- a/pgrx/src/tupdesc.rs +++ b/pgrx/src/tupdesc.rs @@ -259,12 +259,7 @@ impl<'a> Clone for PgTupleDesc<'a> { // This will force the pfree() approach upon drop let tupdesc = unsafe { PgBox::from_pg(pg_sys::CreateTupleDescCopyConstr(tupdesc.as_ptr())) }; - Self { - tupdesc: Some(tupdesc), - parent: self.parent.clone(), - need_release: false, - need_pfree: true, - } + Self { tupdesc: Some(tupdesc), parent: self.parent, need_release: false, need_pfree: true } } }