Skip to content

Handle passing functions as argument by value through generic types #1483

@CohenArthur

Description

@CohenArthur
#[lang = "fn_once"]
pub trait FnOnce<Args> {
    #[lang = "fn_once_output"]
    type Output;

    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}

fn takes_fn_generic<F: FnOnce(i32) -> i32>(a: i32, f: F) -> i32 {
    f(a)
}

fn takes_fn_generic_where<F>(a: i32, f: F) -> i32 where F: FnOnce(i32) -> i32 {
    f(a)
}

returns:

<source>:9:65: error: expected 'i32' got '<placeholder:>'
    9 | fn takes_fn_generic<F: FnOnce(i32) -> i32>(a: i32, f: F) -> i32 {
      | ~~                                                          ~~~ ^
<source>:13:79: error: expected 'i32' got '<placeholder:>'
   13 | fn takes_fn_generic_where<F>(a: i32, f: F) -> i32 where F: FnOnce(i32) -> i32 {
      | ~~                                            ~~~    

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions