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.
|
|
|
|
|
2014-05-05 20:56:44 -05:00
|
|
|
|
2012-04-26 18:02:01 -05:00
|
|
|
fn borrow(_v: &int) {}
|
|
|
|
|
|
|
|
fn local() {
|
2014-06-27 14:30:25 -05:00
|
|
|
let mut v = box 3i;
|
2014-07-07 18:35:15 -05:00
|
|
|
borrow(&*v);
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn local_rec() {
|
2014-05-05 20:56:44 -05:00
|
|
|
struct F { f: Box<int> }
|
|
|
|
let mut v = F {f: box 3};
|
2014-07-07 18:35:15 -05:00
|
|
|
borrow(&*v.f);
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn local_recs() {
|
2013-02-21 17:19:40 -06:00
|
|
|
struct F { f: G }
|
|
|
|
struct G { g: H }
|
2014-05-05 20:56:44 -05:00
|
|
|
struct H { h: Box<int> }
|
|
|
|
let mut v = F {f: G {g: H {h: box 3}}};
|
2014-07-07 18:35:15 -05:00
|
|
|
borrow(&*v.f.g.h);
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
2012-05-10 21:58:23 -05:00
|
|
|
fn aliased_imm() {
|
2014-06-27 14:30:25 -05:00
|
|
|
let mut v = box 3i;
|
2012-05-10 21:58:23 -05:00
|
|
|
let _w = &v;
|
2014-07-07 18:35:15 -05:00
|
|
|
borrow(&*v);
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn aliased_mut() {
|
2014-06-27 14:30:25 -05:00
|
|
|
let mut v = box 3i;
|
2013-03-15 14:24:24 -05:00
|
|
|
let _w = &mut v;
|
2014-07-07 18:35:15 -05:00
|
|
|
borrow(&*v); //~ ERROR cannot borrow `*v`
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn aliased_other() {
|
2014-06-27 14:30:25 -05:00
|
|
|
let mut v = box 3i;
|
|
|
|
let mut w = box 4i;
|
2012-04-26 18:02:01 -05:00
|
|
|
let _x = &mut w;
|
2014-07-07 18:35:15 -05:00
|
|
|
borrow(&*v);
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn aliased_other_reassign() {
|
2014-06-27 14:30:25 -05:00
|
|
|
let mut v = box 3i;
|
|
|
|
let mut w = box 4i;
|
2012-04-26 18:02:01 -05:00
|
|
|
let mut _x = &mut w;
|
2013-03-15 14:24:24 -05:00
|
|
|
_x = &mut v;
|
2014-07-07 18:35:15 -05:00
|
|
|
borrow(&*v); //~ ERROR cannot borrow `*v`
|
2012-04-26 18:02:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|