Skip to content

fn's can no longer be implicitly converted to closures #4544

Closed
@Dretch

Description

@Dretch

The code used to work, but now it doesn't compile:

fn double(x: int) -> int {
    x * 2
}

fn main() {
    let v = (~[1, 2, 3]).map(double);
}

Rustc says:

test-extern-fn.rs:9:29: 9:35 error: mismatched types: expected `&fn(+:&<VI2>) -> <V8>` but found `extern fn(int) -> int` (expected &-ptr but found int)
test-extern-fn.rs:9     let v = (~[1, 2, 3]).map(double);
                                                 ^~~~~~
test-extern-fn.rs:9:8: 9:36 error: cannot determine a type for this local variable: unconstrained type
test-extern-fn.rs:9     let v = (~[1, 2, 3]).map(double);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors

This may be intentional but also might be a bug.

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