E3024#
Legacy constructor functions declared inside a struct must have name new.
This error happens when a constructor function declared inside a struct is
not named new. This is a legacy syntax diagnostic: renaming the nested
function to new is not a migration to current syntax. The compiler also
rejects nested constructor declarations with E3002; use a top-level constructor
instead.
Erroneous example#
pub struct S {
x : Int32
fn constr(x : Int32) -> S
}
fn S::constr(x : Int32) -> S {
{ x, }
}
Suggestion#
Define the constructor with the current top-level Type::Type form:
pub struct S {
x : Int32
}
fn S::S(x : Int32) -> S {
{ x, }
}
pub fn make(x : Int32) -> S {
S(x)
}