Skip to content

Commit c08aa58

Browse files
committed
Further review comments
- Fix IoSafe docs - Remove impls of IoSafe for Rc and Arc Signed-off-by: John Nunley <[email protected]>
1 parent a95d00c commit c08aa58

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/lib.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,8 @@ impl<T> Drop for Async<T> {
11591159
/// traits take `&mut`, there is no guarantee that the implementor of those traits won't move the
11601160
/// source out while the method is being run.
11611161
///
1162-
/// This trait is an antidote to this predicament. By implementing this trait, it is guaranteed
1163-
/// that using any I/O traits won't desroy the source. This way, [`Async`] can implement the
1162+
/// This trait is an antidote to this predicament. By implementing this trait, the user pledges
1163+
/// that using any I/O traits won't destroy the source. This way, [`Async`] can implement the
11641164
/// `async` version of these I/O traits, like [`AsyncRead`], [`AsyncWrite`] and [`AsyncSeek`].
11651165
///
11661166
/// # Safety
@@ -1182,10 +1182,32 @@ impl<T> Drop for Async<T> {
11821182
/// [`AsyncWrite`]: https://docs.rs/futures-io/latest/futures_io/trait.AsyncWrite.html
11831183
pub unsafe trait IoSafe {}
11841184

1185-
// Reference types can't be mutated.
1185+
/// Reference types can't be mutated.
1186+
///
1187+
/// The worst thing that can happen is that external state is used to change what kind of pointer
1188+
/// `as_fd()` returns. For instance:
1189+
///
1190+
/// ```no_compile
1191+
/// struct Bar {
1192+
/// flag: Cell<bool>,
1193+
/// a: TcpStream,
1194+
/// b: TcpStream
1195+
/// }
1196+
///
1197+
/// impl AsFd for Bar {
1198+
/// fn as_fd(&self) -> BorrowedFd<'_> {
1199+
/// if self.flag.replace(!self.flag.get()) {
1200+
/// &self.a
1201+
/// } else {
1202+
/// &self.b
1203+
/// }
1204+
/// }
1205+
/// }
1206+
/// ```
1207+
///
1208+
/// We solve this problem by only calling `as_fd()` once to get the original source. Implementations
1209+
/// like this are considered buggy (but not unsound) and are thus not really supported by `async-io`.
11861210
unsafe impl<T: ?Sized> IoSafe for &T {}
1187-
unsafe impl<T: ?Sized> IoSafe for std::rc::Rc<T> {}
1188-
unsafe impl<T: ?Sized> IoSafe for Arc<T> {}
11891211

11901212
// Can be implemented on top of libstd types.
11911213
unsafe impl IoSafe for std::fs::File {}

0 commit comments

Comments
 (0)