This repository was archived by the owner on Sep 12, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +91
-56
lines changed
Expand file tree Collapse file tree 7 files changed +91
-56
lines changed Original file line number Diff line number Diff line change 11language : rust
2- rust :
3- - stable
4- - beta
5- - nightly
62env :
73 - RUSTFLAGS="-D warnings"
4+ matrix :
5+ include :
6+ - rust : stable
7+ - rust : beta
8+ - rust : nightly
9+ script : cargo test --features compiletest_rs
810matrix :
911 allow_failures :
1012 - rust : nightly
Original file line number Diff line number Diff line change @@ -26,9 +26,11 @@ builtin-lua = ["gcc"]
2626[dependencies ]
2727libc = { version = " 0.2" }
2828failure = { version = " 0.1.1" }
29+ compiletest_rs = { version = " 0.3" , optional = true }
2930
3031[build-dependencies ]
3132gcc = { version = " 0.3.52" , optional = true }
3233
3334[dev-dependencies ]
3435rustyline = " 1.0.0"
36+
Original file line number Diff line number Diff line change @@ -744,55 +744,3 @@ fn too_many_binds() {
744744 . is_err( )
745745 ) ;
746746}
747-
748- // TODO: Need to use compiletest-rs or similar to make sure these don't compile.
749- /*
750- #[test]
751- fn should_not_compile() {
752- let lua = Lua::new();
753- let globals = lua.globals();
754-
755- // Should not allow userdata borrow to outlive lifetime of AnyUserData handle
756- struct MyUserData;
757- impl UserData for MyUserData {};
758- let userdata_ref;
759- {
760- let touter = globals.get::<_, Table>("touter").unwrap();
761- touter.set("userdata", lua.create_userdata(MyUserData)).unwrap();
762- let userdata = touter.get::<_, AnyUserData>("userdata").unwrap();
763- userdata_ref = userdata.borrow::<MyUserData>();
764- }
765-
766- // Should not allow self borrow of lua, it can change addresses
767- globals.set("boom", lua.create_function(|_, _| {
768- lua.eval::<i32>("1 + 1", None)
769- })).unwrap();
770-
771- // Should not allow Scope references to leak
772- struct MyUserdata(Rc<()>);
773- impl UserData for MyUserdata {}
774-
775- let lua = Lua::new();
776- let mut r = None;
777- lua.scope(|scope| {
778- r = Some(scope.create_userdata(MyUserdata(Rc::new(()))).unwrap());
779- });
780-
781- struct Test {
782- field: i32,
783- }
784-
785- let lua = Lua::new();
786- lua.scope(|scope| {
787- let mut test = Test { field: 0 };
788-
789- let f = scope
790- .create_function(|_, ()| {
791- test.field = 42;
792- Ok(())
793- })
794- .unwrap();
795- lua.globals().set("bad!", f).unwrap();
796- });
797- }
798- */
Original file line number Diff line number Diff line change 1+ #![ cfg( feature = "compiletest_rs" ) ]
2+
3+ extern crate compiletest_rs as compiletest;
4+
5+ use std:: path:: PathBuf ;
6+
7+ fn run_mode ( mode : & ' static str ) {
8+ let mut config = compiletest:: Config :: default ( ) ;
9+
10+ config. mode = mode. parse ( ) . expect ( "Invalid mode" ) ;
11+ config. src_base = PathBuf :: from ( format ! ( "tests/{}" , mode) ) ;
12+ config. target_rustcflags = Some ( "-L target/debug -L target/debug/deps" . to_string ( ) ) ;
13+
14+ compiletest:: run_tests ( & config) ;
15+ }
16+
17+ #[ test]
18+ fn compile_test ( ) {
19+ run_mode ( "compile-fail" ) ;
20+ }
Original file line number Diff line number Diff line change 1+ extern crate rlua;
2+
3+ use rlua:: * ;
4+
5+ fn main ( ) {
6+ let lua = Lua :: new ( ) ;
7+ struct Test ( i32 ) ;
8+
9+ let test = Test ( 0 ) ;
10+
11+ let func = lua. create_function ( |_, ( ) | -> Result < i32 > {
12+ //~^ error: closure may outlive the current function, but it borrows `test`, which is owned by the current function
13+ Ok ( test. 0 )
14+ } ) ;
15+ }
Original file line number Diff line number Diff line change 1+ extern crate rlua;
2+
3+ use rlua:: * ;
4+
5+ fn main ( ) {
6+ struct Test {
7+ field : i32 ,
8+ }
9+
10+ let lua = Lua :: new ( ) ;
11+ lua. scope ( |scope| {
12+ let f = {
13+ let mut test = Test { field : 0 } ;
14+
15+ scope
16+ . create_function_mut ( |_, ( ) | {
17+ test. field = 42 ;
18+ //~^ error: `test` does not live long enough
19+ Ok ( ( ) )
20+ } )
21+ . unwrap ( )
22+ } ;
23+
24+ f. call :: < _ , ( ) > ( ( ) ) . unwrap ( ) ;
25+ } ) ;
26+ }
Original file line number Diff line number Diff line change 1+ extern crate rlua;
2+
3+ use rlua:: * ;
4+
5+ fn main ( ) {
6+ let lua = Lua :: new ( ) ;
7+ let globals = lua. globals ( ) ;
8+
9+ // Should not allow userdata borrow to outlive lifetime of AnyUserData handle
10+ struct MyUserData ;
11+ impl UserData for MyUserData { } ;
12+ let userdata_ref;
13+ {
14+ let touter = globals. get :: < _ , Table > ( "touter" ) . unwrap ( ) ;
15+ touter
16+ . set ( "userdata" , lua. create_userdata ( MyUserData ) . unwrap ( ) )
17+ . unwrap ( ) ;
18+ let userdata = touter. get :: < _ , AnyUserData > ( "userdata" ) . unwrap ( ) ;
19+ userdata_ref = userdata. borrow :: < MyUserData > ( ) ;
20+ //~^ error: `userdata` does not live long enough
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments