]> git.proxmox.com Git - rustc.git/blob - src/test/ui/borrowck/borrowck-lend-flow.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / src / test / ui / borrowck / borrowck-lend-flow.rs
1 // Note: the borrowck analysis is currently flow-insensitive.
2 // Therefore, some of these errors are marked as spurious and could be
3 // corrected by a simple change to the analysis. The others are
4 // either genuine or would require more advanced changes. The latter
5 // cases are noted.
6
7 #![feature(box_syntax)]
8
9 fn borrow(_v: &isize) {}
10 fn borrow_mut(_v: &mut isize) {}
11 fn cond() -> bool { panic!() }
12 fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
13 fn produce<T>() -> T { panic!(); }
14
15 fn inc(v: &mut Box<isize>) {
16 *v = box (**v + 1);
17 }
18
19 fn pre_freeze() {
20 // In this instance, the freeze starts before the mut borrow.
21
22 let mut v: Box<_> = box 3;
23 let _w = &v;
24 borrow_mut(&mut *v); //~ ERROR cannot borrow
25 _w.use_ref();
26 }
27
28 fn post_freeze() {
29 // In this instance, the const alias starts after the borrow.
30
31 let mut v: Box<_> = box 3;
32 borrow_mut(&mut *v);
33 let _w = &v;
34 }
35
36 fn main() {}
37
38 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
39 impl<T> Fake for T { }