Kaynağa Gözat

clippy: Fix Clippy report

Signed-off-by: Quentin Monnet <qmo@qmon.net>
Quentin Monnet 2 ay önce
ebeveyn
işleme
f190fc0530
7 değiştirilmiş dosya ile 8 ekleme ve 10 silme
  1. 1 1
      examples/load_elf.rs
  2. 1 1
      examples/to_json.rs
  3. 1 2
      examples/uptime.rs
  4. 1 1
      src/disassembler.rs
  5. 1 2
      src/ebpf.rs
  6. 1 1
      src/verifier.rs
  7. 2 2
      tests/ubpf_vm.rs

+ 1 - 1
examples/load_elf.rs

@@ -52,7 +52,7 @@ fn main() {
     let path = PathBuf::from(filename);
     let file = match elf::File::open_path(path) {
         Ok(f) => f,
-        Err(e) => panic!("Error: {:?}", e),
+        Err(e) => panic!("Error: {e:?}"),
     };
 
     let text_scn = match file.get_section(".classifier") {

+ 1 - 1
examples/to_json.rs

@@ -60,7 +60,7 @@ fn main() {
     let path = PathBuf::from(filename);
     let file = match elf::File::open_path(path) {
         Ok(f) => f,
-        Err(e) => panic!("Error: {:?}", e),
+        Err(e) => panic!("Error: {e:?}"),
     };
 
     let text_scn = match file.get_section(".classifier") {

+ 1 - 2
examples/uptime.rs

@@ -77,6 +77,5 @@ fn print_time(time: u64) {
     let seconds = (time / 10u64.pow(9)) % 60;
     let nanosec =  time % 10u64.pow(9);
 
-    println!("Uptime: {:#x} ns == {} days {:02}:{:02}:{:02}, {} ns",
-             time, days, hours, minutes, seconds, nanosec);
+    println!("Uptime: {time:#x} ns == {days} days {hours:02}:{minutes:02}:{seconds:02}, {nanosec} ns");
 }

+ 1 - 1
src/disassembler.rs

@@ -313,7 +313,7 @@ pub fn to_insn_vec(prog: &[u8]) -> Vec<HLInsn> {
                 match insn.src {
                     0 => { name = "call"; desc = format!("{name} {:#x}", insn.imm); },
                     1 => { name = "callx"; desc = format!("{name} {:#x}", insn.imm); },
-                    _ => { panic!("[Disassembler] Error: unsupported call insn (insn #{:?})", insn_ptr); }
+                    _ => { panic!("[Disassembler] Error: unsupported call insn (insn #{insn_ptr:?})"); }
                 }
              },
             ebpf::TAIL_CALL  => { name = "tail_call"; desc = name.to_string(); },

+ 1 - 2
src/ebpf.rs

@@ -618,8 +618,7 @@ pub fn get_insn(prog: &[u8], idx: usize) -> Insn {
 pub fn to_insn_vec(prog: &[u8]) -> Vec<Insn> {
     if prog.len() % INSN_SIZE != 0 {
         panic!(
-            "Error: eBPF program length must be a multiple of {:?} octets",
-            INSN_SIZE
+            "Error: eBPF program length must be a multiple of {INSN_SIZE:?} octets"
         );
     }
 

+ 1 - 1
src/verifier.rs

@@ -260,7 +260,7 @@ pub fn check(prog: &[u8]) -> Result<(), Error> {
                             reject(format!("call out of code to #{dst_insn_ptr:?} (insn #{insn_ptr:?})"))?;
                         }
                     }
-                    _ => { reject(format!("unsupported call type #{:?} (insn #{insn_ptr:?})", src))?; }
+                    _ => { reject(format!("unsupported call type #{src:?} (insn #{insn_ptr:?})"))?; }
                 }
             },
             ebpf::TAIL_CALL  => { unimplemented!() },

+ 2 - 2
tests/ubpf_vm.rs

@@ -838,7 +838,7 @@ fn test_vm_jmp_unsigned_extend() {
     //    exit
     // we build it manually to bypass the verifier in `assemble(...)`
     #[rustfmt::skip]
-    let insns = vec![
+    let insns = [
         Insn { opc: LD_W_REG,  dst: 2, src: 1, off: 0, imm: 0 }, 
         Insn { opc: BE,        dst: 2, src: 0, off: 0, imm: 32 }, 
         Insn { opc: JEQ_IMM,   dst: 2, src: 0, off: 2, imm: 0x80000000u32 as i32 }, 
@@ -847,7 +847,7 @@ fn test_vm_jmp_unsigned_extend() {
         Insn { opc: MOV32_IMM, dst: 0, src: 0, off: 0, imm: 1 }, 
         Insn { opc: EXIT,      dst: 0, src: 0, off: 0, imm: 0 }
     ];
-    let prog = insns.iter().map(|x| x.to_array()).flatten().collect::<Vec<u8>>();
+    let prog = insns.iter().flat_map(|x| x.to_array()).collect::<Vec<u8>>();
     let vm = rbpf::EbpfVmRaw::new(Some(&prog)).unwrap();
     let mut data = vec![
         0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00