Skip to content

Commit

Permalink
Fix "irrefutable while let pattern" warning
Browse files Browse the repository at this point in the history
```
warning: irrefutable `while let` pattern
  --> examples/arp_packet.rs:61:11
   |
61 |     while let buf = receiver.next().unwrap() {
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this pattern will always match, so the loop will never exit
   = help: consider instead using a `loop { ... }` with a `let` inside it
   = note: `#[warn(irrefutable_let_patterns)]` on by default
```
  • Loading branch information
vvv committed Jul 2, 2023
1 parent 6bdcf95 commit 6f31c07
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/arp_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ fn get_mac_through_arp(interface: NetworkInterface, target_ip: Ipv4Addr) -> MacA

println!("Sent ARP request");

while let buf = receiver.next().unwrap() {
loop {
let buf = receiver.next().unwrap();
let arp = ArpPacket::new(&buf[MutableEthernetPacket::minimum_packet_size()..]).unwrap();
if arp.get_sender_proto_addr() == target_ip
&& arp.get_target_hw_addr() == interface.mac.unwrap()
Expand All @@ -67,7 +68,7 @@ fn get_mac_through_arp(interface: NetworkInterface, target_ip: Ipv4Addr) -> MacA
return arp.get_sender_hw_addr();
}
}
panic!("Never reach here")
// unreachable
}

fn main() {
Expand Down

0 comments on commit 6f31c07

Please sign in to comment.