From 3a080d818bf6f65e42c3716644d3dafd291b57c4 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 2 Jan 2023 00:20:05 +0100 Subject: [PATCH] Clippy fixes --- examples/benchmark.rs | 2 +- examples/dns.rs | 4 ++-- examples/multicast.rs | 8 ++++---- examples/ping.rs | 4 ++-- examples/sixlowpan_benchmark.rs | 4 ++-- examples/utils.rs | 4 ++-- src/iface/interface/mod.rs | 2 +- src/wire/icmpv6.rs | 2 +- src/wire/ieee802154.rs | 2 +- src/wire/ip.rs | 7 ++----- src/wire/ipv6.rs | 2 +- src/wire/ipv6option.rs | 2 +- utils/packet2pcap.rs | 6 +++--- 13 files changed, 23 insertions(+), 26 deletions(-) diff --git a/examples/benchmark.rs b/examples/benchmark.rs index e7220d4a..ad3e6dfc 100644 --- a/examples/benchmark.rs +++ b/examples/benchmark.rs @@ -46,7 +46,7 @@ fn client(kind: Client) { // print!("(P:{})", result); processed += result } - Err(err) => panic!("cannot process: {}", err), + Err(err) => panic!("cannot process: {err}"), } } diff --git a/examples/dns.rs b/examples/dns.rs index 3e9cae03..40aa785a 100644 --- a/examples/dns.rs +++ b/examples/dns.rs @@ -89,11 +89,11 @@ fn main() { .get_query_result(query) { Ok(addrs) => { - println!("Query done: {:?}", addrs); + println!("Query done: {addrs:?}"); break; } Err(GetQueryResultError::Pending) => {} // not done yet - Err(e) => panic!("query failed: {:?}", e), + Err(e) => panic!("query failed: {e:?}"), } phy_wait(fd, iface.poll_delay(timestamp, &sockets)).expect("wait error"); diff --git a/examples/multicast.rs b/examples/multicast.rs index ab46e850..11c90c48 100644 --- a/examples/multicast.rs +++ b/examples/multicast.rs @@ -83,13 +83,13 @@ fn main() { // For display purposes only - normally we wouldn't process incoming IGMP packets // in the application layer match socket.recv() { - Err(e) => println!("Recv IGMP error: {:?}", e), + Err(e) => println!("Recv IGMP error: {e:?}"), Ok(buf) => { Ipv4Packet::new_checked(buf) .and_then(|ipv4_packet| IgmpPacket::new_checked(ipv4_packet.payload())) .and_then(|igmp_packet| IgmpRepr::parse(&igmp_packet)) - .map(|igmp_repr| println!("IGMP packet: {:?}", igmp_repr)) - .unwrap_or_else(|e| println!("parse IGMP error: {:?}", e)); + .map(|igmp_repr| println!("IGMP packet: {igmp_repr:?}")) + .unwrap_or_else(|e| println!("parse IGMP error: {e:?}")); } } } @@ -105,7 +105,7 @@ fn main() { .map(|(data, sender)| { println!("mDNS traffic: {} UDP bytes from {}", data.len(), sender) }) - .unwrap_or_else(|e| println!("Recv UDP error: {:?}", e)); + .unwrap_or_else(|e| println!("Recv UDP error: {e:?}")); } phy_wait(fd, iface.poll_delay(timestamp, &sockets)).expect("wait error"); diff --git a/examples/ping.rs b/examples/ping.rs index 271e29d5..76626d65 100644 --- a/examples/ping.rs +++ b/examples/ping.rs @@ -247,7 +247,7 @@ fn main() { if timestamp - *from < timeout { true } else { - println!("From {} icmp_seq={} timeout", remote_addr, seq); + println!("From {remote_addr} icmp_seq={seq} timeout"); false } }); @@ -269,7 +269,7 @@ fn main() { } } - println!("--- {} ping statistics ---", remote_addr); + println!("--- {remote_addr} ping statistics ---"); println!( "{} packets transmitted, {} received, {:.0}% packet loss", seq_no, diff --git a/examples/sixlowpan_benchmark.rs b/examples/sixlowpan_benchmark.rs index 53a4d430..38e5d7a6 100644 --- a/examples/sixlowpan_benchmark.rs +++ b/examples/sixlowpan_benchmark.rs @@ -65,7 +65,7 @@ use std::thread; use std::fs; fn if_nametoindex(ifname: &str) -> u32 { - let contents = fs::read_to_string(format!("/sys/devices/virtual/net/{}/ifindex", ifname)) + let contents = fs::read_to_string(format!("/sys/devices/virtual/net/{ifname}/ifindex")) .expect("couldn't read interface from \"/sys/devices/virtual/net\"") .replace('\n', ""); contents.parse::().unwrap() @@ -111,7 +111,7 @@ fn client(kind: Client) { // print!("(P:{})", result); processed += result } - Err(err) => panic!("cannot process: {}", err), + Err(err) => panic!("cannot process: {err}"), } } diff --git a/examples/utils.rs b/examples/utils.rs index d2b60caf..dbe90761 100644 --- a/examples/utils.rs +++ b/examples/utils.rs @@ -26,7 +26,7 @@ where Builder::new() .format(move |buf, record| { let elapsed = since_startup(); - let timestamp = format!("[{}]", elapsed); + let timestamp = format!("[{elapsed}]"); if record.target().starts_with("smoltcp::") { writeln!( buf, @@ -73,7 +73,7 @@ pub fn create_options() -> (Options, Vec<&'static str>) { pub fn parse_options(options: &Options, free: Vec<&str>) -> Matches { match options.parse(env::args().skip(1)) { Err(err) => { - println!("{}", err); + println!("{err}"); process::exit(1) } Ok(matches) => { diff --git a/src/iface/interface/mod.rs b/src/iface/interface/mod.rs index c6a95149..349fa737 100644 --- a/src/iface/interface/mod.rs +++ b/src/iface/interface/mod.rs @@ -1630,7 +1630,7 @@ impl<'a> InterfaceInner<'a> { #[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))] fn check_hardware_addr(addr: &HardwareAddress) { if !addr.is_unicast() { - panic!("Ethernet address {} is not unicast", addr) + panic!("Ethernet address {addr} is not unicast") } } diff --git a/src/wire/icmpv6.rs b/src/wire/icmpv6.rs index 86dde185..fa5416e5 100644 --- a/src/wire/icmpv6.rs +++ b/src/wire/icmpv6.rs @@ -418,7 +418,7 @@ impl + AsMut<[u8]>> Packet { let data = self.buffer.as_mut(); NetworkEndian::write_u16(&mut data[field::RECORD_RESV], 0); } - ty => panic!("Message type `{}` does not have any reserved fields.", ty), + ty => panic!("Message type `{ty}` does not have any reserved fields."), } } diff --git a/src/wire/ieee802154.rs b/src/wire/ieee802154.rs index 1d3f183b..2c2b6489 100644 --- a/src/wire/ieee802154.rs +++ b/src/wire/ieee802154.rs @@ -872,7 +872,7 @@ mod test { let mut frame = Frame::new_unchecked(&mut buffer[..buffer_len]); repr.emit(&mut frame); - println!("{:2x?}", frame); + println!("{frame:2x?}"); assert_eq!(frame.frame_type(), FrameType::Data); assert!(!frame.security_enabled()); diff --git a/src/wire/ip.rs b/src/wire/ip.rs index fa189431..e3a3478c 100644 --- a/src/wire/ip.rs +++ b/src/wire/ip.rs @@ -591,7 +591,7 @@ impl Repr { hop_limit, }), #[allow(unreachable_patterns)] - _ => panic!("IP version mismatch: src={:?} dst={:?}", src_addr, dst_addr), + _ => panic!("IP version mismatch: src={src_addr:?} dst={dst_addr:?}"), } } @@ -783,10 +783,7 @@ pub mod checksum { } #[allow(unreachable_patterns)] - _ => panic!( - "Unexpected pseudo header addresses: {}, {}", - src_addr, dst_addr - ), + _ => panic!("Unexpected pseudo header addresses: {src_addr}, {dst_addr}"), } } diff --git a/src/wire/ipv6.rs b/src/wire/ipv6.rs index 47baf5a4..8fe8d813 100644 --- a/src/wire/ipv6.rs +++ b/src/wire/ipv6.rs @@ -787,7 +787,7 @@ mod test { #[test] fn test_address_format() { assert_eq!("ff02::1", format!("{}", Address::LINK_LOCAL_ALL_NODES)); - assert_eq!("fe80::1", format!("{}", LINK_LOCAL_ADDR)); + assert_eq!("fe80::1", format!("{LINK_LOCAL_ADDR}")); assert_eq!( "fe80::7f00:0:1", format!( diff --git a/src/wire/ipv6option.rs b/src/wire/ipv6option.rs index f3fb6dfb..963b066b 100644 --- a/src/wire/ipv6option.rs +++ b/src/wire/ipv6option.rs @@ -534,7 +534,7 @@ mod test { }), ) => continue, (6, Err(Error)) => continue, - (i, res) => panic!("Unexpected option `{:?}` at index {}", res, i), + (i, res) => panic!("Unexpected option `{res:?}` at index {i}"), } } } diff --git a/utils/packet2pcap.rs b/utils/packet2pcap.rs index b76780ea..7d06c6f1 100644 --- a/utils/packet2pcap.rs +++ b/utils/packet2pcap.rs @@ -24,7 +24,7 @@ fn convert( } fn print_usage(program: &str, opts: Options) { - let brief = format!("Usage: {} [options] INPUT OUTPUT", program); + let brief = format!("Usage: {program} [options] INPUT OUTPUT"); print!("{}", opts.usage(&brief)); } @@ -44,7 +44,7 @@ fn main() { let matches = match opts.parse(&args[1..]) { Ok(m) => m, Err(e) => { - eprintln!("{}", e); + eprintln!("{e}"); return; } }; @@ -67,7 +67,7 @@ fn main() { ) { Ok(()) => (), Err(e) => { - eprintln!("Cannot convert packet to pcap: {}", e); + eprintln!("Cannot convert packet to pcap: {e}"); exit(1); } }