Skip to content

Feature Request: Allow default implementations of static methods in derived traits. #3880

Closed
@Dretch

Description

@Dretch

I think it would be great if this sort of thing worked:

trait Shizzle {
    static fn shizzle();
}

trait Shozzle : Shizzle {
    static fn shizzle() {
        io::println(~"shizzle! " + shozzle::<self>());
    }
    static fn shozzle() -> ~str;
}

impl int : Shozzle {
    static fn shozzle() -> ~str { ~"i'm an int!" }
}

fn main() {
    shizzle::<int>();
}

Currently it fails with this error:

test-trait-inheritance.rs:12:4: 12:23 error: duplicate definition of value shizzle
test-trait-inheritance.rs:12     static fn shizzle() {
                                 ^~~~~~~~~~~~~~~~~~~
test-trait-inheritance.rs:5:4: 5:23 note: first definition of value shizzle here:
test-trait-inheritance.rs:5     static fn shizzle();
                                ^~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

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