Why can't types be in where clauses?

I was trying to write a function that had the following signature:

pub async fn join_all_or_first_error<T, E, I>(i: I) -> Result<Vec<T>, E>
where
    I: IntoIterator,
    <I as IntoIterator>::Item: Future,
    <<I as IntoIterator>::Item as Future>::Output: Result<T, E> { ... }

But the error expected trait, found enum "Result" was produced by rustc.

Is there a specific reason why rust doesn't allow this?

You should write

<I as IntoIterator>::Item: Future<Output = Result<T, E>>,

The reason to forbid this is because types are not traits, so it doesn't make sense to ask if a type implements another type

4 Likes