Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Fix some clippy lints #238

Merged
merged 7 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ethtool/examples/dump_coalesce.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT

use ethtool;
use futures::stream::TryStreamExt;
use tokio;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -24,7 +22,7 @@ async fn get_coalesce(iface_name: Option<&str>) {
while let Some(msg) = coalesce_handle.try_next().await.unwrap() {
msgs.push(msg);
}
assert!(msgs.len() > 0);
assert!(!msgs.is_empty());
for msg in msgs {
println!("{:?}", msg);
}
Expand Down
4 changes: 1 addition & 3 deletions ethtool/examples/dump_features.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT

use ethtool;
use futures::stream::TryStreamExt;
use tokio;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -24,7 +22,7 @@ async fn get_feature(iface_name: Option<&str>) {
while let Some(msg) = feature_handle.try_next().await.unwrap() {
msgs.push(msg);
}
assert!(msgs.len() > 0);
assert!(!msgs.is_empty());
for msg in msgs {
println!("{:?}", msg);
}
Expand Down
4 changes: 1 addition & 3 deletions ethtool/examples/dump_link_mode.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT

use ethtool;
use futures::stream::TryStreamExt;
use tokio;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -24,7 +22,7 @@ async fn get_link_mode(iface_name: Option<&str>) {
while let Some(msg) = link_mode_handle.try_next().await.unwrap() {
msgs.push(msg);
}
assert!(msgs.len() > 0);
assert!(!msgs.is_empty());
for msg in msgs {
println!("{:?}", msg);
}
Expand Down
5 changes: 1 addition & 4 deletions ethtool/examples/dump_pause.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// SPDX-License-Identifier: MIT

use env_logger;
use ethtool;
use futures::stream::TryStreamExt;
use tokio;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -26,6 +23,6 @@ async fn get_pause(iface_name: Option<&str>) {
while let Some(msg) = pause_handle.try_next().await.unwrap() {
msgs.push(msg);
}
assert!(msgs.len() > 0);
assert!(!msgs.is_empty());
println!("{:?}", msgs);
}
4 changes: 1 addition & 3 deletions ethtool/examples/dump_rings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT

use ethtool;
use futures::stream::TryStreamExt;
use tokio;

// Once we find a way to load netsimdev kernel module in CI, we can convert this
// to a test
Expand All @@ -24,7 +22,7 @@ async fn get_ring(iface_name: Option<&str>) {
while let Some(msg) = ring_handle.try_next().await.unwrap() {
msgs.push(msg);
}
assert!(msgs.len() > 0);
assert!(!msgs.is_empty());
for msg in msgs {
println!("{:?}", msg);
}
Expand Down
2 changes: 1 addition & 1 deletion ethtool/tests/dump_link_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn dump_link_modes() {
while let Some(msg) = link_modes_handle.try_next().await.unwrap() {
msgs.push(msg);
}
assert!(msgs.len() >= 1);
assert!(!msgs.is_empty());
let ethtool_msg = &msgs[0].payload;
println!("ethtool_msg {:?}", &ethtool_msg);

Expand Down
2 changes: 1 addition & 1 deletion netlink-packet-core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ mod tests {
packet.set_message_type(RTM_GETLINK);
packet.set_sequence_number(1526271540);
packet.set_port_number(0);
packet.set_flags(From::from(NLM_F_ROOT | NLM_F_REQUEST | NLM_F_MATCH));
packet.set_flags((NLM_F_ROOT | NLM_F_REQUEST | NLM_F_MATCH));
packet
.payload_mut()
.copy_from_slice(&IP_LINK_SHOW_PKT[16..]);
Expand Down
2 changes: 1 addition & 1 deletion netlink-packet-route/benches/link_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn b1(c: &mut Criterion) {

c.bench_function("parse LinkMessage nlas", |b| {
b.iter(|| {
Vec::<Nla>::parse_with_param(&LinkMessageBuffer::new(&&LINKMSG1[..]), 0 as u8).unwrap();
Vec::<Nla>::parse_with_param(&LinkMessageBuffer::new(&&LINKMSG1[..]), 0_u8).unwrap();
})
});

Expand Down
2 changes: 1 addition & 1 deletion netlink-packet-route/benches/rtnetlink_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn bench(c: &mut Criterion) {
b.iter(|| {
for (i, buf) in packets.iter().enumerate() {
NetlinkMessage::<RtnlMessage>::deserialize(&buf[16..])
.expect(&format!("message {} failed", i));
.unwrap_or_else(|_| panic!("message {} failed", i));
}
})
});
Expand Down
2 changes: 1 addition & 1 deletion netlink-packet-route/src/rtnl/link/nlas/af_spec_inet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl nlas::Nla for AfSpecInet {
| Ieee802154(ref bytes)
| Caif(ref bytes)
| Alg(ref bytes)
=> (&mut buffer[..bytes.len()]).copy_from_slice(bytes.as_slice()),
=> buffer[..bytes.len()].copy_from_slice(bytes.as_slice()),
Inet6(ref nlas) => nlas.as_slice().emit(buffer),
Inet(ref nlas) => nlas.as_slice().emit(buffer),
Other(ref nla) => nla.emit_value(buffer),
Expand Down
2 changes: 1 addition & 1 deletion netlink-packet-route/src/rtnl/link/nlas/inet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Nla for Inet {
fn emit_value(&self, buffer: &mut [u8]) {
use self::Inet::*;
match *self {
Unspec(ref bytes) => (&mut buffer[..bytes.len()]).copy_from_slice(bytes.as_slice()),
Unspec(ref bytes) => buffer[..bytes.len()].copy_from_slice(bytes.as_slice()),
DevConf(ref dev_conf) => buffer[..dev_conf.len()].copy_from_slice(dev_conf.as_slice()),
Other(ref nla) => nla.emit_value(buffer),
}
Expand Down
2 changes: 1 addition & 1 deletion netlink-packet-sock-diag/examples/dump_ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
},
payload: SockDiagMessage::InetRequest(InetRequest {
family: AF_INET,
protocol: IPPROTO_TCP.into(),
protocol: IPPROTO_TCP,
extensions: ExtensionFlags::empty(),
states: StateFlags::all(),
socket_id: SocketId::new_v4(),
Expand Down
4 changes: 2 additions & 2 deletions netlink-packet-sock-diag/src/inet/socket_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Emitable for SocketId {

let mut address_buf: [u8; 16] = [0; 16];
match self.source_address {
IpAddr::V4(ip) => (&mut address_buf[0..4]).copy_from_slice(&ip.octets()[..]),
IpAddr::V4(ip) => address_buf[0..4].copy_from_slice(&ip.octets()[..]),
IpAddr::V6(ip) => address_buf.copy_from_slice(&ip.octets()[..]),
}

Expand All @@ -124,7 +124,7 @@ impl Emitable for SocketId {

address_buf = [0; 16];
match self.destination_address {
IpAddr::V4(ip) => (&mut address_buf[0..4]).copy_from_slice(&ip.octets()[..]),
IpAddr::V4(ip) => address_buf[0..4].copy_from_slice(&ip.octets()[..]),
IpAddr::V6(ip) => address_buf.copy_from_slice(&ip.octets()[..]),
}

Expand Down
16 changes: 8 additions & 8 deletions netlink-packet-wireguard/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ pub fn parse_ip(payload: &[u8]) -> Result<IpAddr, DecodeError> {
pub fn emit_ip(addr: &IpAddr, buf: &mut [u8]) {
match addr {
IpAddr::V4(ip) => {
(&mut buf[..IPV4_LEN]).copy_from_slice(ip.octets().as_slice());
buf[..IPV4_LEN].copy_from_slice(ip.octets().as_slice());
}
IpAddr::V6(ip) => {
(&mut buf[..IPV6_LEN]).copy_from_slice(ip.octets().as_slice());
buf[..IPV6_LEN].copy_from_slice(ip.octets().as_slice());
}
}
}
Expand All @@ -112,9 +112,9 @@ pub fn emit_ip(addr: &IpAddr, buf: &mut [u8]) {
fn emit_socket_addr_v4(addr: &SocketAddrV4, buf: &mut [u8]) {
NativeEndian::write_u16(&mut buf[..2], AF_INET);
BigEndian::write_u16(&mut buf[2..4], addr.port());
(&mut buf[4..8]).copy_from_slice(addr.ip().octets().as_slice());
buf[4..8].copy_from_slice(addr.ip().octets().as_slice());
// padding
(&mut buf[8..16]).copy_from_slice([0; 8].as_slice());
buf[8..16].copy_from_slice([0; 8].as_slice());
}

/// Emit an IPv6 socket address.
Expand All @@ -137,7 +137,7 @@ fn emit_socket_addr_v6(addr: &SocketAddrV6, buf: &mut [u8]) {
NativeEndian::write_u16(&mut buf[..2], AF_INET6);
BigEndian::write_u16(&mut buf[2..4], addr.port());
NativeEndian::write_u32(&mut buf[4..8], addr.flowinfo());
(&mut buf[8..24]).copy_from_slice(addr.ip().octets().as_slice());
buf[8..24].copy_from_slice(addr.ip().octets().as_slice());
NativeEndian::write_u32(&mut buf[24..28], addr.scope_id());
}

Expand Down Expand Up @@ -206,13 +206,13 @@ mod test {

#[test]
fn test_parse_socket_addr_in_1() {
let ipaddr = parse_socket_addr(&SOCKADDR_IN_BYTES_1).unwrap();
let ipaddr = parse_socket_addr(SOCKADDR_IN_BYTES_1).unwrap();
assert_eq!(ipaddr, SocketAddrV4::new(Ipv4Addr::LOCALHOST, 7290).into());
}

#[test]
fn test_parse_socket_addr_in_2() {
let ipaddr = parse_socket_addr(&SOCKADDR_IN_BYTES_2).unwrap();
let ipaddr = parse_socket_addr(SOCKADDR_IN_BYTES_2).unwrap();
assert_eq!(
ipaddr,
SocketAddrV4::new(Ipv4Addr::new(192, 168, 1, 1), 51820).into()
Expand All @@ -221,7 +221,7 @@ mod test {

#[test]
fn test_parse_socket_addr_in6_1() {
let ipaddr = parse_socket_addr(&SOCKADDR_IN6_BYTES_1).unwrap();
let ipaddr = parse_socket_addr(SOCKADDR_IN6_BYTES_1).unwrap();
assert_eq!(
ipaddr,
SocketAddrV6::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ fn main() -> Result<(), String> {
TokioSocket::new(NETLINK_AUDIT).unwrap();
};
rt.handle().block_on(future);
return Ok(());
Ok(())
}
2 changes: 1 addition & 1 deletion rtnetlink/examples/get_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn get_link_by_index(handle: Handle, index: u32) -> Result<(), Error> {

async fn get_link_by_name(handle: Handle, name: String) -> Result<(), Error> {
let mut links = handle.link().get().match_name(name.clone()).execute();
if let Some(_) = links.try_next().await? {
if (links.try_next().await?).is_some() {
println!("found link {}", name);
// We should only have one link with that name
assert!(links.try_next().await?.is_none());
Expand Down
2 changes: 1 addition & 1 deletion rtnetlink/examples/get_links_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn get_link_by_index(handle: Handle, index: u32) -> Result<(), Error> {

async fn get_link_by_name(handle: Handle, name: String) -> Result<(), Error> {
let mut links = handle.link().get().match_name(name.clone()).execute();
if let Some(_) = links.try_next().await? {
if (links.try_next().await?).is_some() {
println!("found link {}", name);
// We should only have one link with that name
assert!(links.try_next().await?.is_none());
Expand Down
4 changes: 2 additions & 2 deletions rtnetlink/examples/get_links_thread_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn get_link_by_index(handle: Handle, index: u32) -> Result<(), Error> {

async fn get_link_by_name(handle: Handle, name: String) -> Result<(), Error> {
let mut links = handle.link().get().match_name(name.clone()).execute();
if let Some(_) = links.try_next().await? {
if (links.try_next().await?).is_some() {
println!("found link {}", name);
// We should only have one link with that name
assert!(links.try_next().await?.is_none());
Expand Down Expand Up @@ -124,5 +124,5 @@ fn main() -> Result<(), String> {
let future = do_it(&rt);
println!("blocking in main");
rt.handle().block_on(future).unwrap();
return Ok(());
Ok(())
}
8 changes: 3 additions & 5 deletions rtnetlink/examples/property_altname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ async fn main() -> Result<(), ()> {

match action.as_str() {
"add" => {
if let Err(e) = add_property_alt_ifnames(link_name, &alt_ifnames, handle.clone()).await
{
if let Err(e) = add_property_alt_ifnames(link_name, alt_ifnames, handle.clone()).await {
eprintln!("{}", e);
}
}

"del" => {
if let Err(e) = del_property_alt_ifnames(link_name, &alt_ifnames, handle.clone()).await
{
if let Err(e) = del_property_alt_ifnames(link_name, alt_ifnames, handle.clone()).await {
eprintln!("{}", e);
}
}
Expand Down Expand Up @@ -112,7 +110,7 @@ async fn get_link(link_name: &str, handle: Handle) -> Result<LinkMessage, Error>
match links.try_next().await? {
Some(msg) => Ok(msg),
_ => {
eprintln!("Interface {} not found", link_name.to_string());
eprintln!("Interface {} not found", link_name);
Err(Error::RequestFailed)
}
}
Expand Down
2 changes: 1 addition & 1 deletion rtnetlink/src/link/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn _create_wg() -> Result<LinkHandle, Error> {
async fn _get_wg(handle: &mut LinkHandle) -> Result<LinkMessage, Error> {
let mut links = handle.get().match_name(IFACE_NAME.to_owned()).execute();
let msg = links.try_next().await?;
msg.ok_or_else(|| Error::RequestFailed)
msg.ok_or(Error::RequestFailed)
}

async fn _del_wg(handle: &mut LinkHandle, index: u32) -> Result<(), Error> {
Expand Down
30 changes: 18 additions & 12 deletions rtnetlink/src/traffic_control/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,33 @@ fn _remove_test_tclass_from_dummy() {
"1:1",
])
.status()
.expect(&format!(
"failed to remove tclass from dummy interface {}",
TEST_DUMMY_NIC
));
.unwrap_or_else(|_| {
panic!(
"failed to remove tclass from dummy interface {}",
TEST_DUMMY_NIC
)
});
Command::new("tc")
.args(&["qdisc", "del", "dev", TEST_DUMMY_NIC, "root"])
.status()
.expect(&format!(
"failed to remove qdisc from dummy interface {}",
TEST_DUMMY_NIC
));
.unwrap_or_else(|_| {
panic!(
"failed to remove qdisc from dummy interface {}",
TEST_DUMMY_NIC
)
});
}

fn _remove_test_filter_from_dummy() {
Command::new("tc")
.args(&["filter", "del", "dev", TEST_DUMMY_NIC])
.status()
.expect(&format!(
"failed to remove filter from dummy interface {}",
TEST_DUMMY_NIC
));
.unwrap_or_else(|_| {
panic!(
"failed to remove filter from dummy interface {}",
TEST_DUMMY_NIC
)
});
}

async fn _get_filters(ifindex: i32) -> Vec<TcMessage> {
Expand Down