task: remove unnecessary trait bounds on the Debug implementation (#7720)

Remove the trait bounds of the `Debug` impl for `JoinQueue`
and `AbortOnDropHandle`.

Signed-off-by: ADD-SP <[email protected]>
This commit is contained in:
Qi
2025-11-04 11:15:29 +01:00
committed by GitHub
parent 12319f26d0
commit 1ece2f1fa7
2 changed files with 46 additions and 2 deletions
+23 -1
View File
@@ -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<T>(JoinHandle<T>);
impl<T> Drop for AbortOnDropHandle<T> {
@@ -58,6 +57,14 @@ impl<T> AbortOnDropHandle<T> {
}
}
impl<T> std::fmt::Debug for AbortOnDropHandle<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AbortOnDropHandle")
.field("id", &self.0.id())
.finish()
}
}
impl<T> Future for AbortOnDropHandle<T> {
type Output = Result<T, JoinError>;
@@ -71,3 +78,18 @@ impl<T> AsRef<JoinHandle<T>> for AbortOnDropHandle<T> {
&self.0
}
}
#[cfg(test)]
mod tests {
use super::*;
/// A simple type that does not implement [`std::fmt::Debug`].
struct NotDebug;
fn is_debug<T: std::fmt::Debug>() {}
#[test]
fn assert_debug() {
is_debug::<AbortOnDropHandle<NotDebug>>();
}
}
+23 -1
View File
@@ -21,7 +21,6 @@ use tokio::{
///
/// When the [`JoinQueue`] is dropped, all tasks in the [`JoinQueue`] are
/// immediately aborted.
#[derive(Debug)]
pub struct JoinQueue<T>(VecDeque<AbortOnDropHandle<T>>);
impl<T> JoinQueue<T> {
@@ -379,6 +378,14 @@ impl<T> JoinQueue<T> {
}
}
impl<T> std::fmt::Debug for JoinQueue<T> {
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<T> Default for JoinQueue<T> {
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<T: std::fmt::Debug>() {}
#[test]
fn assert_debug() {
is_debug::<JoinQueue<NotDebug>>();
}
}