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/src/parse.rs | |
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/src/parse.rs')
-rw-r--r-- | openpgp/src/parse.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index fbb5cfff..803813e8 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -1447,8 +1447,8 @@ impl Signature4 { // The absolute minimum size for the header is 11 bytes (this // doesn't include the signature MPIs). - if let &BodyLength::Full(len) = header.length() { - if len < 11 { + if let BodyLength::Full(len) = header.length() { + if *len < 11 { // Much too short. return Err( Error::MalformedPacket("Packet too short".into()).into()); @@ -2290,8 +2290,8 @@ impl Key4<key::UnspecifiedParts, key::UnspecifiedRole> bio: &mut buffered_reader::Dup<T, Cookie>, header: &Header) -> Result<()> { // The packet's header is 6 bytes. - if let &BodyLength::Full(len) = header.length() { - if len < 6 { + if let BodyLength::Full(len) = header.length() { + if *len < 6 { // Much too short. return Err(Error::MalformedPacket( format!("Packet too short ({} bytes)", len)).into()); @@ -2402,7 +2402,8 @@ impl Marker { -> Result<()> where T: BufferedReader<Cookie>, { - if let &BodyLength::Full(len) = header.length() { + if let BodyLength::Full(len) = header.length() { + let len = *len; if len as usize != Marker::BODY.len() { return Err(Error::MalformedPacket( format!("Unexpected packet length {}", len)).into()); @@ -4342,9 +4343,9 @@ impl <'a> PacketParser<'a> { Tag::Literal | Tag::CompressedData | Tag::SED | Tag::SEIP | Tag::AED => (), _ => match header.length() { - &BodyLength::Full(l) => if l > max_size { + BodyLength::Full(l) => if *l > max_size { header_syntax_error = Some( - Error::PacketTooLarge(tag, l, max_size).into()); + Error::PacketTooLarge(tag, *l, max_size).into()); }, _ => unreachable!("non-data packets have full length, \ syntax check above"), |