summaryrefslogtreecommitdiff
path: root/tests/compile/userdata_borrow.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/compile/userdata_borrow.rs')
-rw-r--r--tests/compile/userdata_borrow.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/compile/userdata_borrow.rs b/tests/compile/userdata_borrow.rs
new file mode 100644
index 0000000..26eb3c7
--- /dev/null
+++ b/tests/compile/userdata_borrow.rs
@@ -0,0 +1,19 @@
+use mlua::{AnyUserData, Lua, Table, UserData, Result};
+
+fn main() -> Result<()> {
+ let lua = Lua::new();
+ let globals = lua.globals();
+
+ // Should not allow userdata borrow to outlive lifetime of AnyUserData handle
+ struct MyUserData;
+ impl UserData for MyUserData {};
+ let _userdata_ref;
+ {
+ let touter = globals.get::<_, Table>("touter")?;
+ touter.set("userdata", lua.create_userdata(MyUserData)?)?;
+ let userdata = touter.get::<_, AnyUserData>("userdata")?;
+ _userdata_ref = userdata.borrow::<MyUserData>();
+ //~^ error: `userdata` does not live long enough
+ }
+ Ok(())
+}