Trait unexpectedly not implemented with recursive where clause, with poor error message
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This is an issue we came across in Firefox. Note that the Animate impls are derived (including the where clause), which made it a bit more subtle. This is a reduced example of what's going on:
trait Animate : Sized {
fn animate(&self) {}
}
struct GenericFoo<T> {
something: i32,
fallback: T,
}
enum GenericBar<T> {
None,
TheThing(T),
Foo(Box<GenericFoo<Self>>),
}
impl Animate for i32 {}
impl Animate for f32 {}
impl<T: Animate> Animate for GenericFoo<T> {}
impl<T: Animate> Animate for GenericBar<T>
where
GenericFoo<Self>: Animate,
{}
fn main() {
let bar = GenericBar::<f32>::None;
bar.animate();
}
I expect this code to work (like it does if you remove the where GenericFoo<Self>: Animate), or at least provide a more descriptive error message (something about the where clause being cyclic or something, which is what I assume is going on, as GenericFoo<Self>: Animate requires Self: Animate?)
Instead, the compiler silently doesn't implement the trait for GenericBar<f32>, and there's nothing in the error output which would point you to the culprit (the where clause).
Meta
rustc --version --verbose:
rustc 1.89.0-nightly (16d2276fa 2025-05-16)
But happens also in stable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reduced Rust example in the issue and run it with rustc on stable and nightly, recording the trait error output. Compare the behavior with and without the recursive where clause. Done means either the valid implementation is accepted or the diagnostic identifies the cyclic where-clause requirement clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100