Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Fix "zero-sized fn" nightly warnings #278

Closed
gkoz opened this issue Mar 15, 2016 · 8 comments
Closed

Fix "zero-sized fn" nightly warnings #278

gkoz opened this issue Mar 15, 2016 · 8 comments
Milestone

Comments

@gkoz
Copy link
Member

gkoz commented Mar 15, 2016

Example:

src/signal.rs:93:70: 93:79 warning: `extern "C" fn(&core::cell::RefCell<Box<core::ops::FnMut() -> glib::source::Continue + 'static>>) -> i32 {signal::trampoline}` is now zero-sized and has to be cast to a pointer before transmuting to `core::option::Option<unsafe extern "C" fn(*mut libc::c_void) -> i32>`, #[warn(transmute_from_fn_item_types)] on by default

src/signal.rs:93         glib_ffi::g_idle_add_full(glib_ffi::G_PRIORITY_DEFAULT_IDLE, transmute(trampoline),

                                                                                      ^~~~~~~~~

src/signal.rs:93:70: 93:79 warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

src/signal.rs:93:70: 93:79 note: for more information, see issue #19925 <https://github.com/rust-lang/rust/issues/19925>

We should make our extern fns match the expected signatures to make transmutes unnecessary.

@gkoz gkoz added this to the 0.0.8 milestone Mar 15, 2016
@GuillaumeGomez
Copy link
Member

Can't we just cast as *mut c_void? It would do the same after all.

@gkoz
Copy link
Member Author

gkoz commented Mar 15, 2016

Transmuting fn is too fragile anyway. More error-prone than transmuting or casting individual arguments.

@gkoz
Copy link
Member Author

gkoz commented Mar 15, 2016

Um, well, speaking of signals there may not be actual signatures to adhere to. I'm not sure now. So this issue needs some investigation.

@EPashkin
Copy link
Member

rust-lang/rust#19925 stated that we can do even transmute(size_changed_trampoline as usize).
As for @gkoz concern about transmuting individual arguments IMHO it not applied here, except for &Box<Fn> argument that really not error-prone.
May be better solution will be pass some structure with some id and function pointer that will be checked before using function but it needed some storage with unclear rule for erasing elements.
As we need transmute trampoline anyway IMHO better add cast sooner.

@gkoz
Copy link
Member Author

gkoz commented Mar 19, 2016

It looks like we'll have to use the as usize workaround for signal trampolines because there's no other choice there. Callbacks with defined types (like GtkTreeModelFilterVisibleFunc) and g_idle_add can avoid transmuting fns.

@EPashkin
Copy link
Member

I add PR for gtk and glib then.

@EPashkin
Copy link
Member

Also calling g_idle_add_full and others in glib also needed casting.

@gkoz
Copy link
Member Author

gkoz commented Mar 21, 2016

Looks like all warnings are gone. Thanks @EPashkin

@gkoz gkoz closed this as completed Mar 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants