From 0750a6c3caa6d73dd2f7eb75d8843143b6ce91b6 Mon Sep 17 00:00:00 2001 From: Mark Giraud Date: Wed, 15 Nov 2023 20:26:12 +0100 Subject: [PATCH] refactor: Remove unnecessary Debug trait bounds (#1667) * refactor: Remove Debug supertraits Instead of having the Debug trait as supertrait on several traits, the Debug trait is now required in bounds in specific implementations that need this specific trait. This keeps the API cleaner, since users now don't have to propagate the Debug requirement if they don't need to use the Debug trait. * refactor: Reformat code --- libafl/src/executors/command.rs | 10 +++++----- libafl/src/executors/forkserver.rs | 2 +- libafl/src/executors/inprocess.rs | 6 +++--- libafl/src/executors/mod.rs | 4 ++-- libafl/src/executors/shadow.rs | 4 ++-- libafl/src/executors/with_observers.rs | 9 ++++----- libafl/src/feedbacks/concolic.rs | 2 +- libafl/src/feedbacks/map.rs | 16 ++++++++-------- libafl/src/feedbacks/mod.rs | 8 ++++---- libafl/src/feedbacks/new_hash_feedback.rs | 6 +++--- libafl/src/observers/map.rs | 2 +- libafl/src/observers/mod.rs | 4 ++-- libafl/src/stages/tmin.rs | 4 ++-- libafl_bolts/src/serdeany.rs | 5 +++-- libafl_frida/src/executor.rs | 2 +- libafl_qemu/src/executor.rs | 8 ++++---- libafl_qemu/src/helper.rs | 3 +-- libafl_qemu/src/hooks.rs | 2 +- 18 files changed, 48 insertions(+), 49 deletions(-) diff --git a/libafl/src/executors/command.rs b/libafl/src/executors/command.rs index cb6bf9209e..28d83550ad 100644 --- a/libafl/src/executors/command.rs +++ b/libafl/src/executors/command.rs @@ -215,7 +215,7 @@ where impl CommandExecutor where - OT: MatchName + Debug + ObserversTuple, + OT: MatchName + ObserversTuple, S: UsesInput, { /// Creates a new `CommandExecutor`. @@ -315,7 +315,7 @@ where EM: UsesState, S: UsesInput + HasExecutions, S::Input: HasTargetBytes, - T: CommandConfigurator + Debug, + T: CommandConfigurator, OT: Debug + MatchName + ObserversTuple, Z: UsesState, { @@ -565,7 +565,7 @@ impl CommandExecutorBuilder { observers: OT, ) -> Result, Error> where - OT: Debug + MatchName + ObserversTuple, + OT: MatchName + ObserversTuple, S: UsesInput, { let Some(program) = &self.program else { @@ -660,7 +660,7 @@ impl CommandExecutorBuilder { /// ``` #[cfg(all(feature = "std", any(unix, doc)))] -pub trait CommandConfigurator: Sized + Debug { +pub trait CommandConfigurator: Sized { /// Spawns a new process with the given configuration. fn spawn_child(&mut self, input: &I) -> Result where @@ -672,7 +672,7 @@ pub trait CommandConfigurator: Sized + Debug { /// Create an `Executor` from this `CommandConfigurator`. fn into_executor(self, observers: OT) -> CommandExecutor where - OT: Debug + MatchName, + OT: MatchName, { CommandExecutor { observers, diff --git a/libafl/src/executors/forkserver.rs b/libafl/src/executors/forkserver.rs index 4b24b4d895..c7b76d305e 100644 --- a/libafl/src/executors/forkserver.rs +++ b/libafl/src/executors/forkserver.rs @@ -522,7 +522,7 @@ impl TimeoutForkserverExecutor { impl Executor for TimeoutForkserverExecutor where - E: Executor + HasForkserver + HasObservers + Debug, + E: Executor + HasForkserver + HasObservers, E::Input: HasTargetBytes, E::State: HasExecutions, EM: UsesState, diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index c527dad525..5a81e201a1 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -90,7 +90,7 @@ impl Debug for GenericInProcessExecutor where H: FnMut(&S::Input) -> ExitKind + ?Sized, HB: BorrowMut, - OT: ObserversTuple, + OT: ObserversTuple + Debug, S: UsesInput, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { @@ -1599,7 +1599,7 @@ where impl<'a, H, OT, S, SP> Debug for InProcessForkExecutor<'a, H, OT, S, SP> where H: FnMut(&S::Input) -> ExitKind + ?Sized, - OT: ObserversTuple, + OT: ObserversTuple + Debug, S: UsesInput, SP: ShMemProvider, { @@ -1615,7 +1615,7 @@ where impl<'a, H, OT, S, SP> Debug for TimeoutInProcessForkExecutor<'a, H, OT, S, SP> where H: FnMut(&S::Input) -> ExitKind + ?Sized, - OT: ObserversTuple, + OT: ObserversTuple + Debug, S: UsesInput, SP: ShMemProvider, { diff --git a/libafl/src/executors/mod.rs b/libafl/src/executors/mod.rs index 6f48360c34..1214085713 100644 --- a/libafl/src/executors/mod.rs +++ b/libafl/src/executors/mod.rs @@ -118,7 +118,7 @@ pub trait HasObservers: UsesObservers { } /// An executor takes the given inputs, and runs the harness/target. -pub trait Executor: UsesState + Debug +pub trait Executor: UsesState where EM: UsesState, Z: UsesState, @@ -166,7 +166,7 @@ where impl Executor for NopExecutor where EM: UsesState, - S: UsesInput + Debug + HasExecutions, + S: UsesInput + HasExecutions, S::Input: HasTargetBytes, Z: UsesState, { diff --git a/libafl/src/executors/shadow.rs b/libafl/src/executors/shadow.rs index 67ecada499..94a73a9f86 100644 --- a/libafl/src/executors/shadow.rs +++ b/libafl/src/executors/shadow.rs @@ -32,8 +32,8 @@ where impl ShadowExecutor where - E: HasObservers + Debug, - SOT: ObserversTuple + Debug, + E: HasObservers, + SOT: ObserversTuple, { /// Create a new `ShadowExecutor`, wrapping the given `executor`. pub fn new(executor: E, shadow_observers: SOT) -> Self { diff --git a/libafl/src/executors/with_observers.rs b/libafl/src/executors/with_observers.rs index 1ca1785420..9c2e5c6c04 100644 --- a/libafl/src/executors/with_observers.rs +++ b/libafl/src/executors/with_observers.rs @@ -18,8 +18,7 @@ pub struct WithObservers { impl Executor for WithObservers where - E: Executor + Debug, - OT: Debug, + E: Executor, EM: UsesState, Z: UsesState, { @@ -53,8 +52,8 @@ where impl HasObservers for WithObservers where - E: UsesState + Debug, - OT: ObserversTuple + Debug, + E: UsesState, + OT: ObserversTuple, { fn observers(&self) -> &OT { &self.observers @@ -65,7 +64,7 @@ where } } -impl WithObservers { +impl WithObservers { /// Wraps the given [`Executor`] with the given [`ObserversTuple`] to implement [`HasObservers`]. /// /// If the executor already implements [`HasObservers`], then the original implementation will be overshadowed by diff --git a/libafl/src/feedbacks/concolic.rs b/libafl/src/feedbacks/concolic.rs index 946bae29a7..33126fcf8d 100644 --- a/libafl/src/feedbacks/concolic.rs +++ b/libafl/src/feedbacks/concolic.rs @@ -49,7 +49,7 @@ impl Named for ConcolicFeedback { impl Feedback for ConcolicFeedback where - S: UsesInput + Debug + HasClientPerfMonitor, + S: UsesInput + HasClientPerfMonitor, { #[allow(clippy::wrong_self_convention)] fn is_interesting( diff --git a/libafl/src/feedbacks/map.rs b/libafl/src/feedbacks/map.rs index 681b982fe6..95f4b89346 100644 --- a/libafl/src/feedbacks/map.rs +++ b/libafl/src/feedbacks/map.rs @@ -50,7 +50,7 @@ pub type MaxMapPow2Feedback = MapFeedback = MapFeedback; /// A `Reducer` function is used to aggregate values for the novelty search -pub trait Reducer: 'static + Debug +pub trait Reducer: 'static where T: Default + Copy + 'static, { @@ -137,7 +137,7 @@ where } /// A `IsNovel` function is used to discriminate if a reduced value is considered novel. -pub trait IsNovel: 'static + Debug +pub trait IsNovel: 'static where T: Default + Copy + 'static, { @@ -392,10 +392,10 @@ where impl Feedback for MapFeedback where - N: IsNovel + Debug, + N: IsNovel, O: MapObserver + for<'it> AsIter<'it, Item = T>, - R: Reducer + Debug, - S: UsesInput + HasClientPerfMonitor + HasNamedMetadata + Debug, + R: Reducer, + S: UsesInput + HasClientPerfMonitor + HasNamedMetadata, T: Default + Copy + Serialize + for<'de> Deserialize<'de> + PartialEq + Debug + 'static, { fn init_state(&mut self, state: &mut S) -> Result<(), Error> { @@ -496,7 +496,7 @@ impl Feedback for MapFeedback where O: MapObserver + AsSlice, for<'it> O: AsIter<'it, Item = u8>, - S: UsesInput + HasNamedMetadata + HasClientPerfMonitor + Debug, + S: UsesInput + HasNamedMetadata + HasClientPerfMonitor, { #[allow(clippy::wrong_self_convention)] #[allow(clippy::needless_range_loop)] @@ -664,7 +664,7 @@ where O: MapObserver, for<'it> O: AsIter<'it, Item = T>, N: IsNovel, - S: UsesInput + HasNamedMetadata + HasClientPerfMonitor + Debug, + S: UsesInput + HasNamedMetadata + HasClientPerfMonitor, { /// Create new `MapFeedback` #[must_use] @@ -875,7 +875,7 @@ where impl Feedback for ReachabilityFeedback where - S: UsesInput + Debug + HasClientPerfMonitor, + S: UsesInput + HasClientPerfMonitor, O: MapObserver, for<'it> O: AsIter<'it, Item = usize>, { diff --git a/libafl/src/feedbacks/mod.rs b/libafl/src/feedbacks/mod.rs index ef81837bc8..e156d24f4a 100644 --- a/libafl/src/feedbacks/mod.rs +++ b/libafl/src/feedbacks/mod.rs @@ -47,7 +47,7 @@ use crate::{ /// Feedbacks evaluate the observers. /// Basically, they reduce the information provided by an observer to a value, /// indicating the "interestingness" of the last run. -pub trait Feedback: Named + Debug +pub trait Feedback: Named where S: UsesInput + HasClientPerfMonitor, { @@ -186,7 +186,7 @@ where A: Feedback, B: Feedback, FL: FeedbackLogic, - S: UsesInput + HasClientPerfMonitor + Debug, + S: UsesInput + HasClientPerfMonitor, { fn init_state(&mut self, state: &mut S) -> Result<(), Error> { self.first.init_state(state)?; @@ -265,7 +265,7 @@ where } /// Logical combination of two feedbacks -pub trait FeedbackLogic: 'static + Debug +pub trait FeedbackLogic: 'static where A: Feedback, B: Feedback, @@ -619,7 +619,7 @@ where impl Debug for NotFeedback where - A: Feedback, + A: Feedback + Debug, S: UsesInput + HasClientPerfMonitor, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { diff --git a/libafl/src/feedbacks/new_hash_feedback.rs b/libafl/src/feedbacks/new_hash_feedback.rs index f326198e29..1b508ac418 100644 --- a/libafl/src/feedbacks/new_hash_feedback.rs +++ b/libafl/src/feedbacks/new_hash_feedback.rs @@ -87,8 +87,8 @@ pub struct NewHashFeedback { impl Feedback for NewHashFeedback where - O: ObserverWithHashField + Named + Debug, - S: UsesInput + Debug + HasNamedMetadata + HasClientPerfMonitor, + O: ObserverWithHashField + Named, + S: UsesInput + HasNamedMetadata + HasClientPerfMonitor, { fn init_state(&mut self, state: &mut S) -> Result<(), Error> { state.add_named_metadata( @@ -157,7 +157,7 @@ const DEFAULT_CAPACITY: usize = 4096; impl NewHashFeedback where - O: ObserverWithHashField + Named + Debug, + O: ObserverWithHashField + Named, { /// Returns a new [`NewHashFeedback`]. /// Setting an observer name that doesn't exist would eventually trigger a panic. diff --git a/libafl/src/observers/map.rs b/libafl/src/observers/map.rs index c8b363ace4..0c8c8f1aac 100644 --- a/libafl/src/observers/map.rs +++ b/libafl/src/observers/map.rs @@ -83,7 +83,7 @@ fn hash_slice(slice: &[T]) -> u64 { /// A [`MapObserver`] observes the static map, as oftentimes used for AFL-like coverage information /// /// TODO: enforce `iter() -> AssociatedTypeIter` when generic associated types stabilize -pub trait MapObserver: HasLen + Named + Serialize + serde::de::DeserializeOwned + Debug +pub trait MapObserver: HasLen + Named + Serialize + serde::de::DeserializeOwned // where // for<'it> &'it Self: IntoIterator { diff --git a/libafl/src/observers/mod.rs b/libafl/src/observers/mod.rs index 197abd1dea..15b6693a35 100644 --- a/libafl/src/observers/mod.rs +++ b/libafl/src/observers/mod.rs @@ -47,7 +47,7 @@ where /// Observers observe different information about the target. /// They can then be used by various sorts of feedback. -pub trait Observer: Named + Debug +pub trait Observer: Named where S: UsesInput, { @@ -124,7 +124,7 @@ pub trait UsesObservers: UsesState { } /// A haskell-style tuple of observers -pub trait ObserversTuple: MatchName + Debug +pub trait ObserversTuple: MatchName where S: UsesInput, { diff --git a/libafl/src/stages/tmin.rs b/libafl/src/stages/tmin.rs index c532904cae..73db1ad195 100644 --- a/libafl/src/stages/tmin.rs +++ b/libafl/src/stages/tmin.rs @@ -331,8 +331,8 @@ impl HasObserverName for MapEqualityFeedback { impl Feedback for MapEqualityFeedback where - M: MapObserver + Debug, - S: UsesInput + HasClientPerfMonitor + Debug, + M: MapObserver, + S: UsesInput + HasClientPerfMonitor, { fn is_interesting( &mut self, diff --git a/libafl_bolts/src/serdeany.rs b/libafl_bolts/src/serdeany.rs index 82baf49dbb..dc378039c0 100644 --- a/libafl_bolts/src/serdeany.rs +++ b/libafl_bolts/src/serdeany.rs @@ -17,10 +17,11 @@ pub trait SerdeAny: Any + erased_serde::Serialize + Debug { /// Wrap a type for serialization #[derive(Debug)] -pub struct Wrap<'a, T: ?Sized + Debug>(pub &'a T); +pub struct Wrap<'a, T: ?Sized>(pub &'a T); + impl<'a, T> Serialize for Wrap<'a, T> where - T: ?Sized + erased_serde::Serialize + 'a + Debug, + T: ?Sized + erased_serde::Serialize + 'a, { /// Serialize the type fn serialize(&self, serializer: S) -> Result diff --git a/libafl_frida/src/executor.rs b/libafl_frida/src/executor.rs index bd5db64e59..c741685b80 100644 --- a/libafl_frida/src/executor.rs +++ b/libafl_frida/src/executor.rs @@ -49,7 +49,7 @@ where H: FnMut(&S::Input) -> ExitKind, S: UsesInput, S::Input: HasTargetBytes, - OT: ObserversTuple, + OT: ObserversTuple + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("FridaInProcessExecutor") diff --git a/libafl_qemu/src/executor.rs b/libafl_qemu/src/executor.rs index fb949f7ae9..6f67f250c8 100644 --- a/libafl_qemu/src/executor.rs +++ b/libafl_qemu/src/executor.rs @@ -45,8 +45,8 @@ impl<'a, H, OT, QT, S> Debug for QemuExecutor<'a, H, OT, QT, S> where H: FnMut(&S::Input) -> ExitKind, S: UsesInput, - OT: ObserversTuple, - QT: QemuHelperTuple, + OT: ObserversTuple + Debug, + QT: QemuHelperTuple + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("QemuExecutor") @@ -289,8 +289,8 @@ impl<'a, H, OT, QT, S, SP> Debug for QemuForkExecutor<'a, H, OT, QT, S, SP> where H: FnMut(&S::Input) -> ExitKind, S: UsesInput, - OT: ObserversTuple, - QT: QemuHelperTuple, + OT: ObserversTuple + Debug, + QT: QemuHelperTuple + Debug, SP: ShMemProvider, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { diff --git a/libafl_qemu/src/helper.rs b/libafl_qemu/src/helper.rs index 259af872d2..620beb0613 100644 --- a/libafl_qemu/src/helper.rs +++ b/libafl_qemu/src/helper.rs @@ -42,8 +42,7 @@ where } } -pub trait QemuHelperTuple: - MatchFirstType + for<'a> SplitBorrowExtractFirstType<'a> + Debug +pub trait QemuHelperTuple: MatchFirstType + for<'a> SplitBorrowExtractFirstType<'a> where S: UsesInput, { diff --git a/libafl_qemu/src/hooks.rs b/libafl_qemu/src/hooks.rs index 850c15bae7..1d68708ffb 100644 --- a/libafl_qemu/src/hooks.rs +++ b/libafl_qemu/src/hooks.rs @@ -729,7 +729,7 @@ where impl<'a, QT, S> Debug for QemuHooks<'a, QT, S> where S: UsesInput, - QT: QemuHelperTuple, + QT: QemuHelperTuple + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("QemuHooks")