Skip to content

Commit

Permalink
clippy --fix pgrx-pg-sys except bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Oct 31, 2023
1 parent 116bc7b commit 2def3bd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 deletions.
24 changes: 12 additions & 12 deletions pgrx-pg-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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::<Vec<String>>()
.join(", ")
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -405,7 +405,7 @@ fn rewrite_oid_consts(
oids: &BTreeMap<syn::Ident, Box<syn::Expr>>,
) -> Vec<syn::Item> {
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) =>
Expand Down Expand Up @@ -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
};
Expand All @@ -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()))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1042,7 +1042,7 @@ fn apply_pg_guard(items: &Vec<syn::Item>) -> eyre::Result<proc_macro2::TokenStre
Item::ForeignMod(block) => {
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),
Expand Down Expand Up @@ -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),
}
}
3 changes: 1 addition & 2 deletions pgrx-pg-sys/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions pgrx-pg-sys/src/submodules/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl TryFrom<NullableDatum> for Datum {
impl From<NullableDatum> for Option<Datum> {
#[inline]
fn from(nd: NullableDatum) -> Option<Datum> {
Some(Datum::try_from(nd).ok()?)
Datum::try_from(nd).ok()
}
}

Expand Down Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions pgrx-pg-sys/src/submodules/errcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,15 +1280,15 @@ impl From<isize> 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)
}
8 changes: 4 additions & 4 deletions pgrx-pg-sys/src/submodules/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ unsafe fn pg_guard_ffi_boundary_impl<T, F: FnOnce() -> 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

Expand All @@ -148,13 +148,13 @@ unsafe fn pg_guard_ffi_boundary_impl<T, F: FnOnce() -> T>(f: F) -> T {
.is_null()
.then(|| String::from("<null error message>"))
.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 =
Expand Down
12 changes: 5 additions & 7 deletions pgrx-pg-sys/src/submodules/htup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<std::os::raw::c_char>())
}
}
}
} else {
Datum::from(T.cast::<std::os::raw::c_char>())
Expand Down Expand Up @@ -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)
}
}
}
6 changes: 3 additions & 3 deletions pgrx-pg-sys/src/submodules/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 2def3bd

Please sign in to comment.