Skip to content

Unboxed closures: cannot invoke no-argument closures #16673

Closed
@netvl

Description

@netvl
#![feature(unboxed_closures, unboxed_closure_sugar)]

fn make_adder(a: int, b: int) -> Box<|&:| -> int> {
    (box |&:| a + b) as Box<|&:| -> int>
}

fn main() {
    println!("{}", make_adder(1, 2).call(()));
}

This code does not compile with this error:

<anon>:8:42: 8:44 error: mismatched types: expected `()` but found `()` (expected tuple but found ())
<anon>:8     println!("{}", make_adder(1, 2).call(()));
                                                  ^~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
<anon>:8:5: 8:47 note: expansion site
error: aborting due to previous error

Naturally, call() without arguments does not work, but I know of no other way to pass zero argument to the closure.

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