From 1d887c5885179406b30e499d07ef65ab34fd3005 Mon Sep 17 00:00:00 2001 From: Thomas Hatzopoulos Date: Wed, 7 Sep 2022 11:40:56 -0500 Subject: [PATCH] clippy fixes --- crates/asap/src/lib.rs | 8 ++++---- crates/counter-agg/src/lib.rs | 2 +- crates/counter-agg/src/range.rs | 2 +- crates/counter-agg/src/tests.rs | 4 ++-- crates/flat_serialize/flat_serialize/src/lib.rs | 4 ++-- .../flat_serialize/flat_serialize_macro/src/lib.rs | 2 +- crates/hyperloglogplusplus/src/dense.rs | 4 ++-- crates/hyperloglogplusplus/src/lib.rs | 4 ++-- crates/hyperloglogplusplus/src/registers.rs | 14 ++++++++------ crates/hyperloglogplusplus/src/sparse.rs | 6 +++--- crates/hyperloglogplusplus/src/sparse/varint.rs | 2 +- crates/stats-agg/src/lib.rs | 2 +- crates/t-digest/src/lib.rs | 5 ++--- crates/time-weighted-average/src/lib.rs | 4 ++-- crates/tspoint/src/lib.rs | 2 +- crates/udd-sketch/src/lib.rs | 6 +++--- extension/src/hyperloglog.rs | 2 +- extension/src/range.rs | 2 +- extension/src/state_aggregate.rs | 2 +- extension/src/tdigest.rs | 2 +- extension/src/time_vector.rs | 2 +- extension/src/time_vector/pipeline/fill_to.rs | 2 +- tools/post-install/src/update_script.rs | 1 + tools/sql-doctester/src/runner.rs | 2 +- tools/testrunner/src/main.rs | 4 ++-- 25 files changed, 46 insertions(+), 44 deletions(-) diff --git a/crates/asap/src/lib.rs b/crates/asap/src/lib.rs index 049cb522..ab4eafa7 100644 --- a/crates/asap/src/lib.rs +++ b/crates/asap/src/lib.rs @@ -317,13 +317,13 @@ mod tests { assert!(mean(&series_c).abs() < 0.000000000001); // float precision breaks == 0 here assert_eq!(std(&series_c), 1.0); - let test = Metrics::new(&&series_a); - assert_eq!(test.roughness(), (((3.0 * (1.6 as f64).powi(2) + 2.0 * (2.4 as f64).powi(2)) / 5.0)).sqrt()); + let test = Metrics::new(&series_a); + assert_eq!(test.roughness(), (((3.0 * 1.6_f64.powi(2) + 2.0 * 2.4_f64.powi(2)) / 5.0)).sqrt()); assert_eq!(test.kurtosis(), 1.0); - let test = Metrics::new(&&series_b); + let test = Metrics::new(&series_b); assert_eq!(test.roughness(), 0.4686099077599554); // manually verified assert!((test.kurtosis() - 2.7304).abs() < 0.000000000001); // = 2.7304 - let test = Metrics::new(&&series_c); + let test = Metrics::new(&series_c); assert_eq!(test.roughness(), 0.0); assert!((test.kurtosis() - 1.7).abs() < 0.000000000001); // == 1.7 } diff --git a/crates/counter-agg/src/lib.rs b/crates/counter-agg/src/lib.rs index f65bcda3..d07ea66f 100644 --- a/crates/counter-agg/src/lib.rs +++ b/crates/counter-agg/src/lib.rs @@ -10,7 +10,7 @@ pub mod range; #[cfg(test)] mod tests; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum CounterError{ OrderError, BoundsInvalid, diff --git a/crates/counter-agg/src/range.rs b/crates/counter-agg/src/range.rs index e6782f30..a5cb5da7 100644 --- a/crates/counter-agg/src/range.rs +++ b/crates/counter-agg/src/range.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; // we are a discrete type so translating is simple [), this enforces equality // between ranges like [0, 10) and [0, 9] // None values denote infinite bounds on that side -#[derive(Debug, PartialEq, Copy, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)] #[repr(C)] pub struct I64Range { pub left: Option, diff --git a/crates/counter-agg/src/tests.rs b/crates/counter-agg/src/tests.rs index 5393ef6b..25edc21c 100644 --- a/crates/counter-agg/src/tests.rs +++ b/crates/counter-agg/src/tests.rs @@ -90,7 +90,7 @@ #[test] fn test_counter_delta(){ let startpt = &TSPoint{ts: 0, val:10.0}; - let mut summary = CounterSummaryBuilder::new(&startpt, None); + let mut summary = CounterSummaryBuilder::new(startpt, None); // with one point assert_relative_eq!(summary.clone().build().delta(), 0.0); @@ -148,7 +148,7 @@ assert_close_enough(&summary.build(), &combined.build()); // test error in wrong direction - combined = part2.clone(); + combined = part2; assert_eq!(combined.combine(&part1.build()).unwrap_err(), CounterError::OrderError); } #[test] diff --git a/crates/flat_serialize/flat_serialize/src/lib.rs b/crates/flat_serialize/flat_serialize/src/lib.rs index 1f13ec87..38aec2ca 100644 --- a/crates/flat_serialize/flat_serialize/src/lib.rs +++ b/crates/flat_serialize/flat_serialize/src/lib.rs @@ -206,7 +206,7 @@ impl <'input, T: 'input> Slice<'input, T> { match self { Slice::Iter(iter) => Iter::Unflatten(*iter), Slice::Slice(slice) => Iter::Slice(slice), - Slice::Owned(vec) => Iter::Slice(&*vec), + Slice::Owned(vec) => Iter::Slice(vec), } } } @@ -394,7 +394,7 @@ impl<'input, T: 'input> Slice<'input, T> { Slice::Iter(_) => panic!("cannot convert iterator to slice without mutating"), Slice::Slice(s) => *s, - Slice::Owned(o) => &*o, + Slice::Owned(o) => o, } } diff --git a/crates/flat_serialize/flat_serialize_macro/src/lib.rs b/crates/flat_serialize/flat_serialize_macro/src/lib.rs index 9d746896..17896213 100644 --- a/crates/flat_serialize/flat_serialize_macro/src/lib.rs +++ b/crates/flat_serialize/flat_serialize_macro/src/lib.rs @@ -992,7 +992,7 @@ impl FlatSerializeField { let name = self.ident.as_ref().unwrap(); // based on static_assertions // TODO add ConstLen assertion if type is in var-len position? - return quote_spanned!{self.ty.span()=> + quote_spanned!{self.ty.span()=> fn #name<'test, T: flat_serialize::FlatSerializable<'test>>() {} let _ = #name::<#ty #lifetime>; } diff --git a/crates/hyperloglogplusplus/src/dense.rs b/crates/hyperloglogplusplus/src/dense.rs index 6874a647..4ff2bc53 100644 --- a/crates/hyperloglogplusplus/src/dense.rs +++ b/crates/hyperloglogplusplus/src/dense.rs @@ -6,7 +6,7 @@ use crate::hyperloglog_data::{ use crate::{registers::Registers, Extractable}; #[derive(Clone)] -#[derive(serde::Serialize, serde::Deserialize, PartialEq)] +#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq)] pub struct Storage<'s> { pub registers: Registers<'s>, // TODO can be derived from block.len() @@ -528,6 +528,6 @@ mod tests { return false; } - return true; + true } } diff --git a/crates/hyperloglogplusplus/src/lib.rs b/crates/hyperloglogplusplus/src/lib.rs index 3d3f268f..e28dd998 100644 --- a/crates/hyperloglogplusplus/src/lib.rs +++ b/crates/hyperloglogplusplus/src/lib.rs @@ -14,14 +14,14 @@ mod hyperloglog_data; pub mod registers; pub mod sparse; -#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq)] +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] pub struct HyperLogLog<'s, T: ?Sized, B> { storage: HyperLogLogStorage<'s>, pub buildhasher: B, _pd: PhantomData, } -#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq)] +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] pub enum HyperLogLogStorage<'s> { Sparse(sparse::Storage<'s>), Dense(dense::Storage<'s>), diff --git a/crates/hyperloglogplusplus/src/registers.rs b/crates/hyperloglogplusplus/src/registers.rs index 9287ea97..e66857aa 100644 --- a/crates/hyperloglogplusplus/src/registers.rs +++ b/crates/hyperloglogplusplus/src/registers.rs @@ -19,7 +19,7 @@ use std::{borrow::Cow, convert::TryInto, debug_assert}; // and treat the block like a regular integer, using shifts to get the // values in and out #[derive(Clone)] -#[derive(serde::Serialize, serde::Deserialize, PartialEq)] +#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq)] pub struct Registers<'s>(Cow<'s, [u8]>); impl<'s> Registers<'s> { @@ -51,7 +51,7 @@ impl<'s> Registers<'s> { // TODO switch chunks_exact_mut() to as_chunks_mut() once stable? let block_num = idx / 4; let idx_in_block = idx % 4; - let block = self.0.chunks_exact(3).skip(block_num).next().unwrap(); + let block = self.0.chunks_exact(3).nth(block_num).unwrap(); let block = u32::from_be_bytes([block[0], block[1], block[2], 0x0]); let value = block >> (8 + 6 * (3 - idx_in_block)); (value & 0x3f) as u8 @@ -107,7 +107,7 @@ impl<'s> Registers<'s> { self.0.chunks_exact(3).flat_map(|bytes| { const LOW_REG_MASK: u32 = (1 << 6) - 1; - let [a, b, c]: [u8; 3] = (&*bytes).try_into().unwrap(); + let [a, b, c]: [u8; 3] = bytes.try_into().unwrap(); let block = u32::from_be_bytes([a, b, c, 0x0]); // TODO replace with // ``` @@ -303,10 +303,12 @@ mod test { } #[quickcheck] - fn quick_merge(exp: u8, ops_a: Vec<(usize, u8)>, ops_b: Vec<(usize, u8)>) - -> quickcheck::TestResult { + fn quick_merge( + exp: u8, + ops_a: Vec<(usize, u8)>, + ops_b: Vec<(usize, u8)>, + ) -> quickcheck::TestResult { use quickcheck::TestResult; - if exp < 4 || exp > 16 { return TestResult::discard(); } diff --git a/crates/hyperloglogplusplus/src/sparse.rs b/crates/hyperloglogplusplus/src/sparse.rs index 200737ea..4200e029 100644 --- a/crates/hyperloglogplusplus/src/sparse.rs +++ b/crates/hyperloglogplusplus/src/sparse.rs @@ -12,7 +12,7 @@ use self::varint::*; mod varint; -#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq)] +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] pub struct Storage<'s> { to_merge: HashSet, pub compressed: Compressed<'s>, @@ -367,7 +367,7 @@ mod tests { ); return TestResult::failed(); } - return TestResult::passed(); + TestResult::passed() } #[quickcheck] @@ -400,7 +400,7 @@ mod tests { ); return TestResult::failed(); } - return TestResult::passed(); + TestResult::passed() } // fn encoded_order() { diff --git a/crates/hyperloglogplusplus/src/sparse/varint.rs b/crates/hyperloglogplusplus/src/sparse/varint.rs index b5304fd6..91cc1358 100644 --- a/crates/hyperloglogplusplus/src/sparse/varint.rs +++ b/crates/hyperloglogplusplus/src/sparse/varint.rs @@ -12,7 +12,7 @@ pub fn decompression_iter<'a, 'b>(Compressed(bytes): &'a Compressed<'b>) -> impl } #[derive(Default)] -#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq)] +#[derive(serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq)] pub struct Compressed<'c>(Cow<'c, [u8]>); impl<'c> Compressed<'c> { diff --git a/crates/stats-agg/src/lib.rs b/crates/stats-agg/src/lib.rs index 3acc2ae1..1266ef71 100644 --- a/crates/stats-agg/src/lib.rs +++ b/crates/stats-agg/src/lib.rs @@ -6,7 +6,7 @@ // https://github.com/postgres/postgres/blob/472e518a44eacd9caac7d618f1b6451672ca4481/src/backend/utils/adt/float.c#L3260 // -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum StatsError { DoubleOverflow, } diff --git a/crates/t-digest/src/lib.rs b/crates/t-digest/src/lib.rs index d15da04d..3b9a6ea6 100644 --- a/crates/t-digest/src/lib.rs +++ b/crates/t-digest/src/lib.rs @@ -897,7 +897,7 @@ mod tests { for i in 1..=100 { buffer.push(i as f64); if buffer.len() >= digested.max_size() { - let new = std::mem::replace(&mut buffer, vec![]); + let new = std::mem::take(&mut buffer); digested = digested.merge_unsorted(new) } } @@ -961,8 +961,7 @@ mod tests { .iter() .chain(batch2.iter()) .chain(batch3.iter()) - .chain(batch4.iter()) - .map(|x| *x) + .chain(batch4.iter()).copied() .collect(); master.sort_by(|a, b| a.partial_cmp(b).unwrap()); diff --git a/crates/time-weighted-average/src/lib.rs b/crates/time-weighted-average/src/lib.rs index d97af241..03a65b48 100644 --- a/crates/time-weighted-average/src/lib.rs +++ b/crates/time-weighted-average/src/lib.rs @@ -3,7 +3,7 @@ use tspoint::TSPoint; use flat_serialize_macro::FlatSerializable; -#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize, FlatSerializable)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, FlatSerializable)] #[repr(u8)] pub enum TimeWeightMethod { LOCF = 0, @@ -18,7 +18,7 @@ pub struct TimeWeightSummary { pub w_sum: f64, } -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] pub enum TimeWeightError { OrderError, DoubleOverflow, // do we need to do this? diff --git a/crates/tspoint/src/lib.rs b/crates/tspoint/src/lib.rs index e9f3ae14..99c5bd4a 100644 --- a/crates/tspoint/src/lib.rs +++ b/crates/tspoint/src/lib.rs @@ -11,7 +11,7 @@ pub struct TSPoint { pub val: f64, } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum TSPointError { TimesEqualInterpolate, } diff --git a/crates/udd-sketch/src/lib.rs b/crates/udd-sketch/src/lib.rs index 53634d67..b9575495 100644 --- a/crates/udd-sketch/src/lib.rs +++ b/crates/udd-sketch/src/lib.rs @@ -488,14 +488,14 @@ mod tests { assert_eq!(sketch.count(), 2); assert_eq!(sketch.max_error(), 0.1); for i in 2..20 { - sketch.add_value(1000.0 * (1.23 as f64).powi(i)); + sketch.add_value(1000.0 * 1.23_f64.powi(i)); } assert_eq!(sketch.count(), 20); assert_eq!(sketch.max_error(), 0.1); for i in 20..30 { - sketch.add_value(1000.0 * (1.23 as f64).powi(i)); + sketch.add_value(1000.0 * 1.23_f64.powi(i)); } assert_eq!(sketch.count(), 30); @@ -565,7 +565,7 @@ mod tests { let mut sketch5 = UDDSketch::new(20, 0.1); for i in 100..220 { - sketch5.add_value((1.23 as f64).powi(i)); + sketch5.add_value(1.23_f64.powi(i)); } assert_eq!(sketch5.max_error(), a4); diff --git a/extension/src/hyperloglog.rs b/extension/src/hyperloglog.rs index 9b6553c5..77ad74b8 100644 --- a/extension/src/hyperloglog.rs +++ b/extension/src/hyperloglog.rs @@ -21,7 +21,7 @@ use crate::{ use hyperloglogplusplus::{HyperLogLog as HLL, HyperLogLogStorage}; -#[derive(Serialize, Deserialize, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)] pub struct HyperLogLogTrans { logger: HLL<'static, Datum, DatumHashBuilder>, } diff --git a/extension/src/range.rs b/extension/src/range.rs index dda45aa7..5dc888a4 100644 --- a/extension/src/range.rs +++ b/extension/src/range.rs @@ -93,7 +93,7 @@ fn rbound_inclusive(flags: u8) -> bool { // } // ``` flat_serialize! { - #[derive(Debug, PartialEq, Serialize, Deserialize)] + #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] struct I64RangeWrapper { is_present: u8, has_left: u8, diff --git a/extension/src/state_aggregate.rs b/extension/src/state_aggregate.rs index 6ab696c1..758ab7f6 100644 --- a/extension/src/state_aggregate.rs +++ b/extension/src/state_aggregate.rs @@ -270,7 +270,7 @@ impl toolkit_experimental::state_agg { } // Intermediate state kept in postgres. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct StateAggTransState { records: Vec, } diff --git a/extension/src/tdigest.rs b/extension/src/tdigest.rs index cb663fa0..e2145e83 100644 --- a/extension/src/tdigest.rs +++ b/extension/src/tdigest.rs @@ -200,7 +200,7 @@ impl<'input> TDigest<'input> { sum: digest.sum(), min: digest.min(), max: digest.max(), - centroids: (&*centroids).into(), + centroids: centroids.into(), } ) } diff --git a/extension/src/time_vector.rs b/extension/src/time_vector.rs index 3e91f085..801dc48b 100644 --- a/extension/src/time_vector.rs +++ b/extension/src/time_vector.rs @@ -74,7 +74,7 @@ impl<'input> Timevector_TSTZ_F64<'input> { } fn clone_owned(&self) -> Timevector_TSTZ_F64<'static> { - Timevector_TSTZ_F64Data::clone(&*self).into_owned().into() + Timevector_TSTZ_F64Data::clone(self).into_owned().into() } } diff --git a/extension/src/time_vector/pipeline/fill_to.rs b/extension/src/time_vector/pipeline/fill_to.rs index b81b0926..208f32bf 100644 --- a/extension/src/time_vector/pipeline/fill_to.rs +++ b/extension/src/time_vector/pipeline/fill_to.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use super::*; // TODO: there are one or two other gapfill objects in this extension, these should be unified -#[derive(Clone, Serialize, Deserialize, PartialEq, Debug, FlatSerializable)] +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug, FlatSerializable)] #[repr(u64)] pub enum FillToMethod { Locf, diff --git a/tools/post-install/src/update_script.rs b/tools/post-install/src/update_script.rs index eefc1ad0..c177064f 100644 --- a/tools/post-install/src/update_script.rs +++ b/tools/post-install/src/update_script.rs @@ -146,6 +146,7 @@ where // find which of a number of matchers a str starts with, and return the // rest. In other words, if find the first matcher matcher such that the // str is ` ` and return the `` + #[allow(clippy::type_complexity)] fn match_start( line: &str, matchers: [(&str, &mut dyn FnMut(&str) -> T); N], diff --git a/tools/sql-doctester/src/runner.rs b/tools/sql-doctester/src/runner.rs index 55c86acd..7b49ad03 100644 --- a/tools/sql-doctester/src/runner.rs +++ b/tools/sql-doctester/src/runner.rs @@ -92,7 +92,7 @@ pub fn run_tests( if let (Some(db), Some(startup_script)) = (stateless_db.as_ref(), startup_script) { let stateless_connection_config = ConnectionConfig { - database: Some(&*db), + database: Some(db), ..connection_config }; let mut client = Client::connect(&stateless_connection_config.config_string(), NoTls) diff --git a/tools/testrunner/src/main.rs b/tools/testrunner/src/main.rs index c7564026..73f2a894 100644 --- a/tools/testrunner/src/main.rs +++ b/tools/testrunner/src/main.rs @@ -41,14 +41,14 @@ fn main() { let db_name = "_ta_temp_testrunner_db"; let dropper = Deferred(move || { - let mut dropper = Client::connect(&*root_connection_config, NoTls) + let mut dropper = Client::connect(root_connection_config, NoTls) .expect("cannot connect to drop test DBs"); dropper .simple_query(&format!(r#"DROP DATABASE IF EXISTS "{}""#, db_name)) .expect("could not drop test DB"); }); - let mut root_client = Client::connect(&*root_connection_config, NoTls) + let mut root_client = Client::connect(root_connection_config, NoTls) .expect("could not connect to postgres"); root_client .simple_query(&format!(r#"CREATE DATABASE "{}""#, db_name))