Fix clippy because of MSV change

This commit is contained in:
Thibaut Vandervelden 2021-09-13 16:18:42 +02:00 committed by Dario Nieuwenhuis
parent 3ea597ce78
commit 82a62327ba
7 changed files with 23 additions and 12 deletions

View File

@ -854,7 +854,7 @@ where
Context {
now,
caps: self.device.capabilities(),
#[cfg(feature = "medium-ethernet")]
#[cfg(all(feature = "medium-ethernet", feature = "socket-dhcpv4"))]
ethernet_address: self.inner.ethernet_addr,
}
}

View File

@ -63,6 +63,7 @@ impl Answer {
pub struct Cache<'a> {
storage: ManagedMap<'a, IpAddress, Neighbor>,
silent_until: Instant,
#[cfg(any(feature = "std", feature = "alloc"))]
gc_threshold: usize,
}
@ -74,6 +75,7 @@ impl<'a> Cache<'a> {
pub(crate) const ENTRY_LIFETIME: Duration = Duration { millis: 60_000 };
/// Default number of entries in the cache before GC kicks in
#[cfg(any(feature = "std", feature = "alloc"))]
pub(crate) const GC_THRESHOLD: usize = 1024;
/// Create a cache. The backing storage is cleared upon creation.
@ -84,9 +86,18 @@ impl<'a> Cache<'a> {
where
T: Into<ManagedMap<'a, IpAddress, Neighbor>>,
{
Cache::new_with_limit(storage, Cache::GC_THRESHOLD)
let mut storage = storage.into();
storage.clear();
Cache {
storage,
#[cfg(any(feature = "std", feature = "alloc"))]
gc_threshold: Self::GC_THRESHOLD,
silent_until: Instant::from_millis(0),
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
pub fn new_with_limit<T>(storage: T, gc_threshold: usize) -> Cache<'a>
where
T: Into<ManagedMap<'a, IpAddress, Neighbor>>,

View File

@ -23,7 +23,6 @@ const MTU: usize = 1536;
struct Config {
corrupt_pct: u8,
drop_pct: u8,
reorder_pct: u8,
max_size: usize,
max_tx_rate: u64,
max_rx_rate: u64,

View File

@ -281,7 +281,7 @@ impl Dhcpv4Socket {
}
};
let prefix_len = match IpAddress::Ipv4(subnet_mask).to_prefix_len() {
let prefix_len = match IpAddress::Ipv4(subnet_mask).prefix_len() {
Some(prefix_len) => prefix_len,
None => {
net_debug!("DHCP ignoring ACK because subnet_mask is not a valid mask");

View File

@ -187,7 +187,7 @@ from_socket!(Dhcpv4Socket, Dhcpv4);
#[derive(Clone, Debug)]
pub(crate) struct Context {
pub now: Instant,
#[cfg(feature = "medium-ethernet")]
#[cfg(all(feature = "medium-ethernet", feature = "socket-dhcpv4"))]
pub ethernet_address: Option<crate::wire::EthernetAddress>,
pub caps: DeviceCapabilities,
}
@ -215,6 +215,7 @@ impl Context {
#[cfg(not(feature = "medium-ethernet"))]
max_transmission_unit: 1500,
},
#[cfg(all(feature = "medium-ethernet", feature = "socket-dhcpv4"))]
ethernet_address: None,
now: Instant { millis: 0 },
};

View File

@ -732,7 +732,7 @@ impl<'a> TcpSocket<'a> {
// This lets us lower IpRepr later to determine IP header size and calculate MSS,
// but without committing to a specific address right away.
let local_addr = match local_endpoint.addr {
IpAddress::Unspecified => remote_endpoint.addr.to_unspecified(),
IpAddress::Unspecified => remote_endpoint.addr.as_unspecified(),
ip => ip,
};
let local_endpoint = IpEndpoint {

View File

@ -167,7 +167,7 @@ impl Address {
}
/// Return an unspecified address that has the same IP version as `self`.
pub fn to_unspecified(&self) -> Address {
pub fn as_unspecified(&self) -> Address {
match *self {
Address::Unspecified => Address::Unspecified,
#[cfg(feature = "proto-ipv4")]
@ -179,7 +179,7 @@ impl Address {
/// If `self` is a CIDR-compatible subnet mask, return `Some(prefix_len)`,
/// where `prefix_len` is the number of leading zeroes. Return `None` otherwise.
pub fn to_prefix_len(&self) -> Option<u8> {
pub fn prefix_len(&self) -> Option<u8> {
let mut ones = true;
let mut prefix_len = 0;
for byte in self.as_bytes() {
@ -1216,7 +1216,7 @@ pub(crate) mod test {
#[cfg(feature = "proto-ipv4")]
fn to_prefix_len_ipv4() {
fn test_eq<A: Into<Address>>(prefix_len: u8, mask: A) {
assert_eq!(Some(prefix_len), mask.into().to_prefix_len());
assert_eq!(Some(prefix_len), mask.into().prefix_len());
}
test_eq(0, Ipv4Address::new(0, 0, 0, 0));
@ -1258,7 +1258,7 @@ pub(crate) mod test {
fn to_prefix_len_ipv4_error() {
assert_eq!(
None,
IpAddress::from(Ipv4Address::new(255, 255, 255, 1)).to_prefix_len()
IpAddress::from(Ipv4Address::new(255, 255, 255, 1)).prefix_len()
);
}
@ -1266,7 +1266,7 @@ pub(crate) mod test {
#[cfg(feature = "proto-ipv6")]
fn to_prefix_len_ipv6() {
fn test_eq<A: Into<Address>>(prefix_len: u8, mask: A) {
assert_eq!(Some(prefix_len), mask.into().to_prefix_len());
assert_eq!(Some(prefix_len), mask.into().prefix_len());
}
test_eq(0, Ipv6Address::new(0, 0, 0, 0, 0, 0, 0, 0));
@ -1285,7 +1285,7 @@ pub(crate) mod test {
IpAddress::from(Ipv6Address::new(
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0, 1
))
.to_prefix_len()
.prefix_len()
);
}
}