Skip to content

Commit

Permalink
Rollup merge of rust-lang#94818 - yoshuawuyts:into-future-associated-…
Browse files Browse the repository at this point in the history
…type, r=joshtriplett

Rename `IntoFuture::Future` to `IntoFuture::IntoFuture`

Ref: rust-lang#67644 (comment)

This renames `IntoFuture::Future` to `IntoFuture::IntoFuture`. This adds the `Into*` prefix to the associated type, similar to the [`IntoIterator::IntoIter`](https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#associatedtype.IntoIter) associated type. It's my mistake we didn't do so in the first place. This fixes that and brings the two closer together. Thanks!

### References
__`IntoIterator` trait def__
```rust
pub trait IntoIterator {
    type Item;
    type IntoIter: Iterator<Item = Self::Item>;
    fn into_iter(self) -> Self::IntoIter;
}
```
__`IntoFuture` trait def__
```rust
pub trait IntoFuture {
    type Output;
    type IntoFuture: Future<Output = Self::Output>; // Prior to this PR: `type Future:`
    fn into_future(self) -> Self::IntoFuture;
}
```

cc/ `@eholk` `@rust-lang/wg-async`
  • Loading branch information
Dylan-DPC authored Mar 11, 2022
2 parents 86376e3 + 3f2cb6e commit fedf70a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions library/core/src/future/into_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ pub trait IntoFuture {

/// Which kind of future are we turning this into?
#[unstable(feature = "into_future", issue = "67644")]
type Future: Future<Output = Self::Output>;
type IntoFuture: Future<Output = Self::Output>;

/// Creates a future from a value.
#[unstable(feature = "into_future", issue = "67644")]
#[lang = "into_future"]
fn into_future(self) -> Self::Future;
fn into_future(self) -> Self::IntoFuture;
}

#[unstable(feature = "into_future", issue = "67644")]
impl<F: Future> IntoFuture for F {
type Output = F::Output;
type Future = F;
type IntoFuture = F;

fn into_future(self) -> Self::Future {
fn into_future(self) -> Self::IntoFuture {
self
}
}
4 changes: 2 additions & 2 deletions src/test/ui/async-await/await-into-future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ struct AwaitMe;

impl IntoFuture for AwaitMe {
type Output = i32;
type Future = Pin<Box<dyn Future<Output = i32>>>;
type IntoFuture = Pin<Box<dyn Future<Output = i32>>>;

fn into_future(self) -> Self::Future {
fn into_future(self) -> Self::IntoFuture {
Box::pin(me())
}
}
Expand Down

0 comments on commit fedf70a

Please sign in to comment.