Specify the types exactly in the scary transmute

If I happen to change the definition of the Callback type alias, instead of
creating a potentially arbitrary transmute, it will now instead fail to compile.
This commit is contained in:
kyren 2018-02-11 08:30:03 -05:00
parent a91e3ed411
commit da1e1625b3
1 changed files with 9 additions and 7 deletions

View File

@ -1066,15 +1066,17 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
R: ToLuaMulti<'callback>, R: ToLuaMulti<'callback>,
F: 'scope + Fn(&'callback Lua, A) -> Result<R>, F: 'scope + Fn(&'callback Lua, A) -> Result<R>,
{ {
unsafe { let f: Box<
let f: Box< Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>> + 'scope,
Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>> + 'scope, > = Box::new(move |lua, args| func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua));
> = Box::new(move |lua, args| {
func(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
});
unsafe {
// SCARY, we are transmuting the 'scope lifetime to 'static. // SCARY, we are transmuting the 'scope lifetime to 'static.
let mut f = self.lua.create_callback_function(mem::transmute(f))?; let f: Box<
Fn(&'callback Lua, MultiValue<'callback>) -> Result<MultiValue<'callback>>,
> = mem::transmute(f);
let mut f = self.lua.create_callback_function(f)?;
f.0.drop_unref = false; f.0.drop_unref = false;
let mut destructors = self.destructors.borrow_mut(); let mut destructors = self.destructors.borrow_mut();