2019-11-04 00:00:00 +00:00
|
|
|
// check-pass
|
2014-09-15 21:20:05 +12:00
|
|
|
|
2019-04-22 08:40:08 +01:00
|
|
|
#![feature(box_syntax)]
|
2015-01-07 18:53:58 -08:00
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
struct Foo { a: isize, b: isize }
|
2019-04-22 08:40:08 +01:00
|
|
|
|
|
|
|
fn main() {
|
2015-02-17 21:41:32 +01:00
|
|
|
let mut x: Box<_> = box Foo { a: 1, b: 2 };
|
2014-09-15 21:20:05 +12:00
|
|
|
let (a, b) = (&mut x.a, &mut x.b);
|
|
|
|
|
2015-02-17 21:41:32 +01:00
|
|
|
let mut foo: Box<_> = box Foo { a: 1, b: 2 };
|
2014-09-15 21:20:05 +12:00
|
|
|
let (c, d) = (&mut foo.a, &foo.b);
|
2018-11-05 13:49:58 +01:00
|
|
|
|
2019-04-22 08:40:08 +01: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 13:49:58 +01: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 21:20:05 +12:00
|
|
|
}
|
2018-11-05 13:49:58 +01:00
|
|
|
|
|
|
|
fn use_mut<T>(_: &mut T) { }
|
|
|
|
fn use_imm<T>(_: &T) { }
|