From 85362f33d81ebdc1cd355454be2494b9286e80be Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 27 Sep 2021 09:04:34 +0300 Subject: Avoid naming field setting it from variable of the same name When creating a struct with a field foo, using a variable also named foo, it's not necessary to name the field explicitly. Thus, instead of: Self { foo: foo } use this: Self { foo } The shorter form is more idiomatic and thus less confusing to experienced Rust programmers. This was found by the clippy lint redundant_field_names: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names Sponsored-by: author --- openpgp/src/cert/amalgamation.rs | 8 +++--- openpgp/src/cert/amalgamation/key.rs | 6 ++-- openpgp/src/packet/signature.rs | 2 +- openpgp/src/parse.rs | 12 ++++---- openpgp/src/parse/map.rs | 4 +-- openpgp/src/parse/mpis.rs | 46 +++++++++++++++--------------- openpgp/src/parse/packet_parser_builder.rs | 2 +- openpgp/src/parse/packet_pile_parser.rs | 2 +- openpgp/src/parse/stream.rs | 10 +++---- 9 files changed, 46 insertions(+), 46 deletions(-) (limited to 'openpgp') diff --git a/openpgp/src/cert/amalgamation.rs b/openpgp/src/cert/amalgamation.rs index 620980c4..f7c4e51d 100644 --- a/openpgp/src/cert/amalgamation.rs +++ b/openpgp/src/cert/amalgamation.rs @@ -887,11 +887,11 @@ macro_rules! impl_with_policy { Ok(ValidComponentAmalgamation { ca: self, cert: ValidCert { - cert: cert, - policy: policy, - time: time, + cert, + policy, + time, }, - binding_signature: binding_signature, + binding_signature, }) } } diff --git a/openpgp/src/cert/amalgamation/key.rs b/openpgp/src/cert/amalgamation/key.rs index d5c99153..a0614340 100644 --- a/openpgp/src/cert/amalgamation/key.rs +++ b/openpgp/src/cert/amalgamation/key.rs @@ -597,9 +597,9 @@ impl<'a, P> ValidateAmalgamation<'a, Key> // need to check the user's policy. So, it is safe to // create a ValidCert from scratch. cert: ValidCert { - cert: cert, - policy: policy, - time: time, + cert, + policy, + time, }, binding_signature }; diff --git a/openpgp/src/packet/signature.rs b/openpgp/src/packet/signature.rs index 3e46e79e..2db99a39 100644 --- a/openpgp/src/packet/signature.rs +++ b/openpgp/src/packet/signature.rs @@ -1685,7 +1685,7 @@ impl From for SignatureBuilder { SignatureBuilder { overrode_creation_time: false, original_creation_time: creation_time, - fields: fields, + fields, } } } diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 068bdd6b..cae96fc8 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -452,11 +452,11 @@ impl<'a, T: 'a + BufferedReader> PacketHeaderParser { }; PacketHeaderParser { reader: buffered_reader::Dup::with_cookie(inner, cookie), - header: header, - header_bytes: header_bytes, - path: path, - state: state, - map: map, + header, + header_bytes, + path, + state, + map, } } @@ -3050,7 +3050,7 @@ struct PacketParserState { impl PacketParserState { fn new(settings: PacketParserSettings) -> Self { PacketParserState { - settings: settings, + settings, message_validator: Default::default(), keyring_validator: Default::default(), cert_validator: Default::default(), diff --git a/openpgp/src/parse/map.rs b/openpgp/src/parse/map.rs index b0c7bbea..d5012e39 100644 --- a/openpgp/src/parse/map.rs +++ b/openpgp/src/parse/map.rs @@ -50,7 +50,7 @@ impl Map { Map { length: 0, entries: Vec::new(), - header: header, + header, data: Vec::new(), } } @@ -235,7 +235,7 @@ struct Iter<'a> { impl<'a> Iter<'a> { fn new(map: &'a Map) -> Iter<'a> { Iter { - map: map, + map, i: 0, } } diff --git a/openpgp/src/parse/mpis.rs b/openpgp/src/parse/mpis.rs index 35537c0f..f03eb097 100644 --- a/openpgp/src/parse/mpis.rs +++ b/openpgp/src/parse/mpis.rs @@ -48,7 +48,7 @@ impl mpi::PublicKey { let n = MPI::parse("rsa_public_n_len", "rsa_public_n", php)?; let e = MPI::parse("rsa_public_e_len", "rsa_public_e", php)?; - Ok(mpi::PublicKey::RSA { e: e, n: n }) + Ok(mpi::PublicKey::RSA { e, n }) } DSA => { @@ -58,10 +58,10 @@ impl mpi::PublicKey { let y = MPI::parse("dsa_public_y_len", "dsa_public_y", php)?; Ok(mpi::PublicKey::DSA { - p: p, - q: q, - g: g, - y: y, + p, + q, + g, + y, }) } @@ -74,9 +74,9 @@ impl mpi::PublicKey { php)?; Ok(mpi::PublicKey::ElGamal { - p: p, - g: g, - y: y, + p, + g, + y, }) } @@ -87,7 +87,7 @@ impl mpi::PublicKey { Ok(mpi::PublicKey::EdDSA { curve: Curve::from_oid(&curve), - q: q + q }) } @@ -98,7 +98,7 @@ impl mpi::PublicKey { Ok(mpi::PublicKey::ECDSA { curve: Curve::from_oid(&curve), - q: q + q }) } @@ -332,7 +332,7 @@ impl mpi::Ciphertext { php)?; Ok(mpi::Ciphertext::RSA { - c: c, + c, }) } @@ -341,8 +341,8 @@ impl mpi::Ciphertext { let c = MPI::parse("elgamal_c_len", "elgamal_c", php)?; Ok(mpi::Ciphertext::ElGamal { - e: e, - c: c, + e, + c, }) } @@ -353,7 +353,7 @@ impl mpi::Ciphertext { [..key_len]); Ok(mpi::Ciphertext::ECDH { - e: e, key: key.into_boxed_slice() + e, key: key.into_boxed_slice() }) } @@ -410,7 +410,7 @@ impl mpi::Signature { let s = MPI::parse("rsa_signature_len", "rsa_signature", php)?; Ok(mpi::Signature::RSA { - s: s, + s, }) } @@ -421,8 +421,8 @@ impl mpi::Signature { php)?; Ok(mpi::Signature::DSA { - r: r, - s: s, + r, + s, }) } @@ -433,8 +433,8 @@ impl mpi::Signature { "elgamal_sig_s", php)?; Ok(mpi::Signature::ElGamal { - r: r, - s: s, + r, + s, }) } @@ -445,8 +445,8 @@ impl mpi::Signature { php)?; Ok(mpi::Signature::EdDSA { - r: r, - s: s, + r, + s, }) } @@ -457,8 +457,8 @@ impl mpi::Signature { php)?; Ok(mpi::Signature::ECDSA { - r: r, - s: s, + r, + s, }) } diff --git a/openpgp/src/parse/packet_parser_builder.rs b/openpgp/src/parse/packet_parser_builder.rs index 7459f0be..d94a5d2e 100644 --- a/openpgp/src/parse/packet_parser_builder.rs +++ b/openpgp/src/parse/packet_parser_builder.rs @@ -133,7 +133,7 @@ impl<'a> PacketParserBuilder<'a> { -> Result { bio.cookie_mut().level = None; Ok(PacketParserBuilder { - bio: bio, + bio, dearmor: Default::default(), settings: PacketParserSettings::default(), csf_transformation: false, diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 22b1f82f..8523330a 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -252,7 +252,7 @@ impl<'a> PacketPileParser<'a> { { Ok(PacketPileParser { pile: Default::default(), - ppr: ppr, + ppr, }) } diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index f40c3f0d..efb5755e 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -458,8 +458,8 @@ impl<'a> MessageStructure<'a> { fn new_encryption_layer(&mut self, sym_algo: SymmetricAlgorithm, aead_algo: Option) { self.0.push(MessageLayer::Encryption { - sym_algo: sym_algo, - aead_algo: aead_algo, + sym_algo, + aead_algo, }) } @@ -597,8 +597,8 @@ impl IMessageStructure { self.layers.push(IMessageLayer::Encryption { depth, expect_mdc, - sym_algo: sym_algo, - aead_algo: aead_algo, + sym_algo, + aead_algo, }); } @@ -2784,7 +2784,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> { sigid[0], sigid[1], ka.fingerprint()); results.push_verification_result( Ok(GoodChecksum { - sig: sig, + sig, ka, })); // Continue to the next sig. -- cgit v1.2.3