2019-11-03 18:00:00 -06:00
|
|
|
// check-pass
|
2014-09-15 04:20:05 -05:00
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
struct Foo { a: isize, b: isize }
|
2019-04-22 02:40:08 -05:00
|
|
|
|
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut x: Box<_> = Box::new(Foo { a: 1, b: 2 });
|
2014-09-15 04:20:05 -05:00
|
|
|
let (a, b) = (&mut x.a, &mut x.b);
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut foo: Box<_> = Box::new(Foo { a: 1, b: 2 });
|
2014-09-15 04:20:05 -05:00
|
|
|
let (c, d) = (&mut foo.a, &foo.b);
|
2018-11-05 06:49:58 -06:00
|
|
|
|
2019-04-22 02:40:08 -05:00
|
|
|
// We explicitly use the references created above to illustrate that the
|
|
|
|
// borrow checker is accepting this code *not* because of artificially
|
2018-11-05 06:49:58 -06:00
|
|
|
// short lifetimes, but rather because it understands that all the
|
|
|
|
// references are of disjoint parts of memory.
|
|
|
|
use_imm(d);
|
|
|
|
use_mut(c);
|
|
|
|
use_mut(b);
|
|
|
|
use_mut(a);
|
2014-09-15 04:20:05 -05:00
|
|
|
}
|
2018-11-05 06:49:58 -06:00
|
|
|
|
|
|
|
fn use_mut<T>(_: &mut T) { }
|
|
|
|
fn use_imm<T>(_: &T) { }
|