Why does the compiler say a trait bound isn't satisfied here?
⚓ Rust 📅 2026-03-25 👤 surdeus 👁️ 4Here is a simplified version of something real I'm trying to work on, where there are two traits with associated types, and the second one accepts an implementation of the first that is parameterized on the second one's associated type. Further, I need the first one's associated type to be Send:
trait T1<U> {
type AssocType1;
}
trait T2 {
type AssocType2;
fn accept<A>(_: A)
where
A: T1<Self::AssocType2>,
A::AssocType1: Send;
}
impl T2 for () {
type AssocType2 = ();
fn accept<A>(_: A)
where
A: T1<Self::AssocType2>,
A::AssocType1: Send,
{
}
}
This doesn't compile, with what seems to be a nonsense error about how T1 isn't implemented for A when the bound above clearly requires it to be:
error[E0277]: the trait bound `A: T1<()>` is not satisfied
--> src/lib.rs:19:5
|
19 | / fn accept<A>(_: A)
20 | | where
21 | | A: T1<Self::AssocType2>,
22 | | A::AssocType1: Send,
| |____________________________^ the trait `T1<()>` is not implemented for `A`
What's going on here? Is this some limitation in the constraint solver, or have I done something wrong? Note that it works fine if T1 is not generic and also if I remove the Send bound.
Is there a workaround?
5 posts - 2 participants
🏷️ Rust_feed