Repository: tokio-rs/tokio
File: tokio/src/runtime/runtime.rs (Rust)

Code before:
            #[cfg(feature = "rt-multi-thread")]
            Scheduler::MultiThread(multi_thread) => {
                // The threaded scheduler drops its tasks on its worker threads, which is
                // already in the runtime's context.
                multi_thread.shutdown(&self.handle.inner);
            }
        }
    }
}

impl std::panic::UnwindSafe for Runtime {}

impl std::panic::RefUnwindSafe for Runtime {}

fn display_eq(d: impl std::fmt::Display, s: &str) -> bool {
    use std::fmt::Write;

    struct FormatEq<'r> {
        remainder: &'r str,
        unequal: bool,
    }

    impl<'r> Write for FormatEq<'r> {
        fn write_str(&mut self, s: &str) -> std::fmt::Result {
            if !self.unequal {
                if let Some(new_remainder) = self.remainder.strip_prefix(s) {
                    self.remainder = new_remainder;
                } else {
                    self.unequal = true;
                }
            }
            Ok(())
        }
    }

    let mut fmt_eq = FormatEq {
        remainder: s,
        unequal: false,
    };
    let _ = write!(fmt_eq, "{d}");
    fmt_eq.remainder.is_empty() && !fmt_eq.unequal
}

/// Checks whether the given error was emitted by tokio when shutting down its runtime.
pub fn is_rt_shutdown_err(err: &io::Error) -> bool {
    if let Some(inner) = err.get_ref() {
        err.kind() == io::ErrorKind::Other
            && inner.source().is_none()
            && display_eq(inner, RUNTIME_SHUTTING_DOWN_ERROR)
    } else {
        false

Review comment (suggestion):
I know this is an old code but what is the idea of using `self.remainder.strip_prefix(s)` here ?
Wouldn't it be simpler to do: 
```diff

     impl<'r> Write for FormatEq<'r> {
         fn write_str(&mut self, s: &str) -> std::fmt::Result {
-            if !self.unequal {
-                if let Some(new_remainder) = self.remainder.strip_prefix(s) {
-                    self.remainder = new_remainder;
-                } else {
-                    self.unequal = true;
-                }
-            }
+            self.unequal = self.remainder != s;
             Ok(())
         }
     }
```
In addition `remainder` could be renamed to `expected` and `unequal` to `equal` to avoid the double negation below.
I could apply this simplification in a follow-up if I don't miss something!

Code after:
            #[cfg(feature = "rt-multi-thread")]
            Scheduler::MultiThread(multi_thread) => {
                // The threaded scheduler drops its tasks on its worker threads, which is
                // already in the runtime's context.
                multi_thread.shutdown(&self.handle.inner);
            }
        }
    }
}

impl std::panic::UnwindSafe for Runtime {}

impl std::panic::RefUnwindSafe for Runtime {}

fn display_eq(d: impl std::fmt::Display, s: &str) -> bool {
    use std::fmt::Write;

    struct FormatEq<'r> {
        remainder: &'r str,
        unequal: bool,
    }

    impl<'r> Write for FormatEq<'r> {
        fn write_str(&mut self, s: &str) -> std::fmt::Result {
            if !self.unequal {
                if let Some(new_remainder) = self.remainder.strip_prefix(s) {
                    self.remainder = new_remainder;
                } else {
                    self.unequal = true;
                }
            }
            Ok(())
        }
    }

    let mut fmt_eq = FormatEq {
        remainder: s,
        unequal: false,
    };
    let _ = write!(fmt_eq, "{d}");
    fmt_eq.remainder.is_empty() && !fmt_eq.unequal
}

/// Checks whether the given error was emitted by Tokio when shutting down its runtime.
///
/// # Examples
///
/// ```
/// # #[cfg(not(target_family = "wasm"))]
/// # {
/// use tokio::runtime::Runtime;