2021-08-25 00:39:40 +00:00
|
|
|
struct Foo(Box<isize>, isize);
|
|
|
|
|
|
|
|
struct Bar(isize, isize);
|
2015-01-08 01:41:23 +00:00
|
|
|
|
2018-08-14 23:16:05 +00:00
|
|
|
|
|
|
|
|
2014-08-10 03:54:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let x: (Box<_>, _) = (Box::new(1), 2);
|
2014-08-10 03:54:33 +00:00
|
|
|
let r = &x.0;
|
|
|
|
let y = x; //~ ERROR cannot move out of `x` because it is borrowed
|
|
|
|
|
2018-08-14 23:16:05 +00:00
|
|
|
r.use_ref();
|
|
|
|
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut x = (1, 2);
|
2014-08-10 03:54:33 +00:00
|
|
|
let a = &x.0;
|
|
|
|
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
|
2018-08-14 23:16:05 +00:00
|
|
|
a.use_ref();
|
2014-08-10 03:54:33 +00:00
|
|
|
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut x = (1, 2);
|
2014-08-10 03:54:33 +00:00
|
|
|
let a = &mut x.0;
|
|
|
|
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
|
2018-08-14 23:16:05 +00:00
|
|
|
a.use_ref();
|
2014-08-10 03:54:33 +00:00
|
|
|
|
2021-08-25 00:39:40 +00:00
|
|
|
let x = Foo(Box::new(1), 2);
|
2014-08-10 03:54:33 +00:00
|
|
|
let r = &x.0;
|
|
|
|
let y = x; //~ ERROR cannot move out of `x` because it is borrowed
|
2018-08-14 23:16:05 +00:00
|
|
|
r.use_ref();
|
2014-08-10 03:54:33 +00:00
|
|
|
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut x = Bar(1, 2);
|
2014-08-10 03:54:33 +00:00
|
|
|
let a = &x.0;
|
|
|
|
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable because it is also borrowed as
|
2018-08-14 23:16:05 +00:00
|
|
|
a.use_ref();
|
2014-08-10 03:54:33 +00:00
|
|
|
|
2015-01-31 16:23:42 +00:00
|
|
|
let mut x = Bar(1, 2);
|
2014-08-10 03:54:33 +00:00
|
|
|
let a = &mut x.0;
|
|
|
|
let b = &mut x.0; //~ ERROR cannot borrow `x.0` as mutable more than once at a time
|
2018-08-14 23:16:05 +00:00
|
|
|
a.use_mut();
|
2014-08-10 03:54:33 +00:00
|
|
|
}
|
2018-08-14 23:16:05 +00:00
|
|
|
|
|
|
|
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
|
|
|
|
impl<T> Fake for T { }
|