Skip to content

Commit

Permalink
src: Remove presumably unused Clippy directives
Browse files Browse the repository at this point in the history
"cargo clippy" seems to pass just fine without most of the Clippy
directives we have in the code. I believe some issues have been fixed
over time, some directives were unnecessarily added when copy-pasting
into a new file, and for the rest I'm not sure; likely, Clippy's
behaviour has changed somewhat over time.

Anyway, let's remove these if they are not necessary.

Signed-off-by: Quentin Monnet <[email protected]>
  • Loading branch information
qmonnet committed Oct 29, 2024
1 parent 8ec1050 commit b4079fe
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 42 deletions.
2 changes: 0 additions & 2 deletions examples/allowed_memory.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
// Copyright 2024 Akenes SA <[email protected]>

#![allow(clippy::unreadable_literal)]

extern crate elf;
use std::{iter::FromIterator, ptr::addr_of};

Expand Down
2 changes: 0 additions & 2 deletions examples/load_elf.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
// Copyright 2016 6WIND S.A. <[email protected]>

#![allow(clippy::unreadable_literal)]

extern crate elf;
use std::path::PathBuf;

Expand Down
2 changes: 1 addition & 1 deletion examples/rbpf_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn _unwind(a: u64, _b: u64, _c: u64, _d: u64, _e: u64) -> u64
// It reads the program from stdin.
fn main() {
let mut args: Vec<String> = std::env::args().collect();
#[allow(unused_mut)] // In no_std the jit variable isn't mutated.
#[cfg_attr(not(feature = "std"), allow(unused_mut))] // In no_std the jit variable isn't mutated.
let mut jit : bool = false;
let mut cranelift : bool = false;
let mut program_text = String::new();
Expand Down
2 changes: 0 additions & 2 deletions src/ebpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ pub const LD_IND_W : u8 = BPF_LD | BPF_IND | BPF_W;
/// BPF opcode: `ldinddw src, dst, imm`.
pub const LD_IND_DW : u8 = BPF_LD | BPF_IND | BPF_DW;

#[allow(unknown_lints)]
#[allow(clippy::eq_op)]
/// BPF opcode: `lddw dst, imm` /// `dst = imm`.
pub const LD_DW_IMM : u8 = BPF_LD | BPF_IMM | BPF_DW;
/// BPF opcode: `ldxb dst, [src + off]` /// `dst = (src + off) as u8`.
Expand Down
12 changes: 0 additions & 12 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ fn check_mem(
)))
}

#[allow(unknown_lints)]
#[allow(cyclomatic_complexity)]
pub fn execute_program(
prog_: Option<&[u8]>,
mem: &[u8],
Expand Down Expand Up @@ -147,25 +145,21 @@ pub fn execute_program(

// BPF_LDX class
ebpf::LD_B_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize);
check_mem_load(x as u64, 1, insn_ptr)?;
x.read_unaligned() as u64
},
ebpf::LD_H_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize) as *const u16;
check_mem_load(x as u64, 2, insn_ptr)?;
x.read_unaligned() as u64
},
ebpf::LD_W_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize) as *const u32;
check_mem_load(x as u64, 4, insn_ptr)?;
x.read_unaligned() as u64
},
ebpf::LD_DW_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize) as *const u64;
check_mem_load(x as u64, 8, insn_ptr)?;
x.read_unaligned()
Expand All @@ -178,19 +172,16 @@ pub fn execute_program(
x.write_unaligned(insn.imm as u8);
},
ebpf::ST_H_IMM => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u16;
check_mem_store(x as u64, 2, insn_ptr)?;
x.write_unaligned(insn.imm as u16);
},
ebpf::ST_W_IMM => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u32;
check_mem_store(x as u64, 4, insn_ptr)?;
x.write_unaligned(insn.imm as u32);
},
ebpf::ST_DW_IMM => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u64;
check_mem_store(x as u64, 8, insn_ptr)?;
x.write_unaligned(insn.imm as u64);
Expand All @@ -203,19 +194,16 @@ pub fn execute_program(
x.write_unaligned(reg[_src] as u8);
},
ebpf::ST_H_REG => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u16;
check_mem_store(x as u64, 2, insn_ptr)?;
x.write_unaligned(reg[_src] as u16);
},
ebpf::ST_W_REG => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u32;
check_mem_store(x as u64, 4, insn_ptr)?;
x.write_unaligned(reg[_src] as u32);
},
ebpf::ST_DW_REG => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u64;
check_mem_store(x as u64, 8, insn_ptr)?;
x.write_unaligned(reg[_src]);
Expand Down
2 changes: 2 additions & 0 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Copyright 2016 6WIND S.A. <[email protected]>
// (Translation to Rust, MetaBuff addition)

#![allow(clippy::single_match)]

use std::alloc;
use std::mem;
use std::collections::HashMap;
Expand Down
13 changes: 0 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
)]
// Test examples from README.md as part as doc tests.
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
// There are unused mut warnings due to unsafe code.
#![allow(unused_mut)]
// Allows old-style clippy
#![allow(renamed_and_removed_lints)]
#![allow(
clippy::redundant_field_names,
clippy::single_match,
clippy::cast_lossless,
clippy::doc_markdown,
clippy::match_same_arms,
clippy::unreadable_literal
)]
// Configures the crate to be `no_std` when `std` feature is disabled.
#![cfg_attr(not(feature = "std"), no_std)]

Expand Down
2 changes: 0 additions & 2 deletions tests/assembler.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
// Copyright 2017 Rich Lane <[email protected]>

#![allow(clippy::unreadable_literal)]

extern crate rbpf;
mod common;

Expand Down
1 change: 0 additions & 1 deletion tests/cranelift.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#![allow(clippy::unreadable_literal)]
#![cfg(feature = "cranelift")]

extern crate rbpf;
Expand Down
4 changes: 0 additions & 4 deletions tests/misc.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
// Copyright 2016 6WIND S.A. <[email protected]>

// There are unused mut warnings due to unsafe code.
#![allow(unused_mut)]
#![allow(clippy::unreadable_literal)]

// This crate would be needed to load bytecode from a BPF-compiled object file. Since the crate
// is not used anywhere else in the library, it is deactivated: we do not want to load and compile
// it just for the tests. If you want to use it, do not forget to add the following
Expand Down
1 change: 0 additions & 1 deletion tests/ubpf_jit_x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

// These are unit tests for the eBPF JIT compiler.

#![allow(clippy::unreadable_literal)]
#![cfg(all(not(windows), feature = "std"))]

extern crate rbpf;
Expand Down
2 changes: 0 additions & 2 deletions tests/ubpf_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

// These are unit tests for the eBPF interpreter.

#![allow(clippy::unreadable_literal)]

extern crate rbpf;
mod common;

Expand Down

0 comments on commit b4079fe

Please sign in to comment.