#E0074: impl item does not match the trait
A method in a trait impl differs from the trait's declaration in its parameters, return type or throws. Write it as the trait declares it.
nabi
trait Shape { fn area(self) -> f64; }
struct Sq { s: f64; }
impl Shape for Sq {
fn area(self, scale: f64) -> f64 { self.s * scale }
}
error[E0074]: `area` does not match its declaration in trait `Shape`: it takes 2 parameters where the trait's takes 1 --> main.nabi:4:5 | 4 | fn area(self, scale: f64) -> f64 { self.s * scale } | ^^ | = help: write `fn area(self) -> f64`
Write the method as the trait declares it:
nabi
trait Shape { fn area(self) -> f64; }
struct Sq { s: f64; }
impl Shape for Sq {
fn area(self) -> f64 { self.s * self.s }
}
println(f"{Sq { s: 2.0 }.area()}");
4
Related: E0072 impl is missing a trait item, E0073 impl item is not in the trait
Found a mistake? Edit this page on GitHub. Last updated