2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-04-26 18:02:01 -05:00
|
|
|
// Note: the borrowck analysis is currently flow-insensitive.
|
|
|
|
// Therefore, some of these errors are marked as spurious and could be
|
|
|
|
// corrected by a simple change to the analysis. The others are
|
|
|
|
// either genuine or would require more advanced changes. The latter
|
|
|
|
// cases are noted.
|
|
|
|
|
|
|
|
fn borrow(_v: &int) {}
|
2013-03-15 14:24:24 -05:00
|
|
|
fn borrow_mut(_v: &mut int) {}
|
|
|
|
fn cond() -> bool { fail!() }
|
|
|
|
fn for_func(_f: &fn() -> bool) { fail!() }
|
|
|
|
fn produce<T>() -> T { fail!(); }
|
2012-04-26 18:02:01 -05:00
|
|
|
|
|
|
|
fn inc(v: &mut ~int) {
|
|
|
|
*v = ~(**v + 1);
|
|
|
|
}
|
|
|
|
|
2013-03-15 14:24:24 -05:00
|
|
|
fn pre_freeze() {
|
|
|
|
// In this instance, the freeze starts before the mut borrow.
|
2012-04-26 18:02:01 -05:00
|
|
|
|
|
|
|
let mut v = ~3;
|
2013-03-15 14:24:24 -05:00
|
|
|
let _w = &v;
|
|
|
|
borrow_mut(v); //~ ERROR cannot borrow
|
2012-07-26 10:51:57 -05:00
|
|
|
}
|
|
|
|
|
2013-03-15 14:24:24 -05:00
|
|
|
fn pre_const() {
|
|
|
|
// In this instance, the freeze starts before the mut borrow.
|
2012-07-26 10:51:57 -05:00
|
|
|
|
|
|
|
let mut v = ~3;
|
2013-03-15 14:24:24 -05:00
|
|
|
let _w = &const v;
|
|
|
|
borrow_mut(v);
|
2012-05-10 21:58:23 -05:00
|
|
|
}
|
|
|
|
|
2013-03-15 14:24:24 -05:00
|
|
|
fn post_freeze() {
|
|
|
|
// In this instance, the const alias starts after the borrow.
|
2012-04-26 18:02:01 -05:00
|
|
|
|
2013-03-15 14:24:24 -05:00
|
|
|
let mut v = ~3;
|
|
|
|
borrow_mut(v);
|
|
|
|
let _w = &v;
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|