rust-lang / rust

Empowering everyone to build reliable and efficient software.

Home Page:https://www.rust-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

overloaded_calls on boxed Fn<A, R>

mystor opened this issue · comments

It appears as though overloaded_calls doesn't work when the struct which implements Fn<A, R> is boxed.

#![feature(overloaded_calls)]

fn mk_adder(i: int) -> Box<Fn<(int,), int> + 'static> {
    struct Closure(int);
    impl Fn<(int,), int> for Closure {
        extern "rust-call" fn call(&self, args: (int,)) -> int {
            let (j,) = args;
            let &Closure(i) = self;
            i + j
        }
    }

    Closure(i)(3); // Works

    box Closure(i)
}

fn main() {
    let adder = mk_adder(5);
    (*adder)(3); // Fail
}

Example run:

$ rustc main.rs
main.rs:20:5: 20:16 error: expected function, found `core::ops::Fn<(int),int>`
main.rs:20     (*adder)(3); // Fail
               ^~~~~~~~~~~
error: aborting due to previous error

$ rustc --version=verbose
rustc 0.13.0-nightly (f168c12c5 2014-10-25 20:57:10 +0000)
binary: rustc
commit-hash: f168c12c5629afd45c9b3ed250350bf830b99642
commit-date: 2014-10-25 20:57:10 +0000
host: x86_64-apple-darwin
release: 0.13.0-nightly

This now compiles without error, once you update it to current rust.