Why does this trait bound need to be shown?
⚓ Rust 📅 2026-01-24 👤 surdeus 👁️ 1For the following code:
trait List /* supertypeclass */
{
type Next: List;
}
trait ListExtend: List
where
<Self as List>::Next: ListExtend
{}
when you run cargo check, it returns 148 and says
Checking tc_inheritance v0.1.0 (/home/rust/tc_inheritance)
error[E0277]: the trait bound `<<Self as List>::Next as List>::Next: ListExtend` is not satisfied
--> src/lib.rs:15:25
|
15 | <Self as List>::Next: ListExtend {}
| ^^^^^^^^^^ the trait `ListExtend` is not implemented for `<<Self as List>::Next as List>::Next`
|
note: required by a bound in `ListExtend`
--> src/lib.rs:15:25
|
12 | pub trait ListExtend
| ---------- required by a bound in this trait
...
15 | <Self as List>::Next: ListExtend {}
| ^^^^^^^^^^ required by this bound in `ListExtend`
help: consider further restricting the associated type
|
15 | <Self as List>::Next: ListExtend, <<Self as List>::Next as List>::Next: ListExtend {}
| ++++++++++++++++++++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.
error: could not compile `tc_inheritance` (lib) due to 1 previous error
rustc somehow wants to show <Self as List>::Next: ListExtend, but isn't that a premise?
possibly related:
3 posts - 3 participants
🏷️ Rust_feed