Closed
Description
This is broken now:
fn accepts_optional_fn_ptr(_test: Option<fn(int) -> int>) {}
fn test_int(_: int) -> int { 0i }
fn main() {
accepts_optional_fn_ptr(Some(test_int));
}
because it expects Option<fn(int) -> int>
and gets Option<fn(int) -> int {test_int}>
This is an issue for FFI specifically because Option<fn(...) -> ...>
is the idiomatic way (mentioned in the FFI guide) to represent C function pointers as it takes advantage of nullable pointer optimization.
I'll add that for anyone encountering this issue, an explicit cast fixes it:
accepts_optional_fn_ptr(Some(test_int as fn(int) -> int));
Metadata
Metadata
Assignees
Labels
No labels