From e6d87e1603fee90989cd27cc61881eda0dc367e8 Mon Sep 17 00:00:00 2001 From: Qi Date: Mon, 3 Nov 2025 19:38:41 +0800 Subject: [PATCH] task: remove unnecessary trait bounds on the `Debug` implementation Remove the trait bounds of the `Debug` impl for `JoinQueue` and `AbortOnDropHandle`. Signed-off-by: ADD-SP --- tokio-util/src/task/abort_on_drop.rs | 24 +++++++++++++++++++++++- tokio-util/src/task/join_queue.rs | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tokio-util/src/task/abort_on_drop.rs b/tokio-util/src/task/abort_on_drop.rs index e0353ac85c8..191731cb977 100644 --- a/tokio-util/src/task/abort_on_drop.rs +++ b/tokio-util/src/task/abort_on_drop.rs @@ -15,7 +15,6 @@ use std::{ /// /// [aborts]: tokio::task::JoinHandle::abort #[must_use = "Dropping the handle aborts the task immediately"] -#[derive(Debug)] pub struct AbortOnDropHandle(JoinHandle); impl Drop for AbortOnDropHandle { @@ -58,6 +57,14 @@ impl AbortOnDropHandle { } } +impl std::fmt::Debug for AbortOnDropHandle { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("AbortOnDropHandle") + .field("id", &self.0.id()) + .finish() + } +} + impl Future for AbortOnDropHandle { type Output = Result; @@ -71,3 +78,18 @@ impl AsRef> for AbortOnDropHandle { &self.0 } } + +#[cfg(test)] +mod tests { + use super::*; + + /// A simple type that does not implement [`std::fmt::Debug`]. + struct NotDebug; + + fn is_debug() {} + + #[test] + fn assert_debug() { + is_debug::>(); + } +} diff --git a/tokio-util/src/task/join_queue.rs b/tokio-util/src/task/join_queue.rs index 00f42981d84..e327b93c7c9 100644 --- a/tokio-util/src/task/join_queue.rs +++ b/tokio-util/src/task/join_queue.rs @@ -21,7 +21,6 @@ use tokio::{ /// /// When the [`JoinQueue`] is dropped, all tasks in the [`JoinQueue`] are /// immediately aborted. -#[derive(Debug)] pub struct JoinQueue(VecDeque>); impl JoinQueue { @@ -379,6 +378,14 @@ impl JoinQueue { } } +impl std::fmt::Debug for JoinQueue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_list() + .entries(self.0.iter().map(|jh| JoinHandle::id(jh.as_ref()))) + .finish() + } +} + impl Default for JoinQueue { fn default() -> Self { Self::new() @@ -401,3 +408,18 @@ where set } } + +#[cfg(test)] +mod tests { + use super::*; + + /// A simple type that does not implement [`std::fmt::Debug`]. + struct NotDebug; + + fn is_debug() {} + + #[test] + fn assert_debug() { + is_debug::>(); + } +}