From ac2343d9842e1a12ec986a95a73148544ee91a1a Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 8 Jan 2022 13:58:26 +0100 Subject: [PATCH] net: add `UnwindSafe` impl to `PollEvented` (#4384) --- tokio/src/io/poll_evented.rs | 5 +++++ tokio/tests/net_types_unwind.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tokio/tests/net_types_unwind.rs diff --git a/tokio/src/io/poll_evented.rs b/tokio/src/io/poll_evented.rs index 44e68a2a9..ce4c1426a 100644 --- a/tokio/src/io/poll_evented.rs +++ b/tokio/src/io/poll_evented.rs @@ -4,6 +4,7 @@ use mio::event::Source; use std::fmt; use std::io; use std::ops::Deref; +use std::panic::{RefUnwindSafe, UnwindSafe}; cfg_io_driver! { /// Associates an I/O resource that implements the [`std::io::Read`] and/or @@ -185,6 +186,10 @@ feature! { } } +impl UnwindSafe for PollEvented {} + +impl RefUnwindSafe for PollEvented {} + impl Deref for PollEvented { type Target = E; diff --git a/tokio/tests/net_types_unwind.rs b/tokio/tests/net_types_unwind.rs new file mode 100644 index 000000000..4eb4a87fd --- /dev/null +++ b/tokio/tests/net_types_unwind.rs @@ -0,0 +1,32 @@ +#![warn(rust_2018_idioms)] +#![cfg(feature = "full")] + +use std::panic::{RefUnwindSafe, UnwindSafe}; + +#[test] +fn net_types_are_unwind_safe() { + is_unwind_safe::(); + is_unwind_safe::(); + is_unwind_safe::(); + is_unwind_safe::(); +} + +#[test] +#[cfg(unix)] +fn unix_net_types_are_unwind_safe() { + is_unwind_safe::(); + is_unwind_safe::(); + is_unwind_safe::(); +} + +#[test] +#[cfg(windows)] +fn windows_net_types_are_unwind_safe() { + use tokio::net::windows::named_pipe::NamedPipeClient; + use tokio::net::windows::named_pipe::NamedPipeServer; + + is_unwind_safe::(); + is_unwind_safe::(); +} + +fn is_unwind_safe() {}