Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0046: not all trait items implemented, missing: `foo`
What it meansItems are missing in a trait implementation.
What rustc prints
error[E0046]: not all trait items implemented, missing: `foo`
--> main.rs:7:1
|
2 | fn foo();
| --------- `foo` from trait
...
7 | impl Foo for Bar {}
| ^^^^^^^^^^^^^^^^ missing `foo` in implementationReal 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
Items are missing in a trait implementation.
Erroneous code example:
trait Foo {
fn foo();
}
struct Bar;
impl Foo for Bar {}
// error: not all trait items implemented, missing: `foo`
When trying to make some type implement a trait Foo, you must, at minimum, provide implementations for all of Foo's required methods (meaning the methods that do not have default implementations), as well as any required trait items like associated types or constants. Example:
trait Foo {
fn foo();
}
struct Bar;
impl Foo for Bar {
fn foo() {} // ok!
}From rustc --explain E0046 (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
- E0038For any given trait `Trait` there may be a related _type_ called the _trait object type_ which is typically written as `dyn Trait`. In earlier editions of Rust, trait object types were written as plain `Trait` (just the name of the trait, written in type positions) but this was a bit too confusing, so we now write `dyn Trait`
- E0044foreign items may not have type parameters
- E0049associated function `foo` has 0 type parameters but its trait declaration has 1 type parameter
- E0050method `foo` has 1 parameter but the declaration in trait `Foo::foo` has 2
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?