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

Satisfy clippy errors on 7 of 8 crates #1358

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
62 changes: 30 additions & 32 deletions cargo-pgrx/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion pgrx-examples/custom_types/src/ordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::cmp::Ordering;
Clone,
Eq,
PartialEq,
PartialOrd,
PostgresType,
PostgresEq,
PostgresOrd
Expand Down Expand Up @@ -51,6 +50,12 @@ impl Ord for OrderedThing {
}
}

impl PartialOrd for OrderedThing {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(any(test, feature = "pg_test"))]
#[pg_schema]
mod tests {
Expand Down
26 changes: 17 additions & 9 deletions pgrx-pg-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -383,15 +397,9 @@ fn extract_oids(code: &syn::File) -> BTreeMap<syn::Ident, Box<syn::Expr>> {
}

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(
Expand Down
4 changes: 2 additions & 2 deletions pgrx-pg-sys/src/cshim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pgrx-tests/src/tests/zero_datum_edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tests {
use crate as pgrx_tests;
use pgrx::prelude::*;

fn from_helper<T: FromDatum + IntoDatum>(d: pg_sys::Datum) -> Option<T> {
fn from_helper<T: FromDatum>(d: pg_sys::Datum) -> Option<T> {
unsafe { T::from_polymorphic_datum(d, false, pg_sys::InvalidOid) }
}

Expand Down
4 changes: 2 additions & 2 deletions pgrx/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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<T: FromDatum>(arr: Array<T>) -> Option<RawArray> {
pub unsafe fn from_array<T>(arr: Array<T>) -> Option<RawArray> {
let array_type = arr.into_array_type() as *mut _;
// SAFETY: Validity asserted by the caller.
let len = unsafe { ARR_NELEMS(array_type) } as usize;
Expand Down
6 changes: 3 additions & 3 deletions pgrx/src/datum/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions pgrx/src/heap_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ impl<'a> FromDatum for PgHeapTuple<'a, AllocatedByRust> {
composite: Datum,
is_null: bool,
_oid: pg_sys::Oid,
) -> Option<Self>
where
Self: Sized,
{
) -> Option<Self> {
if is_null {
None
} else {
Expand Down