Skip to content

Can't declare static fns in multiple anonymous implementations #4228

Closed
@erickt

Description

@erickt

Some static functions may only make sense for certain constrained typarams, but this is disallowed. For example:

type A<T> = ~[T];

impl<T> A<T> {
    static fn new() -> A<T> { ~[] }
}

impl<T: Copy> A<T> {
    static fn new_copyable() -> A<T> { ~[] }
}

fn main() {}

However, rust errors with this message:

test.rs:7:0: 9:1 error: duplicate definition of type A
test.rs:7 impl<T: Copy> A<T> {
test.rs:8     static fn new_copyable() -> A<T> { ~[] }
test.rs:9 }
test.rs:3:0: 5:1 note: first definition of type A here:
test.rs:3 impl<T> A<T> {
test.rs:4     static fn new() -> A<T> { ~[] }
test.rs:5 }
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions