Skip to content

Commit

Permalink
Appease rustc dead_code lint
Browse files Browse the repository at this point in the history
Some of these are legit, others are false positives. I've filed
rust-lang/rust#120770 for the latter.
  • Loading branch information
tamird authored and vadorovsky committed Feb 8, 2024
1 parent c31cce4 commit 963dd13
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
8 changes: 5 additions & 3 deletions aya-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,21 @@ 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);
#[derive(Copy, Clone)]
#[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.
///
Expand Down
30 changes: 15 additions & 15 deletions aya/src/maps/perf/perf_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions aya/src/programs/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down

0 comments on commit 963dd13

Please sign in to comment.