Browse Source

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.
Tamir Duberstein 1 year ago
parent
commit
963dd13
3 changed files with 21 additions and 18 deletions
  1. 5 3
      aya-log/src/lib.rs
  2. 15 15
      aya/src/maps/perf/perf_buffer.rs
  3. 1 0
      aya/src/programs/probe.rs

+ 5 - 3
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.
 ///

+ 15 - 15
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,

+ 1 - 0
aya/src/programs/probe.rs

@@ -62,6 +62,7 @@ pub(crate) fn lines(bytes: &[u8]) -> impl Iterator<Item = &OsStr> {
 
 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>;