Add compilefail test for Scope::create_nonstatic_userdata

This commit is contained in:
kyren 2018-09-16 19:54:58 -04:00
parent 7eb71fb1df
commit 4a587ca1c5
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
extern crate rlua;
use rlua::*;
fn main() {
let lua = Lua::new();
let globals = lua.globals();
// Should not allow userdata borrow to outlive lifetime of AnyUserData handle
struct MyUserData<'a>(&'a i32);
impl<'a> UserData for MyUserData<'a> {};
let igood = 1;
let lua = Lua::new();
lua.scope(|scope| {
let ugood = scope.create_nonstatic_userdata(MyUserData(&igood)).unwrap();
let ubad = {
let ibad = 42;
scope.create_nonstatic_userdata(MyUserData(&ibad)).unwrap();
//~^ error: `ibad` does not live long enough
};
});
}