]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/borrowck-lend-flow.rs
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / src / test / compile-fail / borrowck-lend-flow.rs
CommitLineData
223e47cc
LB
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
1a4d82fc 17#![feature(box_syntax)]
223e47cc 18
1a4d82fc
JJ
19fn borrow(_v: &isize) {}
20fn borrow_mut(_v: &mut isize) {}
21fn cond() -> bool { panic!() }
22fn for_func<F>(_f: F) where F: FnOnce() -> bool { panic!() }
23fn produce<T>() -> T { panic!(); }
223e47cc 24
1a4d82fc
JJ
25fn inc(v: &mut Box<isize>) {
26 *v = box() (**v + 1);
c1a9b12d 27 //~^ WARN deprecated syntax
223e47cc
LB
28}
29
1a4d82fc 30fn pre_freeze() {
970d7e83 31 // In this instance, the freeze starts before the mut borrow.
223e47cc 32
c34b1796 33 let mut v: Box<_> = box 3;
1a4d82fc
JJ
34 let _w = &v;
35 borrow_mut(&mut *v); //~ ERROR cannot borrow
223e47cc
LB
36}
37
970d7e83
LB
38fn post_freeze() {
39 // In this instance, the const alias starts after the borrow.
223e47cc 40
c34b1796 41 let mut v: Box<_> = box 3;
1a4d82fc 42 borrow_mut(&mut *v);
970d7e83 43 let _w = &v;
223e47cc
LB
44}
45
46fn main() {}