Skip to content

overloaded_calls on boxed Fn<A, R> #18349

Closed
@mystor

Description

@mystor

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

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