diff --git a/pgrx-pg-sys/build.rs b/pgrx-pg-sys/build.rs index c1cf65777b..3fa3e4bf6c 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/port.rs b/pgrx-pg-sys/src/port.rs index a926a9835e..8f52834ceb 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 951af93757..c9c81aa78a 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 231bd2ebb7..b1b0a66372 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 c74f455430..9fe6975a7b 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 d8cfdbd050..248144abe2 100644 --- a/pgrx-pg-sys/src/submodules/htup.rs +++ b/pgrx-pg-sys/src/submodules/htup.rs @@ -271,7 +271,7 @@ unsafe fn fetch_att(T: *mut std::os::raw::c_char, attbyval: bool, attlen: i16) - } else { assert_eq!(attlen, 1); Datum::from(*T.cast::()) - } + } } } else { Datum::from(T.cast::()) @@ -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 b1b851042c..e77853a16f 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]