diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-11-22 12:58:47 +0100 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-11-29 11:53:55 +0100 |
commit | 049055e3ff5ffe86700b668e924fbff96e82be94 (patch) | |
tree | 30dfd63e4d1c3016210b698813e99b70787890e8 | |
parent | 97ce753fefae770ee0b5b02a611d75e29a7cd01d (diff) |
Remove unnecessary borrows.
- Fixed with the help of clippy::needless_borrow.
39 files changed, 97 insertions, 97 deletions
diff --git a/buffered-reader/src/lib.rs b/buffered-reader/src/lib.rs index d9f5b324..28f63a62 100644 --- a/buffered-reader/src/lib.rs +++ b/buffered-reader/src/lib.rs @@ -455,7 +455,7 @@ pub trait BufferedReader<C> : io::Read + fmt::Debug + fmt::Display + Send + Sync // must return a slice shorter than std::usize::MAX. loop { match self.data(s) { - Ok(ref buffer) => { + Ok(buffer) => { if buffer.len() < s { // We really want to do // diff --git a/buffered-reader/src/limitor.rs b/buffered-reader/src/limitor.rs index e7260c3b..54ac5a78 100644 --- a/buffered-reader/src/limitor.rs +++ b/buffered-reader/src/limitor.rs @@ -74,7 +74,7 @@ impl<T: BufferedReader<C>, C: fmt::Debug + Sync + Send> BufferedReader<C> for Li let amount = cmp::min(amount as u64, self.limit) as usize; let result = self.reader.data(amount); match result { - Ok(ref buffer) => + Ok(buffer) => if buffer.len() as u64 > self.limit { Ok(&buffer[0..self.limit as usize]) } else { @@ -94,7 +94,7 @@ impl<T: BufferedReader<C>, C: fmt::Debug + Sync + Send> BufferedReader<C> for Li fn data_consume(&mut self, amount: usize) -> Result<&[u8], io::Error> { let amount = cmp::min(amount as u64, self.limit) as usize; let result = self.reader.data_consume(amount); - if let Ok(ref buffer) = result { + if let Ok(buffer) = result { let amount = cmp::min(amount, buffer.len()); self.limit -= amount as u64; return Ok(&buffer[ @@ -108,7 +108,7 @@ impl<T: BufferedReader<C>, C: fmt::Debug + Sync + Send> BufferedReader<C> for Li return Err(Error::new(ErrorKind::UnexpectedEof, "EOF")); } let result = self.reader.data_consume_hard(amount); - if let Ok(ref buffer) = result { + if let Ok(buffer) = result { let amount = cmp::min(amount, buffer.len()); self.limit -= amount as u64; return Ok(&buffer[ diff --git a/ffi/tests/c-tests.rs b/ffi/tests/c-tests.rs index fbca0600..da05ad1a 100644 --- a/ffi/tests/c-tests.rs +++ b/ffi/tests/c-tests.rs @@ -163,7 +163,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F) if let Some(name) = exported_function_name(&line) { if !test.is_empty() { - fun(path, test_starts_at, &name, replace(&mut test, vec![]), + fun(path, test_starts_at, name, replace(&mut test, vec![]), run)?; test.clear(); } diff --git a/ipc/src/sexp/parse/lexer.rs b/ipc/src/sexp/parse/lexer.rs index b4eae979..29f3f545 100644 --- a/ipc/src/sexp/parse/lexer.rs +++ b/ipc/src/sexp/parse/lexer.rs @@ -116,14 +116,14 @@ impl<'input> Iterator for Lexer<'input> { } } - let len = String::from_utf8_lossy(&input); + let len = String::from_utf8_lossy(input); Some(Err(LexicalError::TruncatedInput( format!("Expected colon and data after {:?}", len)))) }, _ => Some(Err(LexicalError::UnexpectedCharacter( format!("Unexpected character {}", *c as char)))), } - })(&self.input)?; + })(self.input)?; let (l, token) = match len_token { Ok(x) => x, diff --git a/net/src/pks.rs b/net/src/pks.rs index 4c27c63a..4f16ec78 100644 --- a/net/src/pks.rs +++ b/net/src/pks.rs @@ -35,7 +35,7 @@ use url::Url; /// URL that can be used for signing or decryption. fn create_uri(store_uri: &str, key: &Key<PublicParts, UnspecifiedRole>, p: &Password, capability: &str) -> Result<Uri> { - let mut url = Url::parse(&store_uri)?; + let mut url = Url::parse(store_uri)?; let auth = if !url.username().is_empty() { let credentials = format!("{}:{}", url.username(), url.password().unwrap_or_default()); Some(format!("Basic {}", base64::encode(credentials))) diff --git a/net/src/wkd.rs b/net/src/wkd.rs index f1efff8f..e563a168 100644 --- a/net/src/wkd.rs +++ b/net/src/wkd.rs @@ -256,7 +256,7 @@ where .flatten() .map(|value| value.parse::<Uri>()); if let Some(Ok(url)) = url { - return get_following_redirects(&client, url, depth - 1).await; + return get_following_redirects(client, url, depth - 1).await; } } } diff --git a/openpgp-ffi/tests/c-tests.rs b/openpgp-ffi/tests/c-tests.rs index 7a75a9d6..a93653db 100644 --- a/openpgp-ffi/tests/c-tests.rs +++ b/openpgp-ffi/tests/c-tests.rs @@ -162,7 +162,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F) if let Some(name) = exported_function_name(&line) { if !test.is_empty() { - fun(path, test_starts_at, &name, replace(&mut test, vec![]), + fun(path, test_starts_at, name, replace(&mut test, vec![]), run)?; test.clear(); } diff --git a/openpgp/benches/decrypt_message.rs b/openpgp/benches/decrypt_message.rs index e2ed4e5e..9d3876e9 100644 --- a/openpgp/benches/decrypt_message.rs +++ b/openpgp/benches/decrypt_message.rs @@ -20,12 +20,12 @@ lazy_static::lazy_static! { fn decrypt_cert(bytes: &[u8], cert: &Cert) { let mut sink = Vec::new(); - decrypt::decrypt_with_cert(&mut sink, &bytes, cert).unwrap(); + decrypt::decrypt_with_cert(&mut sink, bytes, cert).unwrap(); } fn decrypt_password(bytes: &[u8]) { let mut sink = Vec::new(); - decrypt::decrypt_with_password(&mut sink, &bytes, PASSWORD).unwrap(); + decrypt::decrypt_with_password(&mut sink, bytes, PASSWORD).unwrap(); } fn bench_decrypt(c: &mut Criterion) { @@ -42,7 +42,7 @@ fn bench_decrypt(c: &mut Criterion) { group.bench_with_input( BenchmarkId::new("password", m.len()), &encrypted, - |b, e| b.iter(|| decrypt_password(&e)), + |b, e| b.iter(|| decrypt_password(e)), ); }); @@ -53,7 +53,7 @@ fn bench_decrypt(c: &mut Criterion) { group.bench_with_input( BenchmarkId::new("cert", m.len()), &encrypted, - |b, e| b.iter(|| decrypt_cert(&e, &TESTY)), + |b, e| b.iter(|| decrypt_cert(e, &TESTY)), ); }); diff --git a/openpgp/benches/decrypt_verify_message.rs b/openpgp/benches/decrypt_verify_message.rs index aa84e819..12a48642 100644 --- a/openpgp/benches/decrypt_verify_message.rs +++ b/openpgp/benches/decrypt_verify_message.rs @@ -21,7 +21,7 @@ lazy_static::lazy_static! { fn decrypt_and_verify(bytes: &[u8], sender: &Cert, recipient: &Cert) { let mut sink = Vec::new(); - decrypt::decrypt_and_verify(&mut sink, &bytes, sender, recipient).unwrap(); + decrypt::decrypt_and_verify(&mut sink, bytes, sender, recipient).unwrap(); } fn bench_decrypt_verify(c: &mut Criterion) { @@ -38,7 +38,7 @@ fn bench_decrypt_verify(c: &mut Criterion) { group.bench_with_input( BenchmarkId::new("decrypt and verify", m.len()), &encrypted, - |b, e| b.iter(|| decrypt_and_verify(&e, &SENDER, &RECIPIENT)), + |b, e| b.iter(|| decrypt_and_verify(e, &SENDER, &RECIPIENT)), ); }); diff --git a/openpgp/benches/encrypt_message.rs b/openpgp/benches/encrypt_message.rs index 5b0a0020..93f5925d 100644 --- a/openpgp/benches/encrypt_message.rs +++ b/openpgp/benches/encrypt_message.rs @@ -34,12 +34,12 @@ fn bench_encrypt(c: &mut Criterion) { group.bench_with_input( BenchmarkId::new("password", message.len()), &message, - |b, m| b.iter(|| encrypt_with_password(&m)), + |b, m| b.iter(|| encrypt_with_password(m)), ); group.bench_with_input( BenchmarkId::new("cert", message.len()), &message, - |b, m| b.iter(|| encrypt_to_testy(&m)), + |b, m| b.iter(|| encrypt_to_testy(m)), ); } group.finish(); diff --git a/openpgp/benches/encrypt_sign_message.rs b/openpgp/benches/encrypt_sign_message.rs index 5923ff88..62863eb5 100644 --- a/openpgp/benches/encrypt_sign_message.rs +++ b/openpgp/benches/encrypt_sign_message.rs @@ -34,7 +34,7 @@ fn bench_encrypt_sign(c: &mut Criterion) { group.bench_with_input( BenchmarkId::new("encrypt and sign", message.len()), &message, - |b, m| b.iter(|| encrypt_to_donald_sign_by_ivanka(&m)), + |b, m| b.iter(|| encrypt_to_donald_sign_by_ivanka(m)), ); } group.finish(); diff --git a/openpgp/benches/sign_message.rs b/openpgp/benches/sign_message.rs index 419be8bb..267ea91d 100644 --- a/openpgp/benches/sign_message.rs +++ b/openpgp/benches/sign_message.rs @@ -32,7 +32,7 @@ fn bench_sign(c: &mut Criterion) { group.bench_with_input( BenchmarkId::new("cert", message.len()), &message, - |b, m| b.iter(|| sign_by_testy(&m)), + |b, m| b.iter(|| sign_by_testy(m)), ); } group.finish(); diff --git a/openpgp/benches/verify_message.rs b/openpgp/benches/verify_message.rs index 8dfd3740..200cfb93 100644 --- a/openpgp/benches/verify_message.rs +++ b/openpgp/benches/verify_message.rs @@ -16,7 +16,7 @@ lazy_static::lazy_static! { fn verify(bytes: &[u8], sender: &Cert) { let mut sink = Vec::new(); - decrypt::verify(&mut sink, &bytes, sender).unwrap(); + decrypt::verify(&mut sink, bytes, sender).unwrap(); } fn bench_verify(c: &mut Criterion) { @@ -34,7 +34,7 @@ fn bench_verify(c: &mut Criterion) { group.bench_with_input( BenchmarkId::new("verify", m.len()), &signed, - |b, s| b.iter(|| verify(&s, &SENDER)), + |b, s| b.iter(|| verify(s, &SENDER)), ); }); diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs index fc262ee8..d0c5023d 100644 --- a/openpgp/examples/statistics.rs +++ b/openpgp/examples/statistics.rs @@ -176,7 +176,7 @@ fn main() -> openpgp::Result<()> { SubpacketValue::Unknown { .. } => unreachable!(), SubpacketValue::KeyFlags(k) => - if let Some(count) = key_flags.get_mut(&k) { + if let Some(count) = key_flags.get_mut(k) { *count += 1; } else { key_flags.insert(k.clone(), 1); @@ -437,7 +437,7 @@ fn main() -> openpgp::Result<()> { // Sort by the number of occurrences. let mut kf = key_flags.iter().map(|(f, n)| (format!("{:?}", f), n)) .collect::<Vec<_>>(); - kf.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + kf.sort_unstable_by(|a, b| b.1.cmp(a.1)); for (f, n) in kf.iter() { println!("{:>22} {:>9}", f, n); } @@ -456,7 +456,7 @@ fn main() -> openpgp::Result<()> { let a = format!("{:?}", a); (a[1..a.len()-1].to_string(), n) }).collect::<Vec<_>>(); - preferences.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + preferences.sort_unstable_by(|a, b| b.1.cmp(a.1)); for (a, n) in preferences { println!("{:>70} {:>9}", a, n); } @@ -475,7 +475,7 @@ fn main() -> openpgp::Result<()> { let a = format!("{:?}", a); (a[1..a.len()-1].to_string(), n) }).collect::<Vec<_>>(); - preferences.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + preferences.sort_unstable_by(|a, b| b.1.cmp(a.1)); for (a, n) in preferences { let a = format!("{:?}", a); println!("{:>70} {:>9}", &a[1..a.len()-1], n); @@ -495,7 +495,7 @@ fn main() -> openpgp::Result<()> { let a = format!("{:?}", a); (a[1..a.len()-1].to_string(), n) }).collect::<Vec<_>>(); - preferences.sort_unstable_by(|a, b| b.1.cmp(&a.1)); + preferences.sort_unstable_by(|a, b| b.1.cmp(a.1)); for (a, n) in preferences { let a = format!("{:?}", a); println!("{:>70} {:>9}", &a[1..a.len()-1], n); diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index 968fe025..a1eb3c7c 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -934,7 +934,7 @@ impl<'a> Reader<'a> { } // Possible ASCII-armor header. - if let Some((label, len)) = Label::detect_header(&input) { + if let Some((label, len)) = Label::detect_header(input) { if label == Label::CleartextSignature && ! self.enable_csft { // We found a message using the Cleartext @@ -1422,7 +1422,7 @@ impl<'a> Reader<'a> { armored data")); } - let (dashes, rest) = dash_prefix(&line); + let (dashes, rest) = dash_prefix(line); if dashes.len() > 2 // XXX: heuristic... && rest.starts_with(b"BEGIN PGP SIGNATURE") { diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs index 0d2d3dcf..3ab5ce65 100644 --- a/openpgp/src/cert.rs +++ b/openpgp/src/cert.rs @@ -814,7 +814,7 @@ impl Cert { /// ``` pub fn primary_key(&self) -> PrimaryKeyAmalgamation<key::PublicParts> { - PrimaryKeyAmalgamation::new(&self) + PrimaryKeyAmalgamation::new(self) } /// Returns the certificate's revocation status. @@ -961,7 +961,7 @@ impl Cert { { CertRevocationBuilder::new() .set_reason_for_revocation(code, reason)? - .build(primary_signer, &self, None) + .build(primary_signer, self, None) } /// Sets the key to expire in delta seconds. @@ -2477,29 +2477,29 @@ impl Cert { // they match, then we keep whatever is in the // new key. (Packet::PublicKey(a), Packet::PublicKey(b)) => - (a.public_cmp(&b) == Ordering::Equal, + (a.public_cmp(b) == Ordering::Equal, a == b), (Packet::SecretKey(a), Packet::SecretKey(b)) => - (a.public_cmp(&b) == Ordering::Equal, + (a.public_cmp(b) == Ordering::Equal, a == b), (Packet::PublicKey(a), Packet::SecretKey(b)) => - (a.public_cmp(&b) == Ordering::Equal, + (a.public_cmp(b) == Ordering::Equal, false), (Packet::SecretKey(a), Packet::PublicKey(b)) => - (a.public_cmp(&b) == Ordering::Equal, + (a.public_cmp(b) == Ordering::Equal, false), (Packet::PublicSubkey(a), Packet::PublicSubkey(b)) => - (a.public_cmp(&b) == Ordering::Equal, + (a.public_cmp(b) == Ordering::Equal, a == b), (Packet::SecretSubkey(a), Packet::SecretSubkey(b)) => - (a.public_cmp(&b) == Ordering::Equal, + (a.public_c |