Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0415: Assoc fn called as method

CodeCategoryStability
E0415Struct and enumPermanent

Explanation

A function declared without a self receiver was called on a value as though it were a method. An associated function is selected through its struct type instead.

Likely cause

The call uses receiver.function() instead of Type.function(), or the declaration is missing its intended self parameter. Call it through the type, or add the appropriate receiver parameter when instance access is intended.

Examples

Associated function called on a value

struct Point {
    x: i32,

    fn origin() -> Point { Point { x: 0 } }
}
fn main() -> i32 {
    let point = Point { x: 42 };
    point.origin().x
}

Call the associated function through its type

struct Point {
    x: i32,

    fn origin() -> Point { Point { x: 0 } }
}
fn main() -> i32 {
    Point.origin().x
}

References