Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0643: method `foo` has incompatible signature for trait
What it meansThis error indicates that there is a mismatch between generic parameters and impl Trait parameters in a trait declaration versus its impl.
What rustc prints
error[E0643]: method `foo` has incompatible signature for trait --> main.rs:5:12 | 2 | fn foo(&self, _: &impl Iterator); | ------------- declaration in trait here ... 5 | fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible | ^ expected `impl Trait`, found generic parameter | help: try removing the generic parameter and using `impl Trait` instead | 5 - fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible 5 + fn foo(&self, _: &impl Iterator) { } // error method `foo` has incompatible |
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
This error indicates that there is a mismatch between generic parameters and impl Trait parameters in a trait declaration versus its impl.
trait Foo {
fn foo(&self, _: &impl Iterator);
}
impl Foo for () {
fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible
// signature for trait
}From rustc --explain E0643 (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
- E0634type has conflicting packed representation hints
- E0642patterns aren't allowed in functions without bodies
- E0644closure/coroutine type that references itself
- E0665`#[derive(Default)]` on enum with no `#[default]`
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?