diff --git a/src/criterion.rs b/src/criterion.rs index f7f3dfdb..97ac85af 100644 --- a/src/criterion.rs +++ b/src/criterion.rs @@ -11,6 +11,7 @@ use criterion::profiler::Profiler; use std::fs::File; #[cfg(feature = "protobuf")] use std::io::Write; +use std::marker::PhantomData; use std::os::raw::c_int; use std::path::Path; @@ -20,6 +21,11 @@ pub enum Output<'a> { #[cfg(feature = "protobuf")] Protobuf, + + #[deprecated( + note = "This branch is used to include lifetime parameter. Don't use it directly." + )] + _Phantom(PhantomData<&'a ()>), } pub struct PProfProfiler<'a, 'b> { @@ -38,6 +44,9 @@ impl<'a, 'b> PProfProfiler<'a, 'b> { } } +#[cfg(not(any(feature = "protobuf", feature = "flamegraph")))] +compile_error!("Either feature \"protobuf\" or \"flamegraph\" must be enabled when \"criterion\" feature is enabled."); + impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { fn start_profiling(&mut self, _benchmark_id: &str, _benchmark_dir: &Path) { self.active_profiler = Some(ProfilerGuard::new(self.frequency).unwrap()); @@ -51,6 +60,10 @@ impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { Output::Flamegraph(_) => "flamegraph.svg", #[cfg(feature = "protobuf")] Output::Protobuf => "profile.pb", + // This is `""` but not `unreachable!()`, because `unreachable!()` + // will result in another compile error, so that the user may not + // realize the error thrown by `compile_error!()` at the first time. + _ => "", }; let output_path = benchmark_dir.join(filename); let output_file = File::create(&output_path).unwrap_or_else(|_| { @@ -87,6 +100,8 @@ impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { .write_all(&content) .expect("Error while writing protobuf"); } + + _ => unreachable!(), } } } diff --git a/src/frames.rs b/src/frames.rs index 06f4d0b8..087f2c5e 100644 --- a/src/frames.rs +++ b/src/frames.rs @@ -40,6 +40,7 @@ impl Debug for UnresolvedFrames { } impl UnresolvedFrames { + #[allow(clippy::uninit_assumed_init)] pub fn new(bt: &[Frame], tn: &[u8], thread_id: u64) -> Self { let depth = bt.len(); let mut frames: [Frame; MAX_DEPTH] = diff --git a/src/lib.rs b/src/lib.rs index 3c298afc..32da691a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ pub const MAX_DEPTH: usize = 32; /// Define the MAX supported thread name length. TODO: make this variable mutable. pub const MAX_THREAD_NAME: usize = 16; +#[allow(clippy::uninit_assumed_init)] mod collector; mod error; mod frames; diff --git a/src/profiler.rs b/src/profiler.rs index ae09b6ef..3d547a8b 100644 --- a/src/profiler.rs +++ b/src/profiler.rs @@ -117,6 +117,7 @@ fn write_thread_name(current_thread: libc::pthread_t, name: &mut [libc::c_char]) } #[no_mangle] +#[allow(clippy::uninit_assumed_init)] extern "C" fn perf_signal_handler(_signal: c_int) { if let Some(mut guard) = PROFILER.try_write() { if let Ok(profiler) = guard.as_mut() {