Skip to content

'duplicate definition' error with static functions in different trait scopes #3427

Closed
@brendanzab

Description

@brendanzab

Are static functions meant to be in trait scope, or module scope? Here's an example:

trait Vector2<T:Num Ord FuzzyEq> {
    pure fn x() -> T;
    pure fn y() -> T;

    static pure fn make(&&x:float, &&y:float) -> self;
}

trait Vector3<T:Num Ord FuzzyEq> {
    pure fn x() -> T;
    pure fn y() -> T;
    pure fn z() -> T;

    static pure fn make(&&x:float, &&y:float, &&z:float) -> self;

    fn cross(&&other:self) -> self;
}

trait Vector4<T:Num Ord FuzzyEq> {
    pure fn x() -> T;
    pure fn y() -> T;
    pure fn z() -> T;
    pure fn w() -> T;

    static pure fn make(&&x:float, &&y:float, &&z:float, &&w:float) -> self;
}

This is the error I get when I try to compile:

rustc src/om3d.rc --lib --out-dir=lib
src/vec.rs:61:4: 61:64 error: Duplicate definition of value make
src/vec.rs:61     static pure fn make(&&x:float, &&y:float, &&z:float) -> self;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/vec.rs:53:4: 53:53 note: First definition of value make here:
src/vec.rs:53     static pure fn make(&&x:float, &&y:float) -> self;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/vec.rs:72:4: 72:75 error: Duplicate definition of value make
src/vec.rs:72     static pure fn make(&&x:float, &&y:float, &&z:float, &&w:float) -> self;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/vec.rs:61:4: 61:64 note: First definition of value make here:
src/vec.rs:61     static pure fn make(&&x:float, &&y:float, &&z:float) -> self;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions