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

clippy --fix pgrx libraries #1366

Merged
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
5 changes: 2 additions & 3 deletions pgrx-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<TokenStream, syn::Error> {
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())
}
Expand Down
3 changes: 1 addition & 2 deletions pgrx-macros/src/rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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),
}
}
5 changes: 5 additions & 0 deletions pgrx-pg-sys/src/include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,39 @@

#[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))]
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))]
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))]
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))]
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))]
Expand Down
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
10 changes: 4 additions & 6 deletions pgrx-pg-sys/src/submodules/htup.rs
Original file line number Diff line number Diff line change
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
Loading