From 6b3667d1a49adc8a666ed27d4331e085f0f766e3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 11 Mar 2022 12:10:13 +1100 Subject: [PATCH] Remove unnecessary types in `extension_trait`. The remaining type requires the square brackets (for now) because a `ty` cannot immediately precede a `$(tt)*`. --- src/future/future/mod.rs | 15 +++++----- src/io/buf_read/mod.rs | 4 +-- src/io/read/mod.rs | 10 +++---- src/io/seek/mod.rs | 2 +- src/io/write/mod.rs | 10 +++---- src/stream/stream/mod.rs | 64 ++++++++++++++++++++-------------------- src/utils.rs | 2 +- 7 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/future/future/mod.rs b/src/future/future/mod.rs index a913f4fc..46780f8c 100644 --- a/src/future/future/mod.rs +++ b/src/future/future/mod.rs @@ -45,7 +45,7 @@ extension_trait! { /// ``` #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn delay(self, dur: Duration) -> impl Future [DelayFuture] + fn delay(self, dur: Duration) -> [DelayFuture] where Self: Sized, { @@ -70,8 +70,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn flatten( self, - ) -> impl Future::Output> - [FlattenFuture::Future>] + ) -> [FlattenFuture::Future>] where Self: Sized, ::Output: IntoFuture, @@ -113,7 +112,7 @@ extension_trait! { fn race( self, other: F, - ) -> impl Future::Output> [Race] + ) -> [Race] where Self: std::future::Future + Sized, F: std::future::Future::Output>, @@ -159,7 +158,7 @@ extension_trait! { fn try_race( self, other: F - ) -> impl Future::Output> [TryRace] + ) -> [TryRace] where Self: std::future::Future> + Sized, F: std::future::Future::Output>, @@ -196,7 +195,7 @@ extension_trait! { fn join( self, other: F - ) -> impl Future::Output, ::Output)> [Join] + ) -> [Join] where Self: std::future::Future + Sized, F: std::future::Future, @@ -243,7 +242,7 @@ extension_trait! { fn try_join( self, other: F - ) -> impl Future> [TryJoin] + ) -> [TryJoin] where Self: std::future::Future> + Sized, F: std::future::Future>, @@ -279,7 +278,7 @@ extension_trait! { "#] #[cfg(any(all(feature = "default", feature = "unstable"), feature = "docs"))] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn timeout(self, dur: Duration) -> impl Future [TimeoutFuture] + fn timeout(self, dur: Duration) -> [TimeoutFuture] where Self: Sized { TimeoutFuture::new(self, dur) diff --git a/src/io/buf_read/mod.rs b/src/io/buf_read/mod.rs index d42cbd8a..2b1ee86b 100644 --- a/src/io/buf_read/mod.rs +++ b/src/io/buf_read/mod.rs @@ -78,7 +78,7 @@ extension_trait! { &'a mut self, byte: u8, buf: &'a mut Vec, - ) -> impl Future [ReadUntilFuture<'a, Self>] + ) -> [ReadUntilFuture<'a, Self>] where Self: Unpin, { @@ -131,7 +131,7 @@ extension_trait! { fn read_line<'a>( &'a mut self, buf: &'a mut String, - ) -> impl Future> [ReadLineFuture<'a, Self>] + ) -> [ReadLineFuture<'a, Self>] where Self: Unpin, { diff --git a/src/io/read/mod.rs b/src/io/read/mod.rs index 12c7960e..601bb7f1 100644 --- a/src/io/read/mod.rs +++ b/src/io/read/mod.rs @@ -64,7 +64,7 @@ extension_trait! { fn read<'a>( &'a mut self, buf: &'a mut [u8], - ) -> impl Future> [ReadFuture<'a, Self>] + ) -> [ReadFuture<'a, Self>] where Self: Unpin { @@ -86,7 +86,7 @@ extension_trait! { fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>], - ) -> impl Future> [ReadVectoredFuture<'a, Self>] + ) -> [ReadVectoredFuture<'a, Self>] where Self: Unpin, { @@ -123,7 +123,7 @@ extension_trait! { fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec, - ) -> impl Future> [ReadToEndFuture<'a, Self>] + ) -> [ReadToEndFuture<'a, Self>] where Self: Unpin, { @@ -162,7 +162,7 @@ extension_trait! { fn read_to_string<'a>( &'a mut self, buf: &'a mut String, - ) -> impl Future> [ReadToStringFuture<'a, Self>] + ) -> [ReadToStringFuture<'a, Self>] where Self: Unpin, { @@ -217,7 +217,7 @@ extension_trait! { fn read_exact<'a>( &'a mut self, buf: &'a mut [u8], - ) -> impl Future> [ReadExactFuture<'a, Self>] + ) -> [ReadExactFuture<'a, Self>] where Self: Unpin, { diff --git a/src/io/seek/mod.rs b/src/io/seek/mod.rs index c5ca6c61..29723223 100644 --- a/src/io/seek/mod.rs +++ b/src/io/seek/mod.rs @@ -40,7 +40,7 @@ extension_trait! { fn seek( &mut self, pos: SeekFrom, - ) -> impl Future> [SeekFuture<'_, Self>] + ) -> [SeekFuture<'_, Self>] where Self: Unpin, { diff --git a/src/io/write/mod.rs b/src/io/write/mod.rs index d000ad7c..c8befae3 100644 --- a/src/io/write/mod.rs +++ b/src/io/write/mod.rs @@ -49,7 +49,7 @@ extension_trait! { fn write<'a>( &'a mut self, buf: &'a [u8], - ) -> impl Future> [WriteFuture<'a, Self>] + ) -> [WriteFuture<'a, Self>] where Self: Unpin, { @@ -75,7 +75,7 @@ extension_trait! { # Ok(()) }) } ``` "#] - fn flush(&mut self) -> impl Future> [FlushFuture<'_, Self>] + fn flush(&mut self) -> [FlushFuture<'_, Self>] where Self: Unpin, { @@ -97,7 +97,7 @@ extension_trait! { fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], - ) -> impl Future> [WriteVectoredFuture<'a, Self>] + ) -> [WriteVectoredFuture<'a, Self>] where Self: Unpin, { @@ -133,7 +133,7 @@ extension_trait! { fn write_all<'a>( &'a mut self, buf: &'a [u8], - ) -> impl Future> [WriteAllFuture<'a, Self>] + ) -> [WriteAllFuture<'a, Self>] where Self: Unpin, { @@ -170,7 +170,7 @@ extension_trait! { fn write_fmt<'a>( &'a mut self, fmt: std::fmt::Arguments<'_>, - ) -> impl Future> [WriteFmtFuture<'a, Self>] + ) -> [WriteFmtFuture<'a, Self>] where Self: Unpin, { diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index a316893d..d71dc609 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -177,7 +177,7 @@ extension_trait! { # }) } ``` "#] - fn next(&mut self) -> impl Future> [NextFuture<'_, Self>] + fn next(&mut self) -> [NextFuture<'_, Self>] where Self: Unpin, { @@ -629,7 +629,7 @@ extension_trait! { "#] fn last( self, - ) -> impl Future> [LastFuture] + ) -> [LastFuture] where Self: Sized, { @@ -839,7 +839,7 @@ extension_trait! { fn min_by_key( self, key_by: F, - ) -> impl Future> [MinByKeyFuture] + ) -> [MinByKeyFuture] where Self: Sized, B: Ord, @@ -875,7 +875,7 @@ extension_trait! { fn max_by_key( self, key_by: F, - ) -> impl Future> [MaxByKeyFuture] + ) -> [MaxByKeyFuture] where Self: Sized, B: Ord, @@ -914,7 +914,7 @@ extension_trait! { fn min_by( self, compare: F, - ) -> impl Future> [MinByFuture] + ) -> [MinByFuture] where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering, @@ -947,7 +947,7 @@ extension_trait! { "#] fn max( self, - ) -> impl Future> [MaxFuture] + ) -> [MaxFuture] where Self: Sized, Self::Item: Ord, @@ -980,7 +980,7 @@ extension_trait! { "#] fn min( self, - ) -> impl Future> [MinFuture] + ) -> [MinFuture] where Self: Sized, Self::Item: Ord, @@ -1018,7 +1018,7 @@ extension_trait! { fn max_by( self, compare: F, - ) -> impl Future> [MaxByFuture] + ) -> [MaxByFuture] where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering, @@ -1082,7 +1082,7 @@ extension_trait! { fn nth( &mut self, n: usize, - ) -> impl Future> [NthFuture<'_, Self>] + ) -> [NthFuture<'_, Self>] where Self: Unpin + Sized, { @@ -1138,7 +1138,7 @@ extension_trait! { fn all( &mut self, f: F, - ) -> impl Future [AllFuture<'_, Self, F, Self::Item>] + ) -> [AllFuture<'_, Self, F, Self::Item>] where Self: Unpin + Sized, F: FnMut(Self::Item) -> bool, @@ -1187,7 +1187,7 @@ extension_trait! { fn find

( &mut self, p: P, - ) -> impl Future> [FindFuture<'_, Self, P>] + ) -> [FindFuture<'_, Self, P>] where Self: Unpin + Sized, P: FnMut(&Self::Item) -> bool, @@ -1215,7 +1215,7 @@ extension_trait! { fn find_map( &mut self, f: F, - ) -> impl Future> [FindMapFuture<'_, Self, F>] + ) -> [FindMapFuture<'_, Self, F>] where Self: Unpin + Sized, F: FnMut(Self::Item) -> Option, @@ -1249,7 +1249,7 @@ extension_trait! { self, init: B, f: F, - ) -> impl Future [FoldFuture] + ) -> [FoldFuture] where Self: Sized, F: FnMut(B, Self::Item) -> B, @@ -1286,7 +1286,7 @@ extension_trait! { fn partition( self, f: F, - ) -> impl Future [PartitionFuture] + ) -> [PartitionFuture] where Self: Sized, F: FnMut(&Self::Item) -> bool, @@ -1322,7 +1322,7 @@ extension_trait! { fn for_each( self, f: F, - ) -> impl Future [ForEachFuture] + ) -> [ForEachFuture] where Self: Sized, F: FnMut(Self::Item), @@ -1378,7 +1378,7 @@ extension_trait! { fn any( &mut self, f: F, - ) -> impl Future [AnyFuture<'_, Self, F, Self::Item>] + ) -> [AnyFuture<'_, Self, F, Self::Item>] where Self: Unpin + Sized, F: FnMut(Self::Item) -> bool, @@ -1614,7 +1614,7 @@ extension_trait! { &mut self, init: T, f: F, - ) -> impl Future> [TryFoldFuture<'_, Self, F, T>] + ) -> [TryFoldFuture<'_, Self, F, T>] where Self: Unpin + Sized, F: FnMut(B, Self::Item) -> Result, @@ -1659,7 +1659,7 @@ extension_trait! { fn try_for_each( &mut self, f: F, - ) -> impl Future [TryForEachFuture<'_, Self, F>] + ) -> [TryForEachFuture<'_, Self, F>] where Self: Unpin + Sized, F: FnMut(Self::Item) -> Result<(), E>, @@ -1741,7 +1741,7 @@ extension_trait! { "#] #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn unzip(self) -> impl Future [UnzipFuture] + fn unzip(self) -> [UnzipFuture] where FromA: Default + Extend, FromB: Default + Extend, @@ -1805,7 +1805,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn collect<'a, B>( self, - ) -> impl Future [Pin + 'a + Send>>] + ) -> [Pin + 'a + Send>>] where Self: Sized + 'a + Send, B: FromStream, @@ -1879,7 +1879,7 @@ extension_trait! { fn partial_cmp( self, other: S - ) -> impl Future> [PartialCmpFuture] + ) -> [PartialCmpFuture] where Self: Sized + Stream, S: Stream, @@ -1919,7 +1919,7 @@ extension_trait! { fn position

( &mut self, predicate: P, - ) -> impl Future> [PositionFuture<'_, Self, P>] + ) -> [PositionFuture<'_, Self, P>] where Self: Unpin + Sized, P: FnMut(Self::Item) -> bool, @@ -1957,7 +1957,7 @@ extension_trait! { fn cmp( self, other: S - ) -> impl Future [CmpFuture] + ) -> [CmpFuture] where Self: Sized + Stream, S: Stream, @@ -1988,7 +1988,7 @@ extension_trait! { "#] #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - fn count(self) -> impl Future [CountFuture] + fn count(self) -> [CountFuture] where Self: Sized, { @@ -2023,7 +2023,7 @@ extension_trait! { fn ne( self, other: S - ) -> impl Future [NeFuture] + ) -> [NeFuture] where Self: Sized, S: Sized + Stream, @@ -2060,7 +2060,7 @@ extension_trait! { fn ge( self, other: S - ) -> impl Future [GeFuture] + ) -> [GeFuture] where Self: Sized + Stream, S: Stream, @@ -2097,7 +2097,7 @@ extension_trait! { fn eq( self, other: S - ) -> impl Future [EqFuture] + ) -> [EqFuture] where Self: Sized + Stream, S: Sized + Stream, @@ -2134,7 +2134,7 @@ extension_trait! { fn gt( self, other: S - ) -> impl Future [GtFuture] + ) -> [GtFuture] where Self: Sized + Stream, S: Stream, @@ -2171,7 +2171,7 @@ extension_trait! { fn le( self, other: S - ) -> impl Future [LeFuture] + ) -> [LeFuture] where Self: Sized + Stream, S: Stream, @@ -2208,7 +2208,7 @@ extension_trait! { fn lt( self, other: S - ) -> impl Future [LtFuture] + ) -> [LtFuture] where Self: Sized + Stream, S: Stream, @@ -2252,7 +2252,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn sum<'a, S>( self, - ) -> impl Future [Pin + 'a>>] + ) -> [Pin + 'a>>] where Self: Sized + Stream + 'a, S: Sum, @@ -2298,7 +2298,7 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn product<'a, P>( self, - ) -> impl Future [Pin + 'a>>] + ) -> [Pin + 'a>>] where Self: Sized + Stream + 'a, P: Product, diff --git a/src/utils.rs b/src/utils.rs index 42286ad1..1f3b7fc8 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -271,7 +271,7 @@ macro_rules! extension_trait { }; // Parse the return type in an extension method. - (@ext [-> impl Future [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => { + (@ext [-> [$f:ty] $($tail:tt)*] -> [$($accum:tt)*]) => { extension_trait!(@ext [$($tail)*] -> [$($accum)* -> $f]); };