Fix Clippy lints
Change-Id: Idb28e9afd44f63891e8c49ba0bf68ca367ff1fe6
Reviewed-on: https://fuchsia-review.googlesource.com/c/mundane/+/493386
Reviewed-by: Drew Fisher <zarvox@google.com>
diff --git a/boringssl/bindgen.sh b/boringssl/bindgen.sh
index 00e63d7..227faa2 100755
--- a/boringssl/bindgen.sh
+++ b/boringssl/bindgen.sh
@@ -203,6 +203,7 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
+#![allow(clippy::all)]
EOF
diff --git a/boringssl/boringssl.rs b/boringssl/boringssl.rs
index ccc1abe..a847438 100644
--- a/boringssl/boringssl.rs
+++ b/boringssl/boringssl.rs
@@ -13,6 +13,7 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
+#![allow(clippy::all)]
#[link(name = "crypto_0_4_3")]
extern "C" {}
diff --git a/build/main.rs b/build/main.rs
index 06013b2..6315a12 100644
--- a/build/main.rs
+++ b/build/main.rs
@@ -22,7 +22,8 @@
const SYMBOL_FILE: &str = "boringssl/symbols.txt";
fn env(name: &str) -> String {
- let var = env::var(name).expect(&format!("missing required environment variable {}", name));
+ let var =
+ env::var(name).unwrap_or_else(|_| panic!("missing required environment variable {}", name));
println!("cargo:rerun-if-env-changed={}", var);
var
}
@@ -117,7 +118,7 @@
let mut symbols_file =
fs::File::create(&abs_symbol_file).expect("could not create symbols file");
for symbol in symbols {
- write!(symbols_file, "{}\n", symbol).expect("write to symbols file failed");
+ writeln!(symbols_file, "{}", symbol).expect("write to symbols file failed");
}
// Make sure the file is fully written to disc before pasing it to BoringSSL's build system.
symbols_file.sync_all().expect("failed to sync the symbols file to filesystem");
@@ -213,7 +214,7 @@
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
- .expect(&format!("failed to invoke {}", cmd));
+ .unwrap_or_else(|_| panic!("failed to invoke {}", cmd));
if !output.status.success() {
panic!("{} failed with status {}", cmd, output.status);
}
diff --git a/src/boringssl/raw.rs b/src/boringssl/raw.rs
index 376c688..dc7bd0f 100644
--- a/src/boringssl/raw.rs
+++ b/src/boringssl/raw.rs
@@ -14,6 +14,11 @@
//! This module also directly re-exports any raw bindings which are infallible
//! (e.g., `void` functions).
+// Many of the BoringSSL functions trigger this Clippy lint, and since the
+// purpose of this module is to mirror those functions, our only option is to
+// suppress this lint.
+#![allow(clippy::too_many_arguments)]
+
// Infallible functions and the `size_t` type.
pub use boringssl::ffi::{
size_t, CBB_cleanup, CBB_len, CBS_init, CBS_len, CRYPTO_memcmp, EC_GROUP_get_curve_name,
@@ -588,10 +593,9 @@
impl IntoSizeT for usize {
fn into_size_t(self) -> size_t {
// This is an infallible conversion since we're on a 64-bit platform.
- let x = self as u64;
// This line will stop compiling if `size_t` is no longer an alias for
// `u64`.
- x
+ self as u64
}
}
@@ -621,10 +625,9 @@
impl IntoSizeT for usize {
fn into_size_t(self) -> size_t {
// This is an infallible conversion since we're on a 32-bit platform.
- let x = self as u32;
// This line will stop compiling if `size_t` is no longer an alias for
// `u32`.
- x
+ self as u32
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 1200815..36c5806 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -43,6 +43,12 @@
#![deny(missing_docs)]
#![deny(warnings)]
+// We use the `must_use` attribute liberally, including in cases where it's
+// technically unnecessary because the return type itself is marked as
+// `must_use`. We prefer to do this rather than make the lint happy because it
+// makes it less likely for us to forget a `must_use` attribute in the future if
+// we change the function's signature.
+#![allow(clippy::double_must_use)]
// just in case we forget to add #[forbid(unsafe_code)] on new module
// definitions
#![deny(unsafe_code)]
diff --git a/src/public/rsa/mod.rs b/src/public/rsa/mod.rs
index 7b38a2f..9195e89 100644
--- a/src/public/rsa/mod.rs
+++ b/src/public/rsa/mod.rs
@@ -280,22 +280,12 @@
return Err(Error::new("excess data provided after valid DER input".to_string()));
}
- Ok(match key.rsa_bits().into() {
- B2048::BITS => {
- RsaPubKeyAnyBits::B2048(RsaPubKey { inner: RsaKey::from_RSA(key.clone())? })
- }
- B3072::BITS => {
- RsaPubKeyAnyBits::B3072(RsaPubKey { inner: RsaKey::from_RSA(key.clone())? })
- }
- B4096::BITS => {
- RsaPubKeyAnyBits::B4096(RsaPubKey { inner: RsaKey::from_RSA(key.clone())? })
- }
- B6144::BITS => {
- RsaPubKeyAnyBits::B6144(RsaPubKey { inner: RsaKey::from_RSA(key.clone())? })
- }
- B8192::BITS => {
- RsaPubKeyAnyBits::B8192(RsaPubKey { inner: RsaKey::from_RSA(key.clone())? })
- }
+ Ok(match key.rsa_bits() {
+ B2048::BITS => RsaPubKeyAnyBits::B2048(RsaPubKey { inner: RsaKey::from_RSA(key)? }),
+ B3072::BITS => RsaPubKeyAnyBits::B3072(RsaPubKey { inner: RsaKey::from_RSA(key)? }),
+ B4096::BITS => RsaPubKeyAnyBits::B4096(RsaPubKey { inner: RsaKey::from_RSA(key)? }),
+ B6144::BITS => RsaPubKeyAnyBits::B6144(RsaPubKey { inner: RsaKey::from_RSA(key)? }),
+ B8192::BITS => RsaPubKeyAnyBits::B8192(RsaPubKey { inner: RsaKey::from_RSA(key)? }),
bits => return Err(Error::new(format!("unsupported bit length: {}", bits))),
})
})
@@ -349,21 +339,21 @@
return Err(Error::new("excess data provided after valid DER input".to_string()));
}
- Ok(match key.rsa_bits().into() {
+ Ok(match key.rsa_bits() {
B2048::BITS => {
- RsaPrivKeyAnyBits::B2048(RsaPrivKey { inner: RsaKey::from_RSA(key.clone())? })
+ RsaPrivKeyAnyBits::B2048(RsaPrivKey { inner: RsaKey::from_RSA(key)? })
}
B3072::BITS => {
- RsaPrivKeyAnyBits::B3072(RsaPrivKey { inner: RsaKey::from_RSA(key.clone())? })
+ RsaPrivKeyAnyBits::B3072(RsaPrivKey { inner: RsaKey::from_RSA(key)? })
}
B4096::BITS => {
- RsaPrivKeyAnyBits::B4096(RsaPrivKey { inner: RsaKey::from_RSA(key.clone())? })
+ RsaPrivKeyAnyBits::B4096(RsaPrivKey { inner: RsaKey::from_RSA(key)? })
}
B6144::BITS => {
- RsaPrivKeyAnyBits::B6144(RsaPrivKey { inner: RsaKey::from_RSA(key.clone())? })
+ RsaPrivKeyAnyBits::B6144(RsaPrivKey { inner: RsaKey::from_RSA(key)? })
}
B8192::BITS => {
- RsaPrivKeyAnyBits::B8192(RsaPrivKey { inner: RsaKey::from_RSA(key.clone())? })
+ RsaPrivKeyAnyBits::B8192(RsaPrivKey { inner: RsaKey::from_RSA(key)? })
}
bits => return Err(Error::new(format!("unsupported bit length: {}", bits))),
})