diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-09-20 19:26:48 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-09-21 09:56:49 +0300 |
commit | 7febc9e2722f7ca97be91dc4a68c9f6a0502dc27 (patch) | |
tree | 9159e67837902e39cd251c777f66c23789920ca2 /openpgp-ffi | |
parent | eff8edd82629a4e6151d4bcb104a7695c6975e8d (diff) |
Avoid matching on &Foo, when a plain Foo pattern works
The extra & in a pattern (match arm or if let) is unnecessary and only
makes the code harder to read. In most places it's enough to just
remove the & from the pattern, but in a few places a dereference (*)
needs to be added where the value captured in the pattern is used, as
removing the & changes the type of the captured value to be a
reference.
Overall, the changes are almost mechanical. Although the diff is huge,
it should be easy to read.
The clippy lint match_ref_pats warns about this. See:
https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/src/error.rs | 56 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/skesk.rs | 2 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/user_attribute.rs | 2 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/userid.rs | 12 |
4 files changed, 36 insertions, 36 deletions
diff --git a/openpgp-ffi/src/error.rs b/openpgp-ffi/src/error.rs index 04bb05c0..1709e1c9 100644 --- a/openpgp-ffi/src/error.rs +++ b/openpgp-ffi/src/error.rs @@ -211,63 +211,63 @@ impl<'a> From<&'a anyhow::Error> for Status { fn from(e: &'a anyhow::Error) -> Self { if let Some(e) = e.downcast_ref::<openpgp::Error>() { return match e { - &openpgp::Error::InvalidArgument(_) => + openpgp::Error::InvalidArgument(_) => Status::InvalidArgument, - &openpgp::Error::InvalidOperation(_) => + openpgp::Error::InvalidOperation(_) => Status::InvalidOperation, - &openpgp::Error::MalformedPacket(_) => + openpgp::Error::MalformedPacket(_) => Status::MalformedPacket, - &openpgp::Error::PacketTooLarge(_, _, _) => + openpgp::Error::PacketTooLarge(_, _, _) => Status::PacketTooLarge, - &openpgp::Error::UnsupportedPacketType(_) => + openpgp::Error::UnsupportedPacketType(_) => Status::UnsupportedPacketType, - &openpgp::Error::UnsupportedHashAlgorithm(_) => + openpgp::Error::UnsupportedHashAlgorithm(_) => Status::UnsupportedHashAlgorithm, - &openpgp::Error::UnsupportedPublicKeyAlgorithm(_) => + openpgp::Error::UnsupportedPublicKeyAlgorithm(_) => Status::UnsupportedPublicKeyAlgorithm, - &openpgp::Error::UnsupportedEllipticCurve(_) => + openpgp::Error::UnsupportedEllipticCurve(_) => Status::UnsupportedEllipticCurve, - &openpgp::Error::UnsupportedSymmetricAlgorithm(_) => + openpgp::Error::UnsupportedSymmetricAlgorithm(_) => Status::UnsupportedSymmetricAlgorithm, - &openpgp::Error::UnsupportedAEADAlgorithm(_) => + openpgp::Error::UnsupportedAEADAlgorithm(_) => Status::UnsupportedAEADAlgorithm, - &openpgp::Error::UnsupportedCompressionAlgorithm(_) => + openpgp::Error::UnsupportedCompressionAlgorithm(_) => Status::UnsupportedCompressionAlgorithm, - &openpgp::Error::UnsupportedSignatureType(_) => + openpgp::Error::UnsupportedSignatureType(_) => Status::UnsupportedSignatureType, - &openpgp::Error::InvalidPassword => + openpgp::Error::InvalidPassword => Status::InvalidPassword, - &openpgp::Error::InvalidSessionKey(_) => + openpgp::Error::InvalidSessionKey(_) => Status::InvalidSessionKey, - &openpgp::Error::MissingSessionKey(_) => + openpgp::Error::MissingSessionKey(_) => Status::MissingSessionKey, - &openpgp::Error::MalformedMPI(_) => + openpgp::Error::MalformedMPI(_) => Status::MalformedMPI, - &openpgp::Error::BadSignature(_) => + openpgp::Error::BadSignature(_) => Status::BadSignature, - &openpgp::Error::ManipulatedMessage => + openpgp::Error::ManipulatedMessage => Status::ManipulatedMessage, - &openpgp::Error::MalformedMessage(_) => + openpgp::Error::MalformedMessage(_) => Status::MalformedMessage, - &openpgp::Error::MalformedCert(_) => + openpgp::Error::MalformedCert(_) => Status::MalformedCert, - &openpgp::Error::IndexOutOfRange => + openpgp::Error::IndexOutOfRange => Status::IndexOutOfRange, - &openpgp::Error::UnsupportedCert(_) => + openpgp::Error::UnsupportedCert(_) => Status::UnsupportedCert, - &openpgp::Error::Expired(_) => + openpgp::Error::Expired(_) => Status::Expired, - &openpgp::Error::NotYetLive(_) => + openpgp::Error::NotYetLive(_) => Status::NotYetLive, - &openpgp::Error::NoBindingSignature(_) => + openpgp::Error::NoBindingSignature(_) => Status::NoBindingSignature, - &openpgp::Error::InvalidKey(_) => + openpgp::Error::InvalidKey(_) => Status::InvalidKey, - &openpgp::Error::PolicyViolation(_, _) => + openpgp::Error::PolicyViolation(_, _) => Status::PolicyViolation, // openpgp::Error is non_exhaustive, match on &_ to handle // future additions. - &_ => Status::UnknownError + _ => Status::UnknownError } } diff --git a/openpgp-ffi/src/packet/skesk.rs b/openpgp-ffi/src/packet/skesk.rs index ddc41e1c..a6e9bdfb 100644 --- a/openpgp-ffi/src/packet/skesk.rs +++ b/openpgp-ffi/src/packet/skesk.rs @@ -32,7 +32,7 @@ pub extern "C" fn pgp_skesk_decrypt(errp: Option<&mut *mut crate::error::Error>, let algo = ffi_param_ref_mut!(algo); let key_len = ffi_param_ref_mut!(key_len); - if let &openpgp::Packet::SKESK(ref skesk) = skesk.ref_raw() { + if let openpgp::Packet::SKESK(ref skesk) = skesk.ref_raw() { match skesk.decrypt(&password.to_owned().into()) { Ok((a, k)) => { *algo = a.into(); diff --git a/openpgp-ffi/src/packet/user_attribute.rs b/openpgp-ffi/src/packet/user_attribute.rs index 42e7d156..ad141056 100644 --- a/openpgp-ffi/src/packet/user_attribute.rs +++ b/openpgp-ffi/src/packet/user_attribute.rs @@ -18,7 +18,7 @@ use crate::RefRaw; pub extern "C" fn pgp_user_attribute_value(ua: *const Packet, value_len: Option<&mut size_t>) -> *const u8 { - if let &openpgp::Packet::UserAttribute(ref ua) = ua.ref_raw() { + if let openpgp::Packet::UserAttribute(ref ua) = ua.ref_raw() { if let Some(p) = value_len { *p = ua.value().len(); } diff --git a/openpgp-ffi/src/packet/userid.rs b/openpgp-ffi/src/packet/userid.rs index 89febc06..db0f731b 100644 --- a/openpgp-ffi/src/packet/userid.rs +++ b/openpgp-ffi/src/packet/userid.rs @@ -129,7 +129,7 @@ pub extern "C" fn pgp_user_id_value(uid: *const Packet, value_len: Option<&mut size_t>) -> *const u8 { - if let &openpgp::Packet::UserID(ref uid) = uid.ref_raw() { + if let openpgp::Packet::UserID(ref uid) = uid.ref_raw() { if let Some(p) = value_len { *p = uid.value().len(); } @@ -158,7 +158,7 @@ fn pgp_user_id_name( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.name() { Ok(Some(name)) => *namep = ffi_return_string!(name), @@ -199,7 +199,7 @@ fn pgp_user_id_comment( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.comment() { Ok(Some(comment)) => *commentp = ffi_return_string!(comment), @@ -240,7 +240,7 @@ fn pgp_user_id_email( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.email() { Ok(Some(address)) => *addressp = ffi_return_string!(address), @@ -280,7 +280,7 @@ fn pgp_user_id_uri( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.uri() { Ok(Some(uri)) => *urip = ffi_return_string!(uri), @@ -330,7 +330,7 @@ fn pgp_user_id_email_normalized( ffi_make_fry_from_errp!(errp); let uid = uid.ref_raw(); - if let &openpgp::Packet::UserID(ref uid) = uid { + if let openpgp::Packet::UserID(ref uid) = uid { match uid.email_normalized() { Ok(Some(email)) => *emailp = ffi_return_string!(email), |