forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Infer async closure args from Fn bound even if there is no correspond…
…ing Future bound
- Loading branch information
1 parent
80eb5a8
commit 4290943
Showing
2 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//@ check-pass | ||
//@ edition: 2021 | ||
|
||
// Make sure that we infer the args of an async closure even if it's passed to | ||
// a function that requires the async closure implement `Fn*` but does *not* have | ||
// a `Future` bound on the return type. | ||
|
||
#![feature(async_closure)] | ||
|
||
use std::future::Future; | ||
|
||
trait TryStream { | ||
type Ok; | ||
type Err; | ||
} | ||
|
||
trait TryFuture { | ||
type Ok; | ||
type Err; | ||
} | ||
|
||
impl<F, T, E> TryFuture for F where F: Future<Output = Result<T, E>> { | ||
type Ok = T; | ||
type Err = E; | ||
} | ||
|
||
trait TryStreamExt: TryStream { | ||
fn try_for_each<F, Fut>(&self, f: F) | ||
where | ||
F: FnMut(Self::Ok) -> Fut, | ||
Fut: TryFuture<Ok = (), Err = Self::Err>; | ||
} | ||
|
||
impl<S> TryStreamExt for S where S: TryStream { | ||
fn try_for_each<F, Fut>(&self, f: F) | ||
where | ||
F: FnMut(Self::Ok) -> Fut, | ||
Fut: TryFuture<Ok = (), Err = Self::Err>, | ||
{ } | ||
} | ||
|
||
fn test(stream: impl TryStream<Ok = &'static str, Err = ()>) { | ||
stream.try_for_each(async |s| { | ||
s.trim(); // Make sure we know the type of `s` at this point. | ||
Ok(()) | ||
}); | ||
} | ||
|
||
fn main() {} |