Skip to content

Commit 79dd393

Browse files
committed
Adjust RUNTIME_SHUTTING_DOWN_ERROR comparison
1 parent 20c3427 commit 79dd393

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tokio/src/process/unix/pidfd_reaper.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,41 @@ where
9595
pidfd: PollEvented<Pidfd>,
9696
}
9797

98+
fn display_eq(d: impl std::fmt::Display, s: &str) -> bool {
99+
use std::fmt::Write;
100+
101+
struct FormatEq<'r> {
102+
remainder: &'r str,
103+
unequal: bool,
104+
}
105+
106+
impl<'r> Write for FormatEq<'r> {
107+
fn write_str(&mut self, s: &str) -> std::fmt::Result {
108+
if !self.unequal {
109+
if let Some(new_remainder) = self.remainder.strip_prefix(s) {
110+
self.remainder = new_remainder;
111+
} else {
112+
self.unequal = true;
113+
}
114+
}
115+
Ok(())
116+
}
117+
}
118+
119+
let mut fmt_eq = FormatEq {
120+
remainder: s,
121+
unequal: false,
122+
};
123+
let _ = write!(fmt_eq, "{d}");
124+
fmt_eq.remainder.is_empty() && !fmt_eq.unequal
125+
}
126+
98127
#[allow(deprecated)]
99128
fn is_rt_shutdown_err(err: &io::Error) -> bool {
100129
if let Some(inner) = err.get_ref() {
101-
// Using `Error::description()` is more efficient than `format!("{inner}")`,
102-
// so we use it here even if it is deprecated.
103130
err.kind() == io::ErrorKind::Other
104131
&& inner.source().is_none()
105-
&& inner.description() == RUNTIME_SHUTTING_DOWN_ERROR
132+
&& display_eq(inner, RUNTIME_SHUTTING_DOWN_ERROR)
106133
} else {
107134
false
108135
}

0 commit comments

Comments
 (0)