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
pull/132/head
Matěj Laitl 2021-08-09 13:35:42 +02:00 committed by GitHub
parent e97eb737a4
commit eb90cc53a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 5 deletions

View File

@ -47,3 +47,8 @@ jobs:
with: with:
command: test command: test
args: --verbose args: --verbose
- name: Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

View File

@ -510,7 +510,7 @@ fn fetch(
if peers.iter().any(|p| p.public_key == public_key) { if peers.iter().any(|p| p.public_key == public_key) {
None None
} else { } else {
PeerDiff::new(Some(&existing), None).unwrap() PeerDiff::new(Some(existing), None).unwrap()
} }
}); });

View File

@ -162,7 +162,7 @@ mod tests {
let whole_body = hyper::body::aggregate(res).await?; let whole_body = hyper::body::aggregate(res).await?;
let State { peers, .. } = serde_json::from_reader(whole_body.reader())?; let State { peers, .. } = serde_json::from_reader(whole_body.reader())?;
let mut peer_names = peers.iter().map(|p| &*p.contents.name).collect::<Vec<_>>(); let mut peer_names = peers.iter().map(|p| &*p.contents.name).collect::<Vec<_>>();
peer_names.sort(); peer_names.sort_unstable();
// Developers should see only peers in infra CIDR and developer CIDR. // Developers should see only peers in infra CIDR and developer CIDR.
assert_eq!( assert_eq!(
&["developer1", "developer2", "innernet-server"], &["developer1", "developer2", "innernet-server"],
@ -284,7 +284,7 @@ mod tests {
let whole_body = hyper::body::aggregate(res).await?; let whole_body = hyper::body::aggregate(res).await?;
let State { peers, .. } = serde_json::from_reader(whole_body.reader())?; let State { peers, .. } = serde_json::from_reader(whole_body.reader())?;
let mut peer_names = peers.iter().map(|p| &*p.contents.name).collect::<Vec<_>>(); let mut peer_names = peers.iter().map(|p| &*p.contents.name).collect::<Vec<_>>();
peer_names.sort(); peer_names.sort_unstable();
// Developers should see only peers in infra CIDR and developer CIDR. // Developers should see only peers in infra CIDR and developer CIDR.
assert_eq!( assert_eq!(
&[ &[

View File

@ -134,7 +134,7 @@ impl Server {
pub fn context(&self) -> Context { pub fn context(&self) -> Context {
Context { Context {
db: self.db.clone(), db: self.db.clone(),
interface: self.interface.clone(), interface: self.interface,
endpoints: self.endpoints.clone(), endpoints: self.endpoints.clone(),
public_key: self.public_key.clone(), public_key: self.public_key.clone(),
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]

View File

@ -511,7 +511,7 @@ impl<'a> PeerDiff<'a> {
} }
pub fn public_key(&self) -> &Key { pub fn public_key(&self) -> &Key {
&self.builder.public_key() self.builder.public_key()
} }
pub fn changes(&self) -> &[ChangeString] { pub fn changes(&self) -> &[ChangeString] {