rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.38k stars 624 forks source link

Constrain `Future::Output` in supertrait of `TryFuture` #2763

Open hlbarber opened 1 year ago

hlbarber commented 1 year ago

The obstruction to

trait TryFuture: Future<Output = Result<Self::Ok, Self::Error>> {
    type Ok;
    type Error;
}

originally stated in https://github.com/rust-lang/futures-rs/issues/1776#issuecomment-518307092 no longer exists.

This PR provides an insight into what taking such a change now would look like now.

In addition to the minimal change to the TryFuture trait seen in a88e11011e33df8e6345b1a8527447f3dd5399c5, we additionally:

hlbarber commented 1 year ago

A corresponding change can be made to TryStream.

taiki-e commented 1 year ago

See https://github.com/rust-lang/futures-rs/issues/2508 for the previous discussion.

hlbarber commented 1 year ago

This would require an MSRV bump to rustc version 1.52.

Failing 1.51 Passing 1.52

taiki-e commented 1 year ago

As mentioned in https://github.com/rust-lang/futures-rs/issues/2508#issuecomment-942407374, https://github.com/rust-lang/futures-rs/pull/2344 will unblock this.