Is the type parameter `O` unconstrained?
⚓ Rust 📅 2025-09-10 👤 surdeus 👁️ 8Consider this example:
trait MyFuture<Arg> {
//type Output: Future;
}
impl< F: Fn(Arg) -> O,Arg:Send, O: Future<Output = U>, U> MyFuture<Arg> for F {
//type Output = O;
}
The type parameter O is neither in the impl trait, self type, nor predicates. However, this example can be compiled. If you remove Arg from MyFuture, for example:
trait MyFuture {
//type Output: Future;
}
impl< F: Fn(Arg) -> O,Arg:Send, O: Future<Output = U>, U> MyFuture for F {
//type Output = O;
}
The compiler will report an error:
Compiling playground v0.0.1 (/playground)
error[E0207]: the type parameter `Arg` is not constrained by the impl trait, self type, or predicates
--> src/main.rs:4:23
|
4 | impl< F: Fn(Arg) -> O,Arg:Send, O: Future<Output = U>, U> MyFuture for F {
| ^^^ unconstrained type parameter
error[E0207]: the type parameter `O` is not constrained by the impl trait, self type, or predicates
--> src/main.rs:4:33
|
4 | impl< F: Fn(Arg) -> O,Arg:Send, O: Future<Output = U>, U> MyFuture for F {
| ^ unconstrained type parameter
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
--> src/main.rs:4:56
|
4 | impl< F: Fn(Arg) -> O,Arg:Send, O: Future<Output = U>, U> MyFuture for F {
| ^ unconstrained type parameter
which implies that both O and U are unconstrained type parameters. What's the reason here?
2 posts - 2 participants
🏷️ Rust_feed