Skip to content

Type inference doesn't work for functions returning generic vectors with trait bounds #10436

Closed
@huonw

Description

@huonw
fn works<T>(x: T) -> ~[T] {
    ~[x]
}

fn doesnt<T: Clone>(x: T) -> ~[T] {
    ~[x]
}

fn main() {
    let _: ~[uint] = works(0); // this is ok.
    let _: ~[uint] = doesnt(0);
}
vec-infer.rs:11:21: 11:35 error: mismatched types: expected `~[uint]` but found `~[int]` (expected u but found )
vec-infer.rs:11     let _: ~[uint] = doesnt(0);
                                     ^~~~~~~~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /home/huon/rust/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /home/huon/rust/src/librustc/lib.rs:400

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