From 45c7f3049b1816613624a22198ca01366db8c6b2 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Fri, 4 Nov 2022 13:01:20 +0100 Subject: [PATCH] Update to Rust 1.65 * Use new let-else syntax * Fix new clippy lints Signed-off-by: Alexis Sellier --- .github/workflows/actions.yml | 3 ++- radicle-crypto/src/lib.rs | 2 +- radicle-crypto/src/ssh/keystore.rs | 2 +- radicle-node/src/service.rs | 8 ++------ radicle-node/src/test/simulator.rs | 6 ++---- radicle-node/src/wire.rs | 2 ++ radicle-ssh/src/agent/client.rs | 4 +--- radicle-ssh/src/encoding.rs | 4 ++-- radicle-tools/src/rad-push.rs | 2 +- radicle/src/lib.rs | 1 + radicle/src/storage/git.rs | 4 +--- rust-toolchain | 2 +- 12 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 8cb0d331..e7b0b2e3 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -15,6 +15,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal + toolchain: 1.65 - name: Build run: cargo build --verbose --all-features env: @@ -42,7 +43,7 @@ jobs: with: profile: minimal components: clippy, rustfmt - toolchain: 1.64 + toolchain: 1.65 - name: Cache cargo registry uses: actions/cache@v1 with: diff --git a/radicle-crypto/src/lib.rs b/radicle-crypto/src/lib.rs index b6043fbf..aa8ce39e 100644 --- a/radicle-crypto/src/lib.rs +++ b/radicle-crypto/src/lib.rs @@ -285,7 +285,7 @@ impl PublicKey { buf[..2].copy_from_slice(&Self::MULTICODEC_TYPE); buf[2..].copy_from_slice(self.0.deref()); - multibase::encode(multibase::Base::Base58Btc, &buf) + multibase::encode(multibase::Base::Base58Btc, buf) } } diff --git a/radicle-crypto/src/ssh/keystore.rs b/radicle-crypto/src/ssh/keystore.rs index 7c0ea3d3..96863da2 100644 --- a/radicle-crypto/src/ssh/keystore.rs +++ b/radicle-crypto/src/ssh/keystore.rs @@ -48,7 +48,7 @@ impl Keystore { /// The `passphrase` is used to encrypt the private key. pub fn init(&self, comment: &str, passphrase: &str) -> Result { let pair = KeyPair::generate(); - let ssh_pair = ssh_key::private::Ed25519Keypair::from_bytes(&*pair)?; + let ssh_pair = ssh_key::private::Ed25519Keypair::from_bytes(&pair)?; let ssh_pair = ssh_key::private::KeypairData::Ed25519(ssh_pair); let secret = ssh_key::PrivateKey::new(ssh_pair, comment)?; let secret = secret.encrypt(ssh_key::rand_core::OsRng, passphrase)?; diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index 5fe1fafe..1aa4e3ca 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -417,9 +417,7 @@ where } let seeds = self.seeds(&id); - let seeds = if let Some(seeds) = NonEmpty::from_vec(seeds) { - seeds - } else { + let Some(seeds) = NonEmpty::from_vec(seeds) else { log::error!("No seeds found for {}", id); resp.send(FetchLookup::NotFound).ok(); @@ -755,9 +753,7 @@ where message: Message, ) -> Result<(), session::Error> { let peer_ip = remote.ip(); - let peer = if let Some(peer) = self.sessions.get_mut(&peer_ip) { - peer - } else { + let Some(peer) = self.sessions.get_mut(&peer_ip) else { return Err(session::Error::NotFound(remote.ip())); }; peer.last_active = self.clock.local_time(); diff --git a/radicle-node/src/test/simulator.rs b/radicle-node/src/test/simulator.rs index 3761005e..159c470c 100644 --- a/radicle-node/src/test/simulator.rs +++ b/radicle-node/src/test/simulator.rs @@ -560,13 +560,11 @@ impl Simulation { // // It's also possible that the connection was only attempted and never succeeded, // in which case we would return here. - let port = if let Some(port) = self.connections.get(&(node, remote.ip())) { - *port - } else { + let Some(port) = self.connections.get(&(node, remote.ip())) else { debug!(target: "sim", "Ignoring disconnect of {remote} from {node}"); return; }; - let local_addr: net::SocketAddr = (node, port).into(); + let local_addr: net::SocketAddr = (node, *port).into(); let latency = self.latency(node, remote.ip()); // The remote node receives the disconnection with some delay. diff --git a/radicle-node/src/wire.rs b/radicle-node/src/wire.rs index 71709de2..0ead8d79 100644 --- a/radicle-node/src/wire.rs +++ b/radicle-node/src/wire.rs @@ -129,6 +129,8 @@ impl Encode for PublicKey { impl Encode for &[u8; T] { fn encode(&self, writer: &mut W) -> Result { + // TODO: This can be removed when the clippy bugs are fixed + #[allow(clippy::explicit_auto_deref)] writer.write_all(*self)?; Ok(mem::size_of::()) diff --git a/radicle-ssh/src/agent/client.rs b/radicle-ssh/src/agent/client.rs index a4541d06..e0bfa88f 100644 --- a/radicle-ssh/src/agent/client.rs +++ b/radicle-ssh/src/agent/client.rs @@ -63,9 +63,7 @@ pub trait ClientStream: Sized + Send + Sync { P: AsRef + Send; fn connect_env() -> Result, Error> { - let var = if let Ok(var) = std::env::var("SSH_AUTH_SOCK") { - var - } else { + let Ok(var) = std::env::var("SSH_AUTH_SOCK") else { return Err(Error::EnvVar("SSH_AUTH_SOCK")); }; match Self::connect(var) { diff --git a/radicle-ssh/src/encoding.rs b/radicle-ssh/src/encoding.rs index fc38e02e..8342eefa 100644 --- a/radicle-ssh/src/encoding.rs +++ b/radicle-ssh/src/encoding.rs @@ -103,7 +103,7 @@ impl Encoding for Vec { fn extend_list<'a, I: Iterator>(&mut self, list: I) { let len0 = self.len(); - self.extend(&[0, 0, 0, 0]); + self.extend([0, 0, 0, 0]); let mut first = true; for i in list { @@ -120,7 +120,7 @@ impl Encoding for Vec { } fn write_empty_list(&mut self) { - self.extend(&[0, 0, 0, 0]); + self.extend([0, 0, 0, 0]); } fn write_len(&mut self) { diff --git a/radicle-tools/src/rad-push.rs b/radicle-tools/src/rad-push.rs index 528bbe19..8a3e8dee 100644 --- a/radicle-tools/src/rad-push.rs +++ b/radicle-tools/src/rad-push.rs @@ -8,7 +8,7 @@ fn main() -> anyhow::Result<()> { let profile = radicle::Profile::load()?; let (_, id) = radicle::rad::remote(&repo)?; - let output = radicle::git::run::<_, _, &str, &str>(&cwd, &["push", "rad"], None)?; + let output = radicle::git::run::<_, _, &str, &str>(&cwd, ["push", "rad"], None)?; println!("{}", output); let signer = profile.signer()?; diff --git a/radicle/src/lib.rs b/radicle/src/lib.rs index 913cac12..dbd24773 100644 --- a/radicle/src/lib.rs +++ b/radicle/src/lib.rs @@ -1,4 +1,5 @@ #![allow(clippy::match_like_matches_macro)] +#![allow(clippy::explicit_auto_deref)] // TODO: This can be removed when the clippy bugs are fixed #![cfg_attr(not(test), warn(clippy::unwrap_used))] pub extern crate radicle_crypto as crypto; diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 50d6b5f0..b746a6fa 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -352,9 +352,7 @@ impl Repository { let r = reference?; let name = r.name().ok_or(refs::Error::InvalidRef)?; let (namespace, refname) = git::parse_ref_namespaced::(name)?; - let oid = if let Some(oid) = r.target() { - oid - } else { + let Some(oid) = r.target() else { // Ignore symbolic refs, eg. `HEAD`. return Ok(None); }; diff --git a/rust-toolchain b/rust-toolchain index 8725364a..5b6cd6b3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.64 +1.65