2021-08-24 19:39:40 -05:00
|
|
|
struct Foo(Box<isize>, isize);
|
|
|
|
|
|
|
|
struct Bar(isize, isize);
|
2015-01-07 19:41:23 -06:00
|
|
|
|
2018-08-14 18:16:05 -05:00
|
|
|
|
|
|
|
|
2014-08-09 22:54:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x: (Box<_>, _) = (Box::new(1), 2);
|
2014-08-09 22:54:33 -05:00
|
|
|
let r = &x.0;
|
|
|
|
let y = x; //~ ERROR cannot move out of `x` because it is borrowed
|
|
|
|
|
2018-08-14 18:16:05 -05:00
|
|
|
r.use_ref();
|
|
|
|
|
2015-01-31 10:23:42 -06:00
|
|
|
let mut x = (1, 2);
|
2014-08-09 22:54:33 -05: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 18:16:05 -05:00
|
|
|
a.use_ref();
|
2014-08-09 22:54:33 -05:00
|
|
|
|
2015-01-31 10:23:42 -06:00
|
|
|
let mut x = (1, 2);
|
2014-08-09 22:54:33 -05: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 18:16:05 -05:00
|
|
|
a.use_ref();
|
2014-08-09 22:54:33 -05:00
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
let x = Foo(Box::new(1), 2);
|
2014-08-09 22:54:33 -05:00
|
|
|
let r = &x.0;
|
|
|
|
let y = x; //~ ERROR cannot move out of `x` because it is borrowed
|
2018-08-14 18:16:05 -05:00
|
|
|
r.use_ref();
|
2014-08-09 22:54:33 -05:00
|
|
|
|
2015-01-31 10:23:42 -06:00
|
|
|
let mut x = Bar(1, 2);
|
2014-08-09 22:54:33 -05: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 18:16:05 -05:00
|
|
|
a.use_ref();
|
2014-08-09 22:54:33 -05:00
|
|
|
|
2015-01-31 10:23:42 -06:00
|
|
|
let mut x = Bar(1, 2);
|
2014-08-09 22:54:33 -05: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 18:16:05 -05:00
|
|
|
a.use_mut();
|
2014-08-09 22:54:33 -05:00
|
|
|
}
|
2018-08-14 18:16:05 -05:00
|
|
|
|
|
|
|
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
|
|
|
|
impl<T> Fake for T { }
|