diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index 35651450..19432555 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -21,11 +21,6 @@ cfg_unstable_default! { } extension_trait! { - use core::pin::Pin; - use core::ops::{Deref, DerefMut}; - - use crate::task::{Context, Poll}; - #[doc = r#" A future represents an asynchronous computation. @@ -393,40 +388,4 @@ extension_trait! { TimeoutFuture::new(self, dur) } } - - impl Future for Box { - type Output = F::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Future for &mut F { - type Output = F::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl

Future for Pin

- where - P: DerefMut + Unpin, -

::Target: Future, - { - type Output = <

::Target as Future>::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Future for std::panic::AssertUnwindSafe { - type Output = F::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - unreachable!("this impl only appears in the rendered docs") - } - } } diff --git a/src/io/buf_read/mod.rs b/src/io/buf_read/mod.rs index 3ee6e30b..90bf339d 100644 --- a/src/io/buf_read/mod.rs +++ b/src/io/buf_read/mod.rs @@ -16,8 +16,6 @@ use crate::io; use crate::task::{Context, Poll}; extension_trait! { - use std::ops::{Deref, DerefMut}; - #[doc = r#" Allows reading from a buffered byte stream. @@ -283,62 +281,6 @@ extension_trait! { } } } - - impl BufRead for Box { - fn poll_fill_buf( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn consume(self: Pin<&mut Self>, amt: usize) { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl BufRead for &mut T { - fn poll_fill_buf( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn consume(self: Pin<&mut Self>, amt: usize) { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl

BufRead for Pin

- where - P: DerefMut + Unpin, -

::Target: BufRead, - { - fn poll_fill_buf( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn consume(self: Pin<&mut Self>, amt: usize) { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl BufRead for &[u8] { - fn poll_fill_buf( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> { - unreachable!() - } - - fn consume(self: Pin<&mut Self>, amt: usize) { - unreachable!("this impl only appears in the rendered docs") - } - } } pub fn read_until_internal( diff --git a/src/io/read/mod.rs b/src/io/read/mod.rs index c8f4e28b..8c6d3a3e 100644 --- a/src/io/read/mod.rs +++ b/src/io/read/mod.rs @@ -22,12 +22,6 @@ pub use chain::Chain; pub use take::Take; extension_trait! { - use std::pin::Pin; - use std::ops::{Deref, DerefMut}; - - use crate::io; - use crate::task::{Context, Poll}; - #[doc = r#" Allows reading from a byte stream. @@ -422,50 +416,6 @@ extension_trait! { } } - - impl Read for Box { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Read for &mut T { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl

Read for Pin

- where - P: DerefMut + Unpin, -

::Target: Read, - { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Read for &[u8] { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } } /// Initializes a buffer if necessary. diff --git a/src/io/seek/mod.rs b/src/io/seek/mod.rs index 3b5036c8..748a1ed9 100644 --- a/src/io/seek/mod.rs +++ b/src/io/seek/mod.rs @@ -5,12 +5,6 @@ use seek::SeekFuture; use crate::io::SeekFrom; extension_trait! { - use std::ops::{Deref, DerefMut}; - use std::pin::Pin; - - use crate::io; - use crate::task::{Context, Poll}; - #[doc = r#" Allows seeking through a byte stream. @@ -83,38 +77,4 @@ extension_trait! { SeekFuture { seeker: self, pos } } } - - impl Seek for Box { - fn poll_seek( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - pos: SeekFrom, - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Seek for &mut T { - fn poll_seek( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - pos: SeekFrom, - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl

Seek for Pin

- where - P: DerefMut + Unpin, -

::Target: Seek, - { - fn poll_seek( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - pos: SeekFrom, - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } } diff --git a/src/io/write/mod.rs b/src/io/write/mod.rs index 3dee9feb..b0ed8eec 100644 --- a/src/io/write/mod.rs +++ b/src/io/write/mod.rs @@ -13,11 +13,6 @@ use write_vectored::WriteVectoredFuture; use crate::io::{self, IoSlice}; extension_trait! { - use std::pin::Pin; - use std::ops::{Deref, DerefMut}; - - use crate::task::{Context, Poll}; - #[doc = r#" Allows writing to a byte stream. @@ -245,80 +240,4 @@ extension_trait! { WriteFmtFuture { writer: self, res: Some(res), buffer: None, amt: 0 } } } - - impl Write for Box { - fn poll_write( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &[u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Write for &mut T { - fn poll_write( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &[u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl

Write for Pin

- where - P: DerefMut + Unpin, -

::Target: Write, - { - fn poll_write( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &[u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Write for Vec { - fn poll_write( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &[u8], - ) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - - fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } } diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index af7407a2..90c5cb7a 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -144,10 +144,6 @@ cfg_unstable! { } extension_trait! { - use std::ops::{Deref, DerefMut}; - - use crate::task::{Context, Poll}; - #[doc = r#" An asynchronous stream of values. @@ -2389,40 +2385,4 @@ extension_trait! { Product::product(self) } } - - impl Stream for Box { - type Item = S::Item; - - fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Stream for &mut S { - type Item = S::Item; - - fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl

Stream for Pin

- where - P: DerefMut + Unpin, -

::Target: Stream, - { - type Item = <

::Target as Stream>::Item; - - fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } - - impl Stream for std::panic::AssertUnwindSafe { - type Item = S::Item; - - fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - unreachable!("this impl only appears in the rendered docs") - } - } } diff --git a/src/utils.rs b/src/utils.rs index 77111143..8b8ee23f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -259,26 +259,8 @@ macro_rules! extension_trait { pub trait $ext:ident: $base:path { $($body_ext:tt)* } - - // Shim trait impls that only appear in docs. - $($imp:item)* ) => { - // A fake `impl Future` type that doesn't borrow. - #[allow(dead_code)] - mod owned { - #[doc(hidden)] - pub struct ImplFuture(core::marker::PhantomData); - } - - // Render a fake trait combining the bodies of the base trait and the extension trait. - #[cfg(feature = "docs")] - #[doc = $doc] - pub trait $name { - extension_trait!(@doc [$($body_base)* $($body_ext)*] -> []); - } - - // When not rendering docs, re-export the base trait from the futures crate. - #[cfg(not(feature = "docs"))] + // Re-export the base trait from the futures crate. pub use $base as $name; // The extension trait that adds methods to any type implementing the base trait. @@ -289,36 +271,18 @@ macro_rules! extension_trait { // Blanket implementation of the extension trait for any type implementing the base trait. impl $ext for T {} - - // Shim trait impls that only appear in docs. - $(#[cfg(feature = "docs")] $imp)* }; // Parse the return type in an extension method. - (@doc [-> impl Future [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => { - extension_trait!(@doc [$($tail)*] -> [$($accum)* -> owned::ImplFuture<$out>]); - }; (@ext [-> impl Future [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => { extension_trait!(@ext [$($tail)*] -> [$($accum)* -> $f]); }; // Parse a token. - (@doc [$token:tt $($tail:tt)*] -> [$($accum:tt)*]) => { - extension_trait!(@doc [$($tail)*] -> [$($accum)* $token]); - }; (@ext [$token:tt $($tail:tt)*] -> [$($accum:tt)*]) => { extension_trait!(@ext [$($tail)*] -> [$($accum)* $token]); }; // Handle the end of the token list. - (@doc [] -> [$($accum:tt)*]) => { $($accum)* }; (@ext [] -> [$($accum:tt)*]) => { $($accum)* }; - - // Parse imports at the beginning of the macro. - ($import:item $($tail:tt)*) => { - #[cfg(feature = "docs")] - $import - - extension_trait!($($tail)*); - }; }