Skip to content

Commit

Permalink
Fix clippy errors for 1.85.0. (#490)
Browse files Browse the repository at this point in the history
* Fix clippy errors for 1.85.0.

* Also fix nightly clippies.

* Restore comment.

* Remove redundant ok()
  • Loading branch information
Philip-NLnetLabs authored Feb 26, 2025
1 parent 2d17c29 commit bcb4e85
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 50 deletions.
6 changes: 1 addition & 5 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ fn main() {
socket.recv_from(&mut buffer).unwrap();

// Parse and print the response
let response = match Message::from_octets(buffer) {
Ok(response) => Some(response),
Err(_) => None,
}
.unwrap();
let response = Message::from_octets(buffer).unwrap();

for question in response.question() {
println!("{}", question.unwrap());
Expand Down
2 changes: 1 addition & 1 deletion src/base/iana/rcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl OptRcode {
/// Creates an extended rcode value from its parts.
#[must_use]
pub fn from_parts(rcode: Rcode, ext: u8) -> OptRcode {
OptRcode(u16::from(ext) << 4 | u16::from(rcode.to_int()))
OptRcode((u16::from(ext) << 4) | u16::from(rcode.to_int()))
}

/// Returns the two parts of an extended rcode value.
Expand Down
2 changes: 1 addition & 1 deletion src/base/message_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ impl<Target: Composer> AdditionalBuilder<Target> {
F: FnOnce(&mut OptBuilder<Target>) -> Result<(), Target::AppendError>,
{
self.authority.answer.builder.push(
|target| OptBuilder::new(target)?.build(op).map_err(Into::into),
|target| OptBuilder::new(target)?.build(op),
|counts| counts.inc_arcount(),
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/base/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ impl<Octs> OptRecord<Octs> {
Name::root_slice(),
Class::from_int(self.udp_payload_size),
Ttl::from_secs(
u32::from(self.ext_rcode) << 24
| u32::from(self.version) << 16
(u32::from(self.ext_rcode) << 24)
| (u32::from(self.version) << 16)
| u32::from(self.flags),
),
self.data.for_slice_ref(),
Expand Down
2 changes: 1 addition & 1 deletion src/base/opt/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl<Target: Composer> OptBuilder<'_, Target> {

/// Returns the number of bytes needed for a prefix of a given length
fn prefix_bytes(bits: u8) -> usize {
(usize::from(bits) + 7) / 8
usize::from(bits).div_ceil(8)
}

/// Only keeps the left-most `mask` bits and zeros out the rest.
Expand Down
2 changes: 1 addition & 1 deletion src/base/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ const SECS_PER_DAY: u32 = 86400;
///
/// Two reasons make [`std::time::Duration`] not suited for representing DNS TTL values:
/// 1. According to [RFC 2181](https://datatracker.ietf.org/doc/html/rfc2181#section-8) TTL values have second-level precision while [`std::time::Duration`] can represent time down to the nanosecond level.
/// This amount of precision is simply not needed and might cause confusion when sending `Duration`s over the network.
/// This amount of precision is simply not needed and might cause confusion when sending `Duration`s over the network.
/// 2. When working with DNS TTL values it's common to want to know a time to live in minutes or hours. [`std::time::Duration`] does not expose easy to use methods for this purpose, while `Ttl` does.
///
/// `Ttl` provides two methods [`Ttl::from_duration_lossy`] and [`Ttl::into_duration`] to convert between `Duration` and `Ttl`.
Expand Down
4 changes: 2 additions & 2 deletions src/net/server/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use super::ServerCommand;
/// - "A timeout of at least a few seconds is advisable for normal
/// operations".
/// - "Servers MAY use zero timeouts when they are experiencing heavy load or
/// are under attack".
/// are under attack".
/// - "Servers MAY allow idle connections to remain open for longer periods as
/// resources permit".
///
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Config {
/// - "A timeout of at least a few seconds is advisable for normal
/// operations".
/// - "Servers MAY use zero timeouts when they are experiencing heavy load
/// or are under attack".
/// or are under attack".
/// - "Servers MAY allow idle connections to remain open for longer
/// periods as resources permit".
///
Expand Down
2 changes: 1 addition & 1 deletion src/rdata/dnssec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,7 @@ impl Iterator for RtypeBitmapIter<'_> {
return None;
}
let res =
Rtype::from_int(self.block | (self.octet as u16) << 3 | self.bit);
Rtype::from_int(self.block | ((self.octet as u16) << 3) | self.bit);
self.advance();
Some(res)
}
Expand Down
2 changes: 1 addition & 1 deletion src/rdata/rfc1035/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<Octs: FromBuilder> Txt<Octs> {
{
let mut builder = TxtBuilder::<Octs::Builder>::new();
builder.append_slice(text)?;
builder.finish().map_err(Into::into)
builder.finish()
}
}

Expand Down
46 changes: 26 additions & 20 deletions src/utils/base32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,24 @@ where
f.write_char(ch((chunk[0] & 0x07) << 2))?; // 1
break;
}
f.write_char(ch((chunk[0] & 0x07) << 2 | chunk[1] >> 6))?; // 1
f.write_char(ch(((chunk[0] & 0x07) << 2) | (chunk[1] >> 6)))?; // 1
f.write_char(ch((chunk[1] & 0x3F) >> 1))?; // 2
if chunk.len() == 2 {
f.write_char(ch((chunk[1] & 0x01) << 4))?; // 3
break;
}
f.write_char(ch((chunk[1] & 0x01) << 4 | chunk[2] >> 4))?; // 3
f.write_char(ch(((chunk[1] & 0x01) << 4) | (chunk[2] >> 4)))?; // 3
if chunk.len() == 3 {
f.write_char(ch((chunk[2] & 0x0F) << 1))?; // 4
break;
}
f.write_char(ch((chunk[2] & 0x0F) << 1 | chunk[3] >> 7))?; // 4
f.write_char(ch(((chunk[2] & 0x0F) << 1) | (chunk[3] >> 7)))?; // 4
f.write_char(ch((chunk[3] & 0x7F) >> 2))?; // 5
if chunk.len() == 4 {
f.write_char(ch((chunk[3] & 0x03) << 3))?; // 6
break;
}
f.write_char(ch((chunk[3] & 0x03) << 3 | chunk[4] >> 5))?; // 6
f.write_char(ch(((chunk[3] & 0x03) << 3) | (chunk[4] >> 5)))?; // 6
f.write_char(ch(chunk[4] & 0x1F))?; // 7
}
Ok(())
Expand Down Expand Up @@ -319,31 +319,31 @@ impl<Builder: OctetsBuilder> Decoder<Builder> {

/// Decodes the zeroth octet in a base 32 sequence.
fn octet_0(&mut self) {
let ch = self.buf[0] << 3 | self.buf[1] >> 2;
let ch = (self.buf[0] << 3) | (self.buf[1] >> 2);
self.append(ch)
}

/// Decodes the first octet in a base 32 sequence.
fn octet_1(&mut self) {
let ch = self.buf[1] << 6 | self.buf[2] << 1 | self.buf[3] >> 4;
let ch = (self.buf[1] << 6) | (self.buf[2] << 1) | (self.buf[3] >> 4);
self.append(ch)
}

/// Decodes the second octet in a base 32 sequence.
fn octet_2(&mut self) {
let ch = self.buf[3] << 4 | self.buf[4] >> 1;
let ch = (self.buf[3] << 4) | (self.buf[4] >> 1);
self.append(ch)
}

/// Decodes the third octet in a base 32 sequence.
fn octet_3(&mut self) {
let ch = self.buf[4] << 7 | self.buf[5] << 2 | self.buf[6] >> 3;
let ch = (self.buf[4] << 7) | (self.buf[5] << 2) | (self.buf[6] >> 3);
self.append(ch)
}

/// Decodes the forth octet in a base 32 sequence.
fn octet_4(&mut self) {
let ch = self.buf[6] << 5 | self.buf[7];
let ch = (self.buf[6] << 5) | self.buf[7];
self.append(ch)
}

Expand Down Expand Up @@ -417,11 +417,15 @@ impl SymbolConverter {

if self.next == 8 {
self.output = [
self.input[0] << 3 | self.input[1] >> 2,
self.input[1] << 6 | self.input[2] << 1 | self.input[3] >> 4,
self.input[3] << 4 | self.input[4] >> 1,
self.input[4] << 7 | self.input[5] << 2 | self.input[6] >> 3,
self.input[6] << 5 | self.input[7],
(self.input[0] << 3) | (self.input[1] >> 2),
(self.input[1] << 6)
| (self.input[2] << 1)
| (self.input[3] >> 4),
(self.input[3] << 4) | (self.input[4] >> 1),
(self.input[4] << 7)
| (self.input[5] << 2)
| (self.input[6] >> 3),
(self.input[6] << 5) | self.input[7],
];
self.next = 0;
Ok(Some(&self.output))
Expand Down Expand Up @@ -459,21 +463,23 @@ where
1 | 3 | 6 => return Err(Error::custom("short Base 32 input")),
_ => {}
}
self.output[0] = self.input[0] << 3 | self.input[1] >> 2;
self.output[0] = (self.input[0] << 3) | (self.input[1] >> 2);
if self.next == 2 {
return Ok(Some(&self.output[0..1]));
}
self.output[1] =
self.input[1] << 6 | self.input[2] << 1 | self.input[3] >> 4;
self.output[1] = (self.input[1] << 6)
| (self.input[2] << 1)
| (self.input[3] >> 4);
if self.next == 4 {
return Ok(Some(&self.output[0..2]));
}
self.output[2] = self.input[3] << 4 | self.input[4] >> 1;
self.output[2] = (self.input[3] << 4) | (self.input[4] >> 1);
if self.next == 5 {
return Ok(Some(&self.output[0..3]));
}
self.output[3] =
self.input[4] << 7 | self.input[5] << 2 | self.input[6] >> 3;
self.output[3] = (self.input[4] << 7)
| (self.input[5] << 2)
| (self.input[6] >> 3);
Ok(Some(&self.output[0..4]))
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/utils/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ where
}
2 => {
f.write_char(ch(chunk[0] >> 2))?;
f.write_char(ch((chunk[0] & 0x03) << 4 | chunk[1] >> 4))?;
f.write_char(ch(((chunk[0] & 0x03) << 4) | (chunk[1] >> 4)))?;
f.write_char(ch((chunk[1] & 0x0F) << 2))?;
f.write_char('=')?;
}
3 => {
f.write_char(ch(chunk[0] >> 2))?;
f.write_char(ch((chunk[0] & 0x03) << 4 | chunk[1] >> 4))?;
f.write_char(ch((chunk[1] & 0x0F) << 2 | chunk[2] >> 6))?;
f.write_char(ch(((chunk[0] & 0x03) << 4) | (chunk[1] >> 4)))?;
f.write_char(ch(((chunk[1] & 0x0F) << 2) | (chunk[2] >> 6)))?;
f.write_char(ch(chunk[2] & 0x3F))?;
}
_ => unreachable!(),
Expand Down Expand Up @@ -280,11 +280,11 @@ impl<Builder: OctetsBuilder> Decoder<Builder> {
if self.next == 4 {
let target = self.target.as_mut().unwrap(); // Err covered above.
target
.append_slice(&[self.buf[0] << 2 | self.buf[1] >> 4])
.append_slice(&[(self.buf[0] << 2) | (self.buf[1] >> 4)])
.map_err(Into::into)?;
if self.buf[2] != 0x80 {
target
.append_slice(&[self.buf[1] << 4 | self.buf[2] >> 2])
.append_slice(&[(self.buf[1] << 4) | (self.buf[2] >> 2)])
.map_err(Into::into)?;
}
if self.buf[3] != 0x80 {
Expand Down Expand Up @@ -368,7 +368,7 @@ impl SymbolConverter {
self.next += 1;

if self.next == 4 {
self.output[0] = self.input[0] << 2 | self.input[1] >> 4;
self.output[0] = (self.input[0] << 2) | (self.input[1] >> 4);

if self.input[2] == PAD_MARKER {
// The second to last character is padding. The last one
Expand All @@ -380,7 +380,7 @@ impl SymbolConverter {
Err(Error::custom("illegal Base 64 data"))
}
} else {
self.output[1] = self.input[1] << 4 | self.input[2] >> 2;
self.output[1] = (self.input[1] << 4) | (self.input[2] >> 2);

if self.input[3] == PAD_MARKER {
// The last characters is padding.
Expand Down
11 changes: 3 additions & 8 deletions src/validator/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,9 @@ pub fn make_ede(
code: ExtendedErrorCode,
reason: &str,
) -> Option<ExtendedError<Vec<u8>>> {
match ExtendedError::new_with_str(code, reason) {
Ok(ede) => Some(ede),
Err(_) => {
// Assume that the only reason this case fail is a string that
// is way too long. Just return None.
None
}
}
// Assume that the only reason this case fail is a string that
// is way too long. Just return None.
ExtendedError::new_with_str(code, reason).ok()
}

/// Create a new DNS message based on the original message that fixes any
Expand Down

0 comments on commit bcb4e85

Please sign in to comment.