]> git.proxmox.com Git - rustc.git/blame - src/test/ui/nll/polonius-smoke-test.rs
Update upstream source from tag 'upstream/1.31.0_beta.4+dfsg1'
[rustc.git] / src / test / ui / nll / polonius-smoke-test.rs
CommitLineData
0bf4aa26
XL
1// Check that Polonius borrow check works for simple cases.
2// ignore-compare-mode-nll
3// compile-flags: -Z borrowck=mir -Zpolonius
4
5pub fn return_ref_to_local() -> &'static i32 {
6 let x = 0;
7 &x //~ ERROR
8}
9
10pub fn use_while_mut() {
11 let mut x = 0;
12 let y = &mut x;
13 let z = x; //~ ERROR
14 let w = y;
15}
16
17pub fn use_while_mut_fr(x: &mut i32) -> &mut i32 {
18 let y = &mut *x;
19 let z = x; //~ ERROR
20 y
21}
22
23// Cases like this are why we have Polonius.
24pub fn position_dependent_outlives(x: &mut i32, cond: bool) -> &mut i32 {
25 let y = &mut *x;
26 if cond {
27 return y;
28 } else {
29 *x = 0;
30 return x;
31 }
32}
33
34fn foo<'a, 'b>(p: &'b &'a mut usize) -> &'b usize {
35 p
36}
37
38// Check that we create constraints for well-formedness of function arguments
39fn well_formed_function_inputs() {
40 let s = &mut 1;
41 let r = &mut *s;
42 let tmp = foo(&r);
43 s; //~ ERROR
44 tmp;
45}
46
47fn main() {}