Skip to content

Commit

Permalink
Apply clippy suggestions for Rust 1.79
Browse files Browse the repository at this point in the history
  • Loading branch information
djc authored and bluejekyll committed Jun 14, 2024
1 parent e585bf0 commit c505f84
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 45 deletions.
3 changes: 3 additions & 0 deletions bin/tests/server_harness/mut_message_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use hickory_client::client::*;
use hickory_client::proto::xfer::{DnsHandle, DnsRequest};
#[cfg(feature = "dnssec")]
use hickory_client::{op::Edns, rr::rdata::opt::EdnsOption};
#[cfg(feature = "dnssec")]
use hickory_server::authority::LookupOptions;

#[derive(Clone)]
pub struct MutMessageHandle<C: ClientHandle + Unpin> {
client: C,
#[cfg(feature = "dnssec")]
pub lookup_options: LookupOptions,
}

Expand All @@ -15,6 +17,7 @@ impl<C: ClientHandle + Unpin> MutMessageHandle<C> {
pub fn new(client: C) -> Self {
MutMessageHandle {
client,
#[cfg(feature = "dnssec")]
lookup_options: Default::default(),
}
}
Expand Down
7 changes: 1 addition & 6 deletions crates/client/src/client/async_secure_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// https://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// https://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
#![cfg(feature = "dnssec")]

use std::future::Future;
use std::pin::Pin;
Expand Down Expand Up @@ -108,11 +107,7 @@ where
pub async fn build(
mut self,
) -> Result<(AsyncDnssecClient, DnsExchangeBackground<S, TokioTime>), ProtoError> {
let trust_anchor = if let Some(trust_anchor) = self.trust_anchor.take() {
trust_anchor
} else {
TrustAnchor::default()
};
let trust_anchor = self.trust_anchor.take().unwrap_or_default();
let result = AsyncClient::connect(self.connect_future).await;

result.map(|(client, bg)| (AsyncDnssecClient::from_client(client, trust_anchor), bg))
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/multicast/mdns_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl Future for NextRandomUdpSocket {
//
// The dynamic port range defined by IANA consists of the 49152-65535
// range, and is meant for the selection of ephemeral ports.
let rand_port_range = Uniform::new_inclusive(49152_u16, u16::max_value());
let rand_port_range = Uniform::new_inclusive(49152_u16, u16::MAX);
let mut rand = rand::thread_rng();

for attempt in 0..10 {
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/op/edns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl BinEncodable for Edns {
let place = encoder.place::<u16>()?;
self.options.emit(encoder)?;
let len = encoder.len_since_place(&place);
assert!(len <= u16::max_value() as usize);
assert!(len <= u16::MAX as usize);

place.replace(encoder, len as u16)?;
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions crates/proto/src/op/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ pub fn update_header_counts(
is_truncated: bool,
counts: HeaderCounts,
) -> Header {
assert!(counts.query_count <= u16::max_value() as usize);
assert!(counts.answer_count <= u16::max_value() as usize);
assert!(counts.nameserver_count <= u16::max_value() as usize);
assert!(counts.additional_count <= u16::max_value() as usize);
assert!(counts.query_count <= u16::MAX as usize);
assert!(counts.answer_count <= u16::MAX as usize);
assert!(counts.nameserver_count <= u16::MAX as usize);
assert!(counts.additional_count <= u16::MAX as usize);

// TODO: should the function just take by value?
let mut header = *current_header;
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/rr/dnssec/rsa_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct RSAPublicKey<'a> {
}

impl<'a> RSAPublicKey<'a> {
pub(crate) fn try_from(encoded: &'a [u8]) -> ProtoResult<RSAPublicKey<'a>> {
pub(crate) fn try_from(encoded: &'a [u8]) -> ProtoResult<Self> {
let (e_len_len, e_len) = match encoded.first() {
Some(&0) if encoded.len() >= 3 => {
(3, (usize::from(encoded[1]) << 8) | usize::from(encoded[2]))
Expand Down
4 changes: 2 additions & 2 deletions crates/proto/src/rr/dnssec/supported_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl SupportedAlgorithms {

/// Return the count of supported algorithms
pub fn len(self) -> u16 {
// this is pretty much guaranteed to be less that u16::max_value()
// this is pretty much guaranteed to be less that u16::MAX
self.iter().count() as u16
}

Expand Down Expand Up @@ -193,7 +193,7 @@ impl<'a> Iterator for SupportedAlgorithmsIter<'a> {
type Item = Algorithm;
fn next(&mut self) -> Option<Self::Item> {
// some quick bounds checking
if self.current > u8::max_value() as usize {
if self.current > u8::MAX as usize {
return None;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/rr/domain/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ mod tests {
use crate::error::ProtoErrorKind;

// u16 max value is where issues start being tickled...
let mut buf = Vec::with_capacity(u16::max_value() as usize);
let mut buf = Vec::with_capacity(u16::MAX as usize);
let mut encoder = BinEncoder::new(&mut buf);

let mut result = Ok(());
Expand Down
4 changes: 2 additions & 2 deletions crates/proto/src/rr/rdata/caa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ fn emit_tag(buf: &mut [u8], tag: &Property) -> ProtoResult<u8> {
let property = property.as_bytes();

let len = property.len();
if len > ::std::u8::MAX as usize {
if len > u8::MAX as usize {
return Err(format!("CAA property too long: {len}").into());
}
if buf.len() < len {
Expand Down Expand Up @@ -713,7 +713,7 @@ impl BinEncodable for CAA {

encoder.emit(flags)?;
// TODO: it might be interesting to use the new place semantics here to output all the data, then place the length back to the beginning...
let mut tag_buf = [0_u8; ::std::u8::MAX as usize];
let mut tag_buf = [0_u8; u8::MAX as usize];
let len = emit_tag(&mut tag_buf, &self.tag)?;

// now write to the encoder
Expand Down
12 changes: 6 additions & 6 deletions crates/proto/src/rr/record_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,11 @@ mod tests {
RData::SOA(SOA::new(
Name::from_str("www.example.com").unwrap(),
Name::from_str("xxx.example.com").unwrap(),
u32::max_value(),
u32::MAX,
-1,
-1,
-1,
u32::max_value(),
u32::MAX,
)),
vec![
3, b'w', b'w', b'w', 7, b'e', b'x', b'a', b'm', b'p', b'l', b'e', 3, b'c',
Expand Down Expand Up @@ -1192,11 +1192,11 @@ mod tests {
RData::SOA(SOA::new(
Name::from_str("www.example.com").unwrap(),
Name::from_str("xxx.example.com").unwrap(),
u32::max_value(),
u32::MAX,
-1,
-1,
-1,
u32::max_value(),
u32::MAX,
)),
RData::TXT(TXT::new(vec![
"abcdef".to_string(),
Expand All @@ -1213,11 +1213,11 @@ mod tests {
RData::SOA(SOA::new(
Name::from_str("www.example.com").unwrap(),
Name::from_str("xxx.example.com").unwrap(),
u32::max_value(),
u32::MAX,
-1,
-1,
-1,
u32::max_value(),
u32::MAX,
)),
RData::TXT(TXT::new(vec![
"abcdef".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/rr/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl<R: RecordData> BinEncodable for Record<R> {

// get the length written
let len = encoder.len_since_place(&place);
assert!(len <= u16::max_value() as usize);
assert!(len <= u16::MAX as usize);

// replace the location with the length
place.replace(encoder, len as u16)?;
Expand Down
10 changes: 5 additions & 5 deletions crates/proto/src/serialize/binary/bin_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn get_u16_data() -> Vec<(u16, Vec<u8>)> {
(0, vec![0x00, 0x00]),
(1, vec![0x00, 0x01]),
(256, vec![0x01, 0x00]),
(u16::max_value(), vec![0xFF, 0xFF]),
(u16::MAX, vec![0xFF, 0xFF]),
]
}

Expand All @@ -75,8 +75,8 @@ fn get_i32_data() -> Vec<(i32, Vec<u8>)> {
(256 * 256, vec![0x00, 0x01, 0x00, 0x00]),
(256 * 256 * 256, vec![0x01, 0x00, 0x00, 0x00]),
(-1, vec![0xFF, 0xFF, 0xFF, 0xFF]),
(i32::min_value(), vec![0x80, 0x00, 0x00, 0x00]),
(i32::max_value(), vec![0x7F, 0xFF, 0xFF, 0xFF]),
(i32::MIN, vec![0x80, 0x00, 0x00, 0x00]),
(i32::MAX, vec![0x7F, 0xFF, 0xFF, 0xFF]),
]
}

Expand All @@ -100,9 +100,9 @@ fn get_u32_data() -> Vec<(u32, Vec<u8>)> {
(256, vec![0x00, 0x00, 0x01, 0x00]),
(256 * 256, vec![0x00, 0x01, 0x00, 0x00]),
(256 * 256 * 256, vec![0x01, 0x00, 0x00, 0x00]),
(u32::max_value(), vec![0xFF, 0xFF, 0xFF, 0xFF]),
(u32::MAX, vec![0xFF, 0xFF, 0xFF, 0xFF]),
(2147483648, vec![0x80, 0x00, 0x00, 0x00]),
(i32::max_value() as u32, vec![0x7F, 0xFF, 0xFF, 0xFF]),
(i32::MAX as u32, vec![0x7F, 0xFF, 0xFF, 0xFF]),
]
}

Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/serialize/binary/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'a> BinDecoder<'a> {

/// This is a pretty efficient clone, as the buffer is never cloned, and only the index is set
/// to the value passed in
pub fn clone(&self, index_at: u16) -> BinDecoder<'a> {
pub fn clone(&self, index_at: u16) -> Self {
BinDecoder {
buffer: self.buffer,
remaining: &self.buffer[index_at as usize..],
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/serialize/txt/zone_lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) struct Lexer<'a> {

impl<'a> Lexer<'a> {
/// Creates a new lexer with the given data to parse
pub(crate) fn new(txt: impl Into<Cow<'a, str>>) -> Lexer<'a> {
pub(crate) fn new(txt: impl Into<Cow<'a, str>>) -> Self {
Lexer {
txt: CowChars {
data: txt.into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/proto/src/udp/udp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl<S: DnsUdpSocket + Send> Future for NextRandomUdpSocket<S> {
// As mentioned in Section 2.1, the dynamic ports consist of the range
// 49152-65535. However, ephemeral port selection algorithms should use
// the whole range 1024-65535.
let rand_port_range = Uniform::new_inclusive(1024_u16, u16::max_value());
let rand_port_range = Uniform::new_inclusive(1024_u16, u16::MAX);
let mut rand = rand::thread_rng();

for attempt in 0..10 {
Expand Down
4 changes: 2 additions & 2 deletions crates/resolver/src/caching_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,10 @@ mod tests {
vec![(
Record::from_rdata(
query.name().clone(),
u32::max_value(),
u32::MAX,
RData::A(A::new(127, 0, 0, 1)),
),
u32::max_value(),
u32::MAX,
)],
Instant::now(),
);
Expand Down
2 changes: 0 additions & 2 deletions crates/resolver/src/tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// https://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

#![cfg(feature = "dns-over-tls")]

mod dns_over_native_tls;
mod dns_over_openssl;
mod dns_over_rustls;
Expand Down
2 changes: 1 addition & 1 deletion crates/server/src/authority/message_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'q> MessageResponseBuilder<'q> {
/// # Arguments
///
/// * `query` - any optional query (from the Request) to associate with the Response
pub(crate) fn new(query: Option<&'q WireQuery>) -> MessageResponseBuilder<'q> {
pub(crate) fn new(query: Option<&'q WireQuery>) -> Self {
MessageResponseBuilder {
query,
sig0: None,
Expand Down
12 changes: 5 additions & 7 deletions crates/server/src/store/in_memory/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ impl InnerInMemory {
lookup_options: LookupOptions,
) -> Option<Arc<RecordSet>> {
// this range covers all the records for any of the RecordTypes at a given label.
let start_range_key = RrKey::new(name.clone(), RecordType::Unknown(u16::min_value()));
let end_range_key = RrKey::new(name.clone(), RecordType::Unknown(u16::max_value()));
let start_range_key = RrKey::new(name.clone(), RecordType::Unknown(u16::MIN));
let end_range_key = RrKey::new(name.clone(), RecordType::Unknown(u16::MAX));

fn aname_covers_type(key_type: RecordType, query_type: RecordType) -> bool {
(query_type == RecordType::A || query_type == RecordType::AAAA)
Expand Down Expand Up @@ -608,9 +608,8 @@ impl InnerInMemory {
}

// check that CNAME and ANAME is either not already present, or no other records are if it's a CNAME
let start_range_key =
RrKey::new(record.name().into(), RecordType::Unknown(u16::min_value()));
let end_range_key = RrKey::new(record.name().into(), RecordType::Unknown(u16::max_value()));
let start_range_key = RrKey::new(record.name().into(), RecordType::Unknown(u16::MIN));
let end_range_key = RrKey::new(record.name().into(), RecordType::Unknown(u16::MAX));

let multiple_records_at_label_disallowed = self
.records
Expand Down Expand Up @@ -1058,8 +1057,7 @@ impl Authority for InMemoryAuthority {
// in the case of ANAME the final record should be the A or AAAA record
let (rdatas, a_aaaa_ttl) = {
let last_record = additionals.last();
let a_aaaa_ttl =
last_record.map_or(u32::max_value(), |r| r.ttl());
let a_aaaa_ttl = last_record.map_or(u32::MAX, |r| r.ttl());

// grap the rdatas
let rdatas: Option<Vec<RData>> = last_record
Expand Down

0 comments on commit c505f84

Please sign in to comment.