Skip to content

Commit

Permalink
Merge #528
Browse files Browse the repository at this point in the history
528: Clippy Suggestions Across Workspaces r=thatzopoulos a=thatzopoulos

This PR contains Clippy changes and should be merged before the Cargo Fmt PR: #524

Co-authored-by: Thomas Hatzopoulos <thomas@timescale.com>
  • Loading branch information
bors[bot] and thatzopoulos authored Sep 8, 2022
2 parents 818462d + 1d887c5 commit b6baa47
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 44 deletions.
8 changes: 4 additions & 4 deletions crates/asap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion crates/counter-agg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod range;
#[cfg(test)]
mod tests;

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum CounterError{
OrderError,
BoundsInvalid,
Expand Down
2 changes: 1 addition & 1 deletion crates/counter-agg/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i64>,
Expand Down
4 changes: 2 additions & 2 deletions crates/counter-agg/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions crates/flat_serialize/flat_serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/flat_serialize/flat_serialize_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hyperloglogplusplus/src/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -528,6 +528,6 @@ mod tests {
return false;
}

return true;
true
}
}
4 changes: 2 additions & 2 deletions crates/hyperloglogplusplus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>,
}

#[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>),
Expand Down
14 changes: 8 additions & 6 deletions crates/hyperloglogplusplus/src/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
// ```
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions crates/hyperloglogplusplus/src/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Encoded>,
pub compressed: Compressed<'s>,
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
);
return TestResult::failed();
}
return TestResult::passed();
TestResult::passed()
}

#[quickcheck]
Expand Down Expand Up @@ -400,7 +400,7 @@ mod tests {
);
return TestResult::failed();
}
return TestResult::passed();
TestResult::passed()
}

// fn encoded_order() {
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperloglogplusplus/src/sparse/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion crates/stats-agg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
5 changes: 2 additions & 3 deletions crates/t-digest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions crates/time-weighted-average/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion crates/tspoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct TSPoint {
pub val: f64,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum TSPointError {
TimesEqualInterpolate,
}
Expand Down
6 changes: 3 additions & 3 deletions crates/udd-sketch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion extension/src/hyperloglog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion extension/src/state_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record>,
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src/tdigest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'input> TDigest<'input> {
sum: digest.sum(),
min: digest.min(),
max: digest.max(),
centroids: (&*centroids).into(),
centroids: centroids.into(),
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src/time_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
2 changes: 1 addition & 1 deletion extension/src/time_vector/pipeline/fill_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tools/post-install/src/update_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<matcher> <remaining>` and return the `<remaining>`
#[allow(clippy::type_complexity)]
fn match_start<T, const N: usize>(
line: &str,
matchers: [(&str, &mut dyn FnMut(&str) -> T); N],
Expand Down
2 changes: 1 addition & 1 deletion tools/sql-doctester/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn run_tests<OnErr: FnMut(Test, TestError)>(

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)
Expand Down
4 changes: 2 additions & 2 deletions tools/testrunner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b6baa47

Please sign in to comment.