]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-lend-flow.rs
Rollup merge of #106570 - Xaeroxe:div-duration-tests, r=JohnTitor
[rust.git] / tests / 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
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::new(**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::new(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::new(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 { }