E0414: Method called as assoc fn
| Code | Category | Stability |
|---|---|---|
E0414 | Struct and enum | Permanent |
Explanation
A function declared with a self receiver was called through its type as though it were an associated function. A method needs a receiver value to supply self.
Likely cause
The call uses Type.method() instead of receiver.method(), or the declaration accidentally includes a self parameter. Construct or obtain a receiver value, or remove self if the function is meant to be associated with the type rather than an instance.
Examples
Method called through its type
struct Point {
x: i32,
fn value(self) -> i32 { self.x }
}
fn main() -> i32 {
Point.value()
}
Call the method on a receiver
struct Point {
x: i32,
fn value(self) -> i32 { self.x }
}
fn main() -> i32 {
let point = Point { x: 42 };
point.value()
}