Open
Description
I'm trying to create a Channel
abstraction over Sink
and Stream
and encountered the following issue:
Given the following (simplified without Sink and Stream) code: Playground
trait GenericTrait<T> {}
trait Channel<I>: GenericTrait<Self::T> {
type T;
}
trait Sender {
type Msg;
fn send<C>()
where
C: Channel<Self::Msg>;
}
impl<T> Sender for T {
type Msg = ();
fn send<C>()
where
C: Channel<Self::Msg>,
{
}
}
// This works
fn foo<I, C>(ch: C) where C: Channel<I> {}
The current output is:
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the trait bound `C: Channel<()>` is not satisfied
--> src/lib.rs:18:5
|
18 | / fn send<C>()
19 | | where
20 | | C: Channel<Self::Msg>,
| |______________________________^ the trait `Channel<()>` is not implemented for `C`
|
help: consider further restricting this bound
|
20 | C: Channel<Self::Msg> + Channel<()>,
| +++++++++++++
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the trait bound `C: Channel<()>` is not satisfied
--> src/lib.rs:20:12
|
20 | C: Channel<Self::Msg>,
| ^^^^^^^^^^^^^^^^^^ the trait `Channel<()>` is not implemented for `C`
|
help: consider further restricting this bound
|
20 | C: Channel<Self::Msg> + Channel<()>,
| +++++++++++++
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to 2 previous errors
The issue is present in stable, beta and nightly.
When either removing the generic parameter on GenericParameter<I>
, the Self::T
bound on trait Channel<I>: GenericTrait<Self::T>
or the Self::Msg
bound on the send method
fn send<C>()
where
C: Channel<Self::Msg>;
the code compiles.
I think this is at least a diagnostics bug, as the error message is quite unhelpful :D This also seems like a bug/limitation of the trait system?
This might be related/the same as #58231 or #57905, but I wasn't exactly sure.