Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0276: impl has stricter requirements than trait
What it meansA trait implementation has stricter requirements than the trait definition.
What rustc prints
error[E0276]: impl has stricter requirements than trait
--> main.rs:6:30
|
2 | fn foo<T>(x: T);
| ---------------- definition of `foo` from trait
...
6 | fn foo<T>(x: T) where T: Copy {}
| ^^^^ impl has extra requirement `T: Copy`Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
A trait implementation has stricter requirements than the trait definition.
Erroneous code example:
trait Foo {
fn foo<T>(x: T);
}
impl Foo for bool {
fn foo<T>(x: T) where T: Copy {}
}
Here, all types implementing Foo must have a method foo<T>(x: T) which can take any type T. However, in the impl for bool, we have added an extra bound that T is Copy, which isn't compatible with the original trait.
Consider removing the bound from the method or adding the bound to the original method definition in the trait.
From rustc --explain E0276 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0433failed to resolve
- E0271type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
- E0275overflow evaluating the requirement `Bar<Bar<Bar<Bar<Bar<Bar<Bar<_>>>>>>>: Foo`
- E0282type annotations needed
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?