Skip to content

Unusual return value from FnOnce closure #16591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomjakubowski opened this issue Aug 18, 2014 · 3 comments · Fixed by #16655
Closed

Unusual return value from FnOnce closure #16591

tomjakubowski opened this issue Aug 18, 2014 · 3 comments · Fixed by #16655
Labels
A-closures Area: Closures (`|…| { … }`)

Comments

@tomjakubowski
Copy link
Contributor

#![feature(unboxed_closures, unboxed_closure_sugar)]

use std::ops::FnOnce;

fn main() {
    let task: Box<|: int| -> int> = box |: x| x;
    let (vtable, data): (*mut (), *mut ()) = unsafe { std::mem::transmute_copy(&task) };
    println!("vtable {}", vtable);
    println!("data   {}", data);
    println!("return 0x{:x}", task.call_once((0i, )));
}

prints something like:

vtable 0x7f9fa1b750c0
data   0x7f9fa1b7bc40
return 0x7f9fa1b7bc40

task.call_once() with a string slice tends to cause a segfault.

@tomjakubowski
Copy link
Contributor Author

Updated with a much shorter example.

@huonw
Copy link
Member

huonw commented Aug 19, 2014

It seems to be returning the data pointer of the Box trait object. (It's also a little weird that there is a data pointer, since the closure is theoretically zero sized, as it has no captures. It's doing the right thing: all zero sized allocations point to the same (non-null) address.)

@pcwalton
Copy link
Contributor

I think we need an unboxing shim here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants