From 2f156658d0a1a887ac25f682f73b4de28a855750 Mon Sep 17 00:00:00 2001 From: Jubilee <46493976+workingjubilee@users.noreply.github.com> Date: Fri, 27 Oct 2023 19:04:35 -0700 Subject: [PATCH] Satisfy clippy errors on 7 of 8 crates (#1358) This does more cleanup in the vein of weakening needless bounds. - https://github.com/pgcentralfoundation/pgrx/pull/1355 The "main point" is some no-op "make clippy happy" refactoring. This permits running `cargo clippy` without getting *errors* (it still issues literally hundreds of warnings) on most of the repository's crates. It does not solve this for `pgrx` itself, as clippy detected a more serious issue there, and that issue is instead its own PR: - https://github.com/pgcentralfoundation/pgrx/pull/1357 --- cargo-pgrx/src/manifest.rs | 62 +++++++++---------- pgrx-examples/custom_types/src/ordered.rs | 7 ++- pgrx-pg-sys/build.rs | 26 +++++--- pgrx-pg-sys/src/cshim.rs | 4 +- pgrx-tests/src/tests/zero_datum_edge_cases.rs | 2 +- pgrx/src/array.rs | 4 +- pgrx/src/datum/array.rs | 6 +- pgrx/src/heap_tuple.rs | 5 +- 8 files changed, 62 insertions(+), 54 deletions(-) diff --git a/cargo-pgrx/src/manifest.rs b/cargo-pgrx/src/manifest.rs index 9b52fddab..8b38c45ad 100644 --- a/cargo-pgrx/src/manifest.rs +++ b/cargo-pgrx/src/manifest.rs @@ -125,51 +125,49 @@ pub(crate) fn pg_config_and_version<'a>( user_features: Option<&mut Features>, verbose: bool, ) -> eyre::Result<(PgConfig, PgVersionSource)> { - let pg_version = { - 'outer: loop { - if let Some(pg_version) = specified_pg_version { - // the user gave us an explicit Postgres version to use, so we will - break 'outer Some(PgVersionSource::CliArgument(pg_version)); - } else if let Some(features) = user_features.as_ref() { - // the user did not give us an explicit Postgres version, so see if there's one in the set - // of `--feature` flags they gave us - for flag in &features.features { - if pgrx.is_feature_flag(flag) { - // use the first feature flag that is a Postgres version we support - break 'outer Some(PgVersionSource::FeatureFlag(flag.clone())); - } + let pg_version = || { + if let Some(pg_version) = specified_pg_version { + // the user gave us an explicit Postgres version to use, so we will + return Some(PgVersionSource::CliArgument(pg_version)); + } else if let Some(features) = user_features.as_ref() { + // the user did not give us an explicit Postgres version, so see if there's one in the set + // of `--feature` flags they gave us + for flag in &features.features { + if pgrx.is_feature_flag(flag) { + // use the first feature flag that is a Postgres version we support + return Some(PgVersionSource::FeatureFlag(flag.clone())); } + } - // user didn't give us a feature flag that is a Postgres version + // user didn't give us a feature flag that is a Postgres version - // if they didn't ask for `--no-default-features` lets see if we have a default - // postgres version feature specified in the manifest - if !features.no_default_features { - if let Some(default_features) = manifest.features.get("default") { - for flag in default_features { - if pgrx.is_feature_flag(flag) { - break 'outer Some(PgVersionSource::DefaultFeature(flag.clone())); - } - } - } - } - } else { - // lets check the manifest for a default feature + // if they didn't ask for `--no-default-features` lets see if we have a default + // postgres version feature specified in the manifest + if !features.no_default_features { if let Some(default_features) = manifest.features.get("default") { for flag in default_features { if pgrx.is_feature_flag(flag) { - break 'outer Some(PgVersionSource::DefaultFeature(flag.clone())); + return Some(PgVersionSource::DefaultFeature(flag.clone())); } } } } - - // we cannot determine the Postgres version the user wants to use - break 'outer None; + } else { + // lets check the manifest for a default feature + if let Some(default_features) = manifest.features.get("default") { + for flag in default_features { + if pgrx.is_feature_flag(flag) { + return Some(PgVersionSource::DefaultFeature(flag.clone())); + } + } + } } + + // we cannot determine the Postgres version the user wants to use + None }; - match pg_version { + match pg_version() { Some(pg_version) => { // we have determined a Postgres version diff --git a/pgrx-examples/custom_types/src/ordered.rs b/pgrx-examples/custom_types/src/ordered.rs index 9c1684b19..6f2f6ddcd 100644 --- a/pgrx-examples/custom_types/src/ordered.rs +++ b/pgrx-examples/custom_types/src/ordered.rs @@ -19,7 +19,6 @@ use std::cmp::Ordering; Clone, Eq, PartialEq, - PartialOrd, PostgresType, PostgresEq, PostgresOrd @@ -51,6 +50,12 @@ impl Ord for OrderedThing { } } +impl PartialOrd for OrderedThing { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + #[cfg(any(test, feature = "pg_test"))] #[pg_schema] mod tests { diff --git a/pgrx-pg-sys/build.rs b/pgrx-pg-sys/build.rs index b8a9e5eae..b75b77845 100644 --- a/pgrx-pg-sys/build.rs +++ b/pgrx-pg-sys/build.rs @@ -57,6 +57,20 @@ impl PgrxOverrides { "FP_SUBNORMAL".into(), "FP_ZERO".into(), "IPPORT_RESERVED".into(), + // These are just annoying due to clippy + "M_E".into(), + "M_LOG2E".into(), + "M_LOG10E".into(), + "M_LN2".into(), + "M_LN10".into(), + "M_PI".into(), + "M_PI_2".into(), + "M_PI_4".into(), + "M_1_PI".into(), + "M_2_PI".into(), + "M_SQRT2".into(), + "M_SQRT1_2".into(), + "M_2_SQRTPI".into(), ] .into_iter() .collect(), @@ -383,15 +397,9 @@ fn extract_oids(code: &syn::File) -> BTreeMap> { } fn is_builtin_oid(name: &str) -> bool { - if name.ends_with("OID") && name != "HEAP_HASOID" { - true - } else if name.ends_with("RelationId") { - true - } else if name == "TemplateDbOid" { - true - } else { - false - } + name.ends_with("OID") && name != "HEAP_HASOID" + || name.ends_with("RelationId") + || name == "TemplateDbOid" } fn rewrite_oid_consts( diff --git a/pgrx-pg-sys/src/cshim.rs b/pgrx-pg-sys/src/cshim.rs index 36ebe2cac..f656e223e 100644 --- a/pgrx-pg-sys/src/cshim.rs +++ b/pgrx-pg-sys/src/cshim.rs @@ -12,7 +12,7 @@ extern "C" { pub fn pgrx_list_nth_cell(list: *mut pg_sys::List, nth: i32) -> *mut pg_sys::ListCell; #[link_name = "pgrx_planner_rt_fetch"] - #[deprecated(since = "0.11", note = "use pgrx::pg_sys::planner_rt_fetch")] + #[deprecated(since = "0.11.0", note = "use pgrx::pg_sys::planner_rt_fetch")] pub fn planner_rt_fetch( index: pg_sys::Index, root: *mut pg_sys::PlannerInfo, @@ -33,7 +33,7 @@ extern "C" { /// ((RangeTblEntry *) list_nth(rangetable, (rangetable_index)-1)) /// ``` #[inline] -#[deprecated(since = "0.11", note = "use pgrx::pg_sys::rt_fetch")] +#[deprecated(since = "0.11.0", note = "use pgrx::pg_sys::rt_fetch")] pub unsafe fn rt_fetch( index: super::Index, range_table: *mut super::List, diff --git a/pgrx-tests/src/tests/zero_datum_edge_cases.rs b/pgrx-tests/src/tests/zero_datum_edge_cases.rs index 303818230..d61326eae 100644 --- a/pgrx-tests/src/tests/zero_datum_edge_cases.rs +++ b/pgrx-tests/src/tests/zero_datum_edge_cases.rs @@ -14,7 +14,7 @@ mod tests { use crate as pgrx_tests; use pgrx::prelude::*; - fn from_helper(d: pg_sys::Datum) -> Option { + fn from_helper(d: pg_sys::Datum) -> Option { unsafe { T::from_polymorphic_datum(d, false, pg_sys::InvalidOid) } } diff --git a/pgrx/src/array.rs b/pgrx/src/array.rs index 589fbf985..3352ebf63 100644 --- a/pgrx/src/array.rs +++ b/pgrx/src/array.rs @@ -7,7 +7,7 @@ //LICENSE All rights reserved. //LICENSE //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file. -use crate::datum::{Array, FromDatum}; +use crate::datum::Array; use crate::pg_sys; use crate::toast::{Toast, Toasty}; use bitvec::prelude::*; @@ -273,7 +273,7 @@ impl RawArray { /// # Safety /// Array must have been made from an ArrayType pointer, /// or a null value, as-if [RawArray::from_ptr]. - pub unsafe fn from_array(arr: Array) -> Option { + pub unsafe fn from_array(arr: Array) -> Option { let array_type = arr.into_array_type() as *mut _; // SAFETY: Validity asserted by the caller. let len = unsafe { ARR_NELEMS(array_type) } as usize; diff --git a/pgrx/src/datum/array.rs b/pgrx/src/datum/array.rs index ba520ba3c..5f47b7576 100644 --- a/pgrx/src/datum/array.rs +++ b/pgrx/src/datum/array.rs @@ -549,7 +549,7 @@ impl<'a, T: FromDatum> VariadicArray<'a, T> { } } -pub struct ArrayTypedIterator<'a, T: 'a + FromDatum> { +pub struct ArrayTypedIterator<'a, T: 'a> { array: &'a Array<'a, T>, curr: usize, ptr: *const u8, @@ -592,7 +592,7 @@ impl<'a, T: FromDatum + serde::Serialize> serde::Serialize for ArrayTypedIterato } } -pub struct ArrayIterator<'a, T: 'a + FromDatum> { +pub struct ArrayIterator<'a, T: 'a> { array: &'a Array<'a, T>, curr: usize, ptr: *const u8, @@ -627,7 +627,7 @@ impl<'a, T: FromDatum> Iterator for ArrayIterator<'a, T> { impl<'a, T: FromDatum> ExactSizeIterator for ArrayIterator<'a, T> {} impl<'a, T: FromDatum> core::iter::FusedIterator for ArrayIterator<'a, T> {} -pub struct ArrayIntoIterator<'a, T: FromDatum> { +pub struct ArrayIntoIterator<'a, T> { array: Array<'a, T>, curr: usize, ptr: *const u8, diff --git a/pgrx/src/heap_tuple.rs b/pgrx/src/heap_tuple.rs index 86860355c..b39032e96 100644 --- a/pgrx/src/heap_tuple.rs +++ b/pgrx/src/heap_tuple.rs @@ -76,10 +76,7 @@ impl<'a> FromDatum for PgHeapTuple<'a, AllocatedByRust> { composite: Datum, is_null: bool, _oid: pg_sys::Oid, - ) -> Option - where - Self: Sized, - { + ) -> Option { if is_null { None } else {