summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/polonius/polonius-smoke-test.rs
blob: c4344af7175ac0248797d2de4e58fd3c82c7012c (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Check that Polonius borrow check works for simple cases.
// compile-flags: -Z polonius

pub fn return_ref_to_local() -> &'static i32 {
    let x = 0;
    &x //~ ERROR
}

pub fn use_while_mut() {
    let mut x = 0;
    let y = &mut x;
    let z = x; //~ ERROR
    let w = y;
}

pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
    let y = &mut *x;
    let z = x; //~ ERROR
    y
}

// Cases like this are why we have Polonius.
pub fn position_dependent_outlives(x: &mut i32, cond: bool) -> &mut i32 {
    let y = &mut *x;
    if cond {
        return y;
    } else {
        *x = 0;
        return x;
    }
}

fn foo<'a, 'b>(p: &'b &'a mut usize) -> &'b usize {
    p
}

// Check that we create constraints for well-formedness of function arguments
fn well_formed_function_inputs() {
    let s = &mut 1;
    let r = &mut *s;
    let tmp = foo(&r);
    s; //~ ERROR
    tmp;
}

fn main() {}