Skip to content

Type inference when using the new slice syntax #20860

@IvanUkhov

Description

@IvanUkhov

Hello,

The following code:

#[allow(unstable)]
extern crate test;

fn foo(_: &mut[f64]) {
}

fn bar(bencher: &mut test::Bencher) {
    let mut a = vec![1.0, 2.0, 3.0];
    bencher.iter(|&mut:| foo(&mut a[])); // Works with a.as_mut_slice()
}

fn main() {
    let mut a = vec![1.0, 2.0, 3.0];
    foo(&mut a[]);
}

yields the following error:

<anon>:9:13: 9:40 error: unable to infer enough type information about `closure[<anon>:9:18: 9:39]`; type annotations required
<anon>:9     bencher.iter(|&mut:| foo(&mut a[])); // Works with a.as_mut_slice()
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101

However, replacing the new &mut a[] with the old a.as_mut_slice() makes it compile just fine. Presumably the type inference should work identically in the two cases.

Regards,
Ivan

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