Fix lints

pull/497/head
Alessandro Decina 2 years ago
parent d33ed21fc4
commit 9f4ef6f67d

@ -799,9 +799,10 @@ impl DeclTag {
} }
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
#[repr(u32)] #[repr(u32)]
pub enum BtfKind { pub enum BtfKind {
#[default]
Unknown = 0, Unknown = 0,
Int = 1, Int = 1,
Ptr = 2, Ptr = 2,
@ -879,12 +880,6 @@ impl Display for BtfKind {
} }
} }
impl Default for BtfKind {
fn default() -> Self {
BtfKind::Unknown
}
}
unsafe fn read<T>(data: &[u8]) -> Result<T, BtfError> { unsafe fn read<T>(data: &[u8]) -> Result<T, BtfError> {
if mem::size_of::<T>() > data.len() { if mem::size_of::<T>() > data.len() {
return Err(BtfError::InvalidTypeInfo); return Err(BtfError::InvalidTypeInfo);

@ -81,9 +81,10 @@ pub struct BtfMapDef {
/// Upon pinning a map, a file representation is created for the map, /// Upon pinning a map, a file representation is created for the map,
/// so that the map can be alive and retrievable across sessions. /// so that the map can be alive and retrievable across sessions.
#[repr(u32)] #[repr(u32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum PinningType { pub enum PinningType {
/// No pinning /// No pinning
#[default]
None = 0, None = 0,
/// Pin by the name /// Pin by the name
ByName = 1, ByName = 1,
@ -112,12 +113,6 @@ impl TryFrom<u32> for PinningType {
} }
} }
impl Default for PinningType {
fn default() -> Self {
PinningType::None
}
}
/// Map definition in legacy BPF map declaration style /// Map definition in legacy BPF map declaration style
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[repr(C)] #[repr(C)]

@ -1463,7 +1463,6 @@ mod tests {
map_flags: 5, map_flags: 5,
id: 0, id: 0,
pinning: PinningType::None, pinning: PinningType::None,
..Default::default()
}; };
assert_eq!( assert_eq!(
@ -1482,7 +1481,6 @@ mod tests {
map_flags: 5, map_flags: 5,
id: 6, id: 6,
pinning: PinningType::ByName, pinning: PinningType::ByName,
..Default::default()
}; };
assert_eq!(parse_map_def("foo", bytes_of(&def)).unwrap(), def); assert_eq!(parse_map_def("foo", bytes_of(&def)).unwrap(), def);
@ -1498,7 +1496,6 @@ mod tests {
map_flags: 5, map_flags: 5,
id: 6, id: 6,
pinning: PinningType::ByName, pinning: PinningType::ByName,
..Default::default()
}; };
let mut buf = [0u8; 128]; let mut buf = [0u8; 128];
unsafe { ptr::write_unaligned(buf.as_mut_ptr() as *mut _, def) }; unsafe { ptr::write_unaligned(buf.as_mut_ptr() as *mut _, def) };
@ -1529,7 +1526,6 @@ mod tests {
map_flags: 5, map_flags: 5,
id: 0, id: 0,
pinning: PinningType::None, pinning: PinningType::None,
..Default::default()
}) })
), ),
"foo" "foo"
@ -1664,7 +1660,7 @@ mod tests {
buf.extend(&map_data); buf.extend(&map_data);
buf.extend(&map_data); buf.extend(&map_data);
// throw in some padding // throw in some padding
buf.extend(&[0, 0, 0, 0]); buf.extend([0, 0, 0, 0]);
buf.extend(&map_data); buf.extend(&map_data);
assert_matches!( assert_matches!(
obj.parse_section(fake_section(BpfSectionKind::Maps, "maps", buf.as_slice(),)), obj.parse_section(fake_section(BpfSectionKind::Maps, "maps", buf.as_slice(),)),
@ -2198,7 +2194,6 @@ mod tests {
map_flags: BPF_F_RDONLY_PROG, map_flags: BPF_F_RDONLY_PROG,
id: 1, id: 1,
pinning: PinningType::None, pinning: PinningType::None,
..Default::default()
}, },
section_index: 1, section_index: 1,
symbol_index: 1, symbol_index: 1,

@ -7,26 +7,19 @@ use crate::{
}; };
/// Defines where to attach a `CgroupSock` program. /// Defines where to attach a `CgroupSock` program.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, Default)]
pub enum CgroupSockAttachType { pub enum CgroupSockAttachType {
/// Called after the IPv4 bind events. /// Called after the IPv4 bind events.
PostBind4, PostBind4,
/// Called after the IPv6 bind events. /// Called after the IPv6 bind events.
PostBind6, PostBind6,
/// Attach to IPv4 connect events. /// Attach to IPv4 connect events.
#[default]
SockCreate, SockCreate,
/// Attach to IPv6 connect events. /// Attach to IPv6 connect events.
SockRelease, SockRelease,
} }
impl Default for CgroupSockAttachType {
// The kernel checks for a 0 attach_type and sets it to sock_create
// We may as well do that here also
fn default() -> Self {
CgroupSockAttachType::SockCreate
}
}
impl From<CgroupSockAttachType> for bpf_attach_type { impl From<CgroupSockAttachType> for bpf_attach_type {
fn from(s: CgroupSockAttachType) -> bpf_attach_type { fn from(s: CgroupSockAttachType) -> bpf_attach_type {
match s { match s {

Loading…
Cancel
Save