rust-errors-trait-bounds
Installation
SKILL.md
Rust Trait Bound Errors
Diagnose and fix the five trait-related rustc error codes. The root cause is almost always one of four things: a missing trait import, a missing bound on a generic, a missing trait implementation, or an inference failure that only looks trait-related.
Quick Reference
| Code | Message shape | Most common cause | First fix to try |
|---|---|---|---|
| E0277 | the trait bound \T: Trait` is not satisfied` |
Generic lacks the bound, or type never implements the trait | Add T: Trait to the generic, or #[derive(Trait)] on the type |
| E0599 | no method named \m` found for type `T`` |
Trait that defines the method is not imported | use the::Trait; to bring the method into scope |
| E0220 | associated type \A` not found for `Trait`` |
Wrong associated type name | Use the exact name the trait declares (e.g. Item, Output) |
| E0308 | mismatched types |
Concrete vs dyn Trait, or impl Trait unification failure |
Box the trait object, or align the two concrete types |
| E0282 | type annotations needed |
Inference has no anchor type | Add a let x: T annotation or a turbofish ::<T>() |
ALWAYS read the full error block, not just the first line. Rustc prints the following trait bounds were not satisfied and a help: note listing the exact missing bound and the source crate. That detail names the fix.