Clippy fixes

This commit is contained in:
Dario Nieuwenhuis 2023-01-02 00:20:05 +01:00
parent 38094d9c69
commit 3a080d818b
13 changed files with 23 additions and 26 deletions

View File

@ -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}"),
}
}

View File

@ -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");

View File

@ -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");

View File

@ -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,

View File

@ -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::<u32>().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}"),
}
}

View File

@ -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) => {

View File

@ -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")
}
}

View File

@ -418,7 +418,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T> {
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."),
}
}

View File

@ -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());

View File

@ -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}"),
}
}

View File

@ -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!(

View File

@ -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}"),
}
}
}

View File

@ -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);
}
}