summaryrefslogtreecommitdiff
path: root/tests/compile-fail/scope_invariance.rs
blob: d63634ea78ba80fb9ce0e28c329833467d6743f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
extern crate rlua;

use rlua::*;

fn main() {
    struct Test {
        field: i32,
    }

    let lua = Lua::new();
    lua.scope(|scope| {
        let f = {
            let mut test = Test { field: 0 };

            scope
                .create_function_mut(|_, ()| {
                    test.field = 42;
                    //~^ error: `test` does not live long enough
                    Ok(())
                })
                .unwrap()
        };

        f.call::<_, ()>(()).unwrap();
    });
}