]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/borrowck-lend-flow.rs
Do not use entropy during gen_weighted_bool(1)
[rust.git] / src / test / compile-fail / borrowck-lend-flow.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Note: the borrowck analysis is currently flow-insensitive.
12 // Therefore, some of these errors are marked as spurious and could be
13 // corrected by a simple change to the analysis.  The others are
14 // either genuine or would require more advanced changes.  The latter
15 // cases are noted.
16
17
18 fn borrow(_v: &int) {}
19 fn borrow_mut(_v: &mut int) {}
20 fn cond() -> bool { panic!() }
21 fn for_func(_f: || -> bool) { panic!() }
22 fn produce<T>() -> T { panic!(); }
23
24 fn inc(v: &mut Box<int>) {
25     *v = box() (**v + 1);
26 }
27
28 fn pre_freeze() {
29     // In this instance, the freeze starts before the mut borrow.
30
31     let mut v = box 3;
32     let _w = &v;
33     borrow_mut(&mut *v); //~ ERROR cannot borrow
34 }
35
36 fn post_freeze() {
37     // In this instance, the const alias starts after the borrow.
38
39     let mut v = box 3;
40     borrow_mut(&mut *v);
41     let _w = &v;
42 }
43
44 fn main() {}