Skip to content

Commit

Permalink
Various Clippy fixes.
Browse files Browse the repository at this point in the history
These are the last remaining Clippy fixes (well, at least until we
introduce some more or Clippy becomes more stringent!).
  • Loading branch information
ltratt committed Mar 29, 2023
1 parent 5bc2998 commit f35941d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
6 changes: 2 additions & 4 deletions hwtracer/src/decode/ykpt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ impl<'t> YkPTBlockIterator<'t> {

/// Fetch the next packet and update iterator state.
fn packet(&mut self) -> Result<Packet, HWTracerError> {
let ret = if let Some(pkt_or_err) = self.parser.next() {
if let Some(pkt_or_err) = self.parser.next() {
let mut pkt = pkt_or_err?;

if pkt.kind() == PacketKind::OVF {
Expand Down Expand Up @@ -778,9 +778,7 @@ impl<'t> YkPTBlockIterator<'t> {
Ok(pkt)
} else {
Err(HWTracerError::NoMorePackets)
};

ret
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion hwtracer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::new_without_default)]
#![allow(clippy::upper_case_acronyms)]
#![feature(once_cell)]
#![feature(ptr_sub_ptr)]

Expand Down
4 changes: 3 additions & 1 deletion ykcapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#[cfg(feature = "yk_testing")]
mod testing;

use libc;
use std::arch::asm;
use std::convert::{TryFrom, TryInto};
use std::ffi::{c_char, c_void, CString};
Expand All @@ -25,6 +24,7 @@ use ykrt::{HotThreshold, Location, MT};
use yksmp::{Location as SMLocation, StackMapParser};

#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn yk_mt_new(err_msg: *mut *const c_char) -> *mut MT {
match MT::new() {
Ok(mt) => Box::into_raw(Box::new(mt)),
Expand All @@ -45,6 +45,7 @@ pub extern "C" fn yk_mt_new(err_msg: *mut *const c_char) -> *mut MT {
}

#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn yk_mt_drop(mt: *mut MT) {
unsafe { Box::from_raw(mt) };
}
Expand All @@ -58,6 +59,7 @@ pub extern "C" fn yk_mt_control_point(_mt: *mut MT, _loc: *mut Location) {
// The "real" control point, that is called once the interpreter has been patched by ykllvm.
// Returns the address of a reconstructed stack or null if there wasn#t a guard failure.
#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub extern "C" fn __ykrt_control_point(
mt: *mut MT,
loc: *mut Location,
Expand Down
2 changes: 2 additions & 0 deletions ykfr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(once_cell)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::missing_safety_doc)]

use llvm_sys::{core::*, target::LLVMABISizeOfType};
use object::{Object, ObjectSection};
Expand Down
1 change: 1 addition & 0 deletions ykrt/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ impl LocationInner {
/// If this `State` is not counting, return its `HotLocation`. It is undefined behaviour to
/// call this function if this `State` is in the counting phase and/or if this `State` is not
/// locked.
#[allow(clippy::mut_from_ref)]
pub(super) unsafe fn hot_location(&self) -> &mut HotLocation {
debug_assert!(!self.is_counting());
debug_assert!(self.is_locked());
Expand Down
2 changes: 1 addition & 1 deletion ykrt/src/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl MT {
max_worker_threads: AtomicUsize::new(cmp::max(1, num_cpus::get() - 1)),
active_worker_threads: AtomicUsize::new(0),
trace_decoder_kind: TraceDecoderKind::default_for_platform()
.ok_or_else(|| "Tracing is not supported on this platform")?,
.ok_or("Tracing is not supported on this platform")?,
tracing_kind: TracingKind::default(),
})
}
Expand Down
4 changes: 4 additions & 0 deletions yksmp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub struct LiveVar {
}

impl LiveVar {
pub fn is_empty(&self) -> bool {
self.locs.is_empty()
}

pub fn len(&self) -> usize {
self.locs.len()
}
Expand Down
7 changes: 6 additions & 1 deletion yktrace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(once_cell)]
#![feature(naked_functions)]
#![allow(clippy::new_without_default)]
#![allow(clippy::missing_safety_doc)]

mod errors;
use hwtracer::decode::TraceDecoderKind;
Expand Down Expand Up @@ -141,6 +142,10 @@ impl IRTrace {
Self { blocks, faddrs }
}

pub fn is_empty(&self) -> bool {
self.blocks.is_empty()
}

pub fn len(&self) -> usize {
self.blocks.len()
}
Expand Down Expand Up @@ -229,7 +234,7 @@ impl IRTrace {
di_tmpname_c,
)
};
if ret == ptr::null() {
if ret.is_null() {
Err("Could not compile trace.".into())
} else {
Ok((ret, di_tmp))
Expand Down

0 comments on commit f35941d

Please sign in to comment.