diff options
author | kyren <kerriganw@gmail.com> | 2018-09-16 19:54:58 -0400 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2018-09-16 19:54:58 -0400 |
commit | 4a587ca1c598b0afa3ac74972fb6fcea3788493d (patch) | |
tree | c431cc47fc2605a2300a67719bcffcb42ef5b532 /tests/compile-fail | |
parent | 7eb71fb1dfa6bbca9792537baadbca30b438b77a (diff) | |
download | mlua-4a587ca1c598b0afa3ac74972fb6fcea3788493d.zip |
Add compilefail test for Scope::create_nonstatic_userdata
Diffstat (limited to 'tests/compile-fail')
-rw-r--r-- | tests/compile-fail/scope_userdata_borrow.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/compile-fail/scope_userdata_borrow.rs b/tests/compile-fail/scope_userdata_borrow.rs new file mode 100644 index 0000000..7d94e04 --- /dev/null +++ b/tests/compile-fail/scope_userdata_borrow.rs @@ -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 + }; + }); +} |