From eb90cc53a5415e1760bf4bfe4e7aa67fbb85ad44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Laitl?= Date: Mon, 9 Aug 2021 13:35:42 +0200 Subject: [PATCH] Fix clippy warnings, add clippy to CI (#127) * Tidy code a bit thanks to clippy Clippy 1.54 newly detects some redundant constructs, that's nice. sort_unstable() should yield exact same results as sort() for `Vec<&str>` and could be faster, clippy says. * Add clippy to CI --- .github/workflows/rust.yml | 5 +++++ client/src/main.rs | 2 +- server/src/api/user.rs | 4 ++-- server/src/test.rs | 2 +- shared/src/types.rs | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9aca196..ca3bb3d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -47,3 +47,8 @@ jobs: with: command: test args: --verbose + - name: Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/client/src/main.rs b/client/src/main.rs index 9b7880d..e411883 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -510,7 +510,7 @@ fn fetch( if peers.iter().any(|p| p.public_key == public_key) { None } else { - PeerDiff::new(Some(&existing), None).unwrap() + PeerDiff::new(Some(existing), None).unwrap() } }); diff --git a/server/src/api/user.rs b/server/src/api/user.rs index 781517c..40c189c 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -162,7 +162,7 @@ mod tests { let whole_body = hyper::body::aggregate(res).await?; let State { peers, .. } = serde_json::from_reader(whole_body.reader())?; let mut peer_names = peers.iter().map(|p| &*p.contents.name).collect::>(); - peer_names.sort(); + peer_names.sort_unstable(); // Developers should see only peers in infra CIDR and developer CIDR. assert_eq!( &["developer1", "developer2", "innernet-server"], @@ -284,7 +284,7 @@ mod tests { let whole_body = hyper::body::aggregate(res).await?; let State { peers, .. } = serde_json::from_reader(whole_body.reader())?; let mut peer_names = peers.iter().map(|p| &*p.contents.name).collect::>(); - peer_names.sort(); + peer_names.sort_unstable(); // Developers should see only peers in infra CIDR and developer CIDR. assert_eq!( &[ diff --git a/server/src/test.rs b/server/src/test.rs index 190a3ba..0f1b3e9 100644 --- a/server/src/test.rs +++ b/server/src/test.rs @@ -134,7 +134,7 @@ impl Server { pub fn context(&self) -> Context { Context { db: self.db.clone(), - interface: self.interface.clone(), + interface: self.interface, endpoints: self.endpoints.clone(), public_key: self.public_key.clone(), #[cfg(target_os = "linux")] diff --git a/shared/src/types.rs b/shared/src/types.rs index 41bae3c..7fde367 100644 --- a/shared/src/types.rs +++ b/shared/src/types.rs @@ -511,7 +511,7 @@ impl<'a> PeerDiff<'a> { } pub fn public_key(&self) -> &Key { - &self.builder.public_key() + self.builder.public_key() } pub fn changes(&self) -> &[ChangeString] {