libbpf / libbpf-rs

Minimal and opinionated eBPF tooling for the Rust ecosystem
Other
741 stars 129 forks source link

New clippy warnings with 0.24.2 #921

Closed jfernandez closed 3 weeks ago

jfernandez commented 3 weeks ago

I'm getting these clippy warnings after I updated bpftop to libbpf-rs from 0.23.3 -> 0.24.2

The change: https://github.com/Netflix/bpftop/pull/84/files CI: https://github.com/Netflix/bpftop/actions/runs/10518621156/job/29144723066?pr=84

error: this loop never actually loops
  --> /home/runner/work/bpftop/bpftop/src/bpf/pid_iter.skel.rs:43:13
   |
43 | /             for map in object.maps_mut() {
44 | |                 let name = map.name().to_str().ok_or_else(|| {
45 | |                     libbpf_rs::Error::from(std::io::Error::new(
46 | |                         std::io::ErrorKind::InvalidData,
...  |
52 | |                 }
53 | |             }
   | |_____________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
   = note: `#[deny(clippy::never_loop)]` on by default
help: if you need the first element of the iterator, try writing
   |
43 |             if let Some(map) = object.maps_mut().next() {
   |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

warning: this match could be replaced by its body itself
  --> /home/runner/work/bpftop/bpftop/src/bpf/pid_iter.skel.rs:50:17
   |
50 | /                 match name {
51 | |                     _ => panic!("encountered unexpected map: `{name}`"),
52 | |                 }
   | |_________________^ help: consider using the match body instead: `panic!("encountered unexpected map: `{name}`")`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
   = note: `#[warn(clippy::match_single_binding)]` on by default

error: this loop never actually loops
  --> /home/runner/work/bpftop/bpftop/src/bpf/pid_iter.skel.rs:74:13
   |
74 | /             for map in object.maps_mut() {
75 | |                 let name = map.name().to_str().ok_or_else(|| {
76 | |                     libbpf_rs::Error::from(std::io::Error::new(
77 | |                         std::io::ErrorKind::InvalidData,
...  |
83 | |                 }
84 | |             }
   | |_____________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
help: if you need the first element of the iterator, try writing
   |
74 |             if let Some(map) = object.maps_mut().next() {
   |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

warning: this match could be replaced by its body itself
  --> /home/runner/work/bpftop/bpftop/src/bpf/pid_iter.skel.rs:81:17
   |
81 | /                 match name {
82 | |                     _ => panic!("encountered unexpected map: `{name}`"),
83 | |                 }
   | |_________________^ help: consider using the match body instead: `panic!("encountered unexpected map: `{name}`")`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
d-e-s-o commented 3 weeks ago

I tried building bpftop with https://github.com/libbpf/libbpf-rs/pull/922 and no longer saw any warnings. Will cut a new release later today.

d-e-s-o commented 3 weeks ago

Should be fixed in https://crates.io/crates/libbpf-cargo/0.24.3

jfernandez commented 2 weeks ago

@d-e-s-o thank you!