From 963dd1321925c95f80c8a2bf656b88a39497ca01 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Thu, 8 Feb 2024 09:17:30 +0000 Subject: [PATCH] Appease rustc dead_code lint Some of these are legit, others are false positives. I've filed https://github.com/rust-lang/rust/issues/120770 for the latter. --- aya-log/src/lib.rs | 8 +++++--- aya/src/maps/perf/perf_buffer.rs | 30 +++++++++++++++--------------- aya/src/programs/probe.rs | 1 + 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/aya-log/src/lib.rs b/aya-log/src/lib.rs index afd80653d..2758ca7a9 100644 --- a/aya-log/src/lib.rs +++ b/aya-log/src/lib.rs @@ -74,9 +74,11 @@ use bytes::BytesMut; use log::{error, Log, Record}; use thiserror::Error; +#[allow(dead_code)] // TODO(https://github.com/rust-lang/rust/issues/120770): Remove when false positive is fixed. #[derive(Copy, Clone)] #[repr(transparent)] struct RecordFieldWrapper(RecordField); +#[allow(dead_code)] // TODO(https://github.com/rust-lang/rust/issues/120770): Remove when false positive is fixed. #[derive(Copy, Clone)] #[repr(transparent)] struct ArgumentWrapper(Argument); @@ -84,9 +86,9 @@ struct ArgumentWrapper(Argument); #[repr(transparent)] struct DisplayHintWrapper(DisplayHint); -unsafe impl aya::Pod for RecordFieldWrapper {} -unsafe impl aya::Pod for ArgumentWrapper {} -unsafe impl aya::Pod for DisplayHintWrapper {} +unsafe impl Pod for RecordFieldWrapper {} +unsafe impl Pod for ArgumentWrapper {} +unsafe impl Pod for DisplayHintWrapper {} /// Log messages generated by `aya_log_ebpf` using the [log] crate. /// diff --git a/aya/src/maps/perf/perf_buffer.rs b/aya/src/maps/perf/perf_buffer.rs index c50bbb863..44a00c8bc 100644 --- a/aya/src/maps/perf/perf_buffer.rs +++ b/aya/src/maps/perf/perf_buffer.rs @@ -282,21 +282,6 @@ impl Drop for PerfBuffer { } } -#[derive(Debug)] -#[repr(C)] -struct Sample { - header: perf_event_header, - size: u32, -} - -#[repr(C)] -#[derive(Debug)] -struct LostSamples { - header: perf_event_header, - id: u64, - count: u64, -} - #[cfg(test)] mod tests { use std::{fmt::Debug, mem}; @@ -309,6 +294,13 @@ mod tests { sys::{override_syscall, Syscall, TEST_MMAP_RET}, }; + #[repr(C)] + #[derive(Debug)] + struct Sample { + header: perf_event_header, + size: u32, + } + const PAGE_SIZE: usize = 4096; union MMappedBuf { mmap_page: perf_event_mmap_page, @@ -375,6 +367,14 @@ mod tests { }; fake_mmap(&mmapped_buf); + #[repr(C)] + #[derive(Debug)] + struct LostSamples { + header: perf_event_header, + id: u64, + count: u64, + } + let evt = LostSamples { header: perf_event_header { type_: PERF_RECORD_LOST as u32, diff --git a/aya/src/programs/probe.rs b/aya/src/programs/probe.rs index f36c8cf98..85be3b3c5 100644 --- a/aya/src/programs/probe.rs +++ b/aya/src/programs/probe.rs @@ -62,6 +62,7 @@ pub(crate) fn lines(bytes: &[u8]) -> impl Iterator { pub(crate) trait OsStringExt { fn starts_with(&self, needle: &OsStr) -> bool; + #[allow(dead_code)] // Would be odd to have the others without this one. fn ends_with(&self, needle: &OsStr) -> bool; fn strip_prefix(&self, prefix: &OsStr) -> Option<&OsStr>; fn strip_suffix(&self, suffix: &OsStr) -> Option<&OsStr>;