From d47ac72cdcdac0d492a8ff4f71a0fd028cb1144b Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 16 Feb 2024 15:57:00 +0100 Subject: [PATCH] clippy --- members/matchmatchmatch/src/main.rs | 1 - members/revsqrt/benches/rsqrt-bench.rs | 4 ++-- members/revsqrt/tests/basic-revsqrt.rs | 24 ++++++++++++------------ members/revsqrt/tests/revsqrt.rs | 4 ++-- members/serde-json-demo/src/main.rs | 6 +++--- members/shortc/src/main.rs | 10 ++++++---- members/socker/src/pool.rs | 4 ++-- members/tokio-send-sync/src/main.rs | 2 +- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/members/matchmatchmatch/src/main.rs b/members/matchmatchmatch/src/main.rs index 9f87e60..a5382d3 100644 --- a/members/matchmatchmatch/src/main.rs +++ b/members/matchmatchmatch/src/main.rs @@ -291,7 +291,6 @@ fn main() { } { Some(inner) => { println!("{:?}", inner); - return; } None => unreachable!(), } diff --git a/members/revsqrt/benches/rsqrt-bench.rs b/members/revsqrt/benches/rsqrt-bench.rs index 5fa3e1c..8e52345 100644 --- a/members/revsqrt/benches/rsqrt-bench.rs +++ b/members/revsqrt/benches/rsqrt-bench.rs @@ -2,8 +2,8 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Through use revsqrt::{fast_inverse_sqrt, regular_inverse_sqrt}; const SIZE: f32 = 1337.1337; -const FCONST: f32 = 1024.12481224; -const FCONST1: f32 = 4025.724812234; +const FCONST: f32 = 1_024.124_8; +const FCONST1: f32 = 4_025.724_9; pub fn single_input(c: &mut Criterion) { c.bench_with_input(BenchmarkId::new("regular rsqrt", SIZE), &SIZE, |b, &s| { diff --git a/members/revsqrt/tests/basic-revsqrt.rs b/members/revsqrt/tests/basic-revsqrt.rs index ae3522f..c90175f 100644 --- a/members/revsqrt/tests/basic-revsqrt.rs +++ b/members/revsqrt/tests/basic-revsqrt.rs @@ -1,8 +1,8 @@ use std::iter::zip; -use revsqrt; -use rand; + + // is n about the same as m? // This is actually not so easy! How do you measure "about same"ness? @@ -34,14 +34,14 @@ fn test_calc_regular_rsqrt() { #[test] fn test_calc_specific_fast_rsqrt() { - let params: &[f32] = &[1.0, 1.1, 100.0, 1337.0, 123.45678900, 1337.1337]; + let params: &[f32] = &[1.0, 1.1, 100.0, 1337.0, 123.456_79, 1337.1337]; let results: &[f32] = &[ 1.0, - 0.9534625892455922, + 0.953_462_6, 0.1, - 0.02734854943722097, - 0.0900000004095, - 0.027347182112297627, + 0.027_348_55, + 0.09, + 0.027_347_183, ]; for (n, m) in zip(params, results) { assert!(about_same(revsqrt::fast_inverse_sqrt(*n), *m)) @@ -50,14 +50,14 @@ fn test_calc_specific_fast_rsqrt() { #[test] fn test_calc_specific_reqular_rsqrt() { - let params: &[f32] = &[1.0, 1.1, 100.0, 1337.0, 123.45678900, 1337.1337]; + let params: &[f32] = &[1.0, 1.1, 100.0, 1337.0, 123.456_79, 1337.1337]; let results: &[f32] = &[ 1.0, - 0.9534625892455922, + 0.953_462_6, 0.1, - 0.02734854943722097, - 0.0900000004095, - 0.027347182112297627, + 0.027_348_55, + 0.09, + 0.027_347_183, ]; for (n, m) in zip(params, results) { assert_eq!(revsqrt::regular_inverse_sqrt(*n), *m) diff --git a/members/revsqrt/tests/revsqrt.rs b/members/revsqrt/tests/revsqrt.rs index f7e2260..6e96167 100644 --- a/members/revsqrt/tests/revsqrt.rs +++ b/members/revsqrt/tests/revsqrt.rs @@ -1,9 +1,9 @@ use std::iter::zip; -use revsqrt; + use cucumber::{gherkin::Step, given, then, when, World}; -use rand; + /// stores the current information for each scenario #[derive(Debug, Default, World)] diff --git a/members/serde-json-demo/src/main.rs b/members/serde-json-demo/src/main.rs index 22ff1ab..356a8f6 100644 --- a/members/serde-json-demo/src/main.rs +++ b/members/serde-json-demo/src/main.rs @@ -1,7 +1,7 @@ -use anyhow; -use chrono; + + use serde::{Deserialize, Serialize}; -use serde_json; + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(rename_all = "UPPERCASE")] diff --git a/members/shortc/src/main.rs b/members/shortc/src/main.rs index 4da3f9b..ccfc762 100644 --- a/members/shortc/src/main.rs +++ b/members/shortc/src/main.rs @@ -6,16 +6,18 @@ use std::{ // This is just a very simple tcp server/client that connects to itself -const ADDR: &'static str = "127.0.0.1:9911"; +const ADDR: & str = "127.0.0.1:9911"; fn main() -> Result<()> { - let mut listen = net::TcpListener::bind(ADDR)?; + let listen = net::TcpListener::bind(ADDR)?; let mut client = net::TcpStream::connect(ADDR)?; - let mut sink = io::sink(); + let _sink = io::sink(); client.write_all(b"foo")?; let mut com = listen.accept()?; com.0.write_all(b"bak")?; - let mut buf = [0;3]; + let mut buf = [0; 3]; + #[allow(clippy::unused_io_amount)] + #[allow(clippy::all)] client.read(&mut buf)?; println!("{buf:x?}"); Ok(()) diff --git a/members/socker/src/pool.rs b/members/socker/src/pool.rs index b56f534..936589c 100644 --- a/members/socker/src/pool.rs +++ b/members/socker/src/pool.rs @@ -41,8 +41,8 @@ impl ThreadPool { /// /// The `new` function will panic if the size is zero. pub fn build(size: usize) -> Result { - if !(size > 0) { - return Err(format!("cannot build a thread pool with size 0!")); + if size <= 0 { + return Err("cannot build a thread pool with size 0!".to_string()); } let (sender, receiver) = mpsc::channel(); let receiver = Arc::new(Mutex::new(receiver)); diff --git a/members/tokio-send-sync/src/main.rs b/members/tokio-send-sync/src/main.rs index 6ab531a..e568a62 100644 --- a/members/tokio-send-sync/src/main.rs +++ b/members/tokio-send-sync/src/main.rs @@ -12,7 +12,7 @@ async fn foo(t: TestType) -> Result { #[tokio::main()] async fn main() { let testdata: TestType = 1337; - let arcmut = Arc::new(Mutex::new(testdata)); + let _arcmut = Arc::new(Mutex::new(testdata)); tokio::spawn(async move { let a = foo(testdata).await; a.unwrap().accept().await