2021-08-25 02:39:40 +02:00
|
|
|
fn borrow(_v: &isize) {}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
|
2018-08-15 01:16:05 +02:00
|
|
|
|
|
|
|
|
2012-04-26 16:02:01 -07:00
|
|
|
|
|
|
|
fn local() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v: Box<_> = Box::new(3);
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v);
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn local_rec() {
|
2015-01-08 21:54:35 +11:00
|
|
|
struct F { f: Box<isize> }
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v = F {f: Box::new(3)};
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v.f);
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn local_recs() {
|
2013-02-21 15:19:40 -08:00
|
|
|
struct F { f: G }
|
|
|
|
struct G { g: H }
|
2015-01-08 21:54:35 +11:00
|
|
|
struct H { h: Box<isize> }
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v = F {f: G {g: H {h: Box::new(3)}}};
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v.f.g.h);
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
2012-05-10 19:58:23 -07:00
|
|
|
fn aliased_imm() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v: Box<_> = Box::new(3);
|
2018-08-15 01:16:05 +02:00
|
|
|
let w = &v;
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v);
|
2018-08-15 01:16:05 +02:00
|
|
|
w.use_ref();
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn aliased_mut() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v: Box<_> = Box::new(3);
|
2018-08-15 01:16:05 +02:00
|
|
|
let w = &mut v;
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v); //~ ERROR cannot borrow `*v`
|
2018-08-15 01:16:05 +02:00
|
|
|
w.use_mut();
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn aliased_other() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v: Box<_> = Box::new(3);
|
|
|
|
let mut w: Box<_> = Box::new(4);
|
2018-08-15 01:16:05 +02:00
|
|
|
let x = &mut w;
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v);
|
2018-08-15 01:16:05 +02:00
|
|
|
x.use_mut();
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn aliased_other_reassign() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v: Box<_> = Box::new(3);
|
|
|
|
let mut w: Box<_> = Box::new(4);
|
2018-08-15 01:16:05 +02:00
|
|
|
let mut x = &mut w;
|
|
|
|
x = &mut v;
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v); //~ ERROR cannot borrow `*v`
|
2018-08-15 01:16:05 +02:00
|
|
|
x.use_mut();
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|
2018-08-15 01:16:05 +02:00
|
|
|
|
|
|
|
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
|
|
|
|
impl<T> Fake for T { }
|