gtk-rs / gir

Tool to generate rust bindings and user API for glib-based libraries
https://gtk-rs.org/gir/book/
MIT License
230 stars 102 forks source link

`void`-returning non-throwing async method generates broken binding code #1477

Open kawadakk opened 1 year ago

kawadakk commented 1 year ago

Given a Vala interface method:

public virtual async void hoge_async() {}

gir generates the following trampoline:

unsafe extern "C" fn hoge_async_trampoline<P: FnOnce(()) + 'static>(_source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer) {
    let _ = ffi::foo_bar_hoge_finish(_source_object as *mut _, res);
    let callback: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::from_raw(user_data as *mut _);
    let callback: P = callback.into_inner();
    callback(result); // error[E0425]: cannot find value `result` in this scope
}
kawadakk commented 1 year ago

This is where the problematic line is generated: https://github.com/gtk-rs/gir/blob/3a2fdae0a42b47a66c33fbd295594f2c22bba295/src/codegen/function_body_chunk.rs#L895-L898