2013-05-17 21:12:50 -04:00
|
|
|
enum Foo {
|
2015-01-08 22:02:42 +11:00
|
|
|
X, Y(usize, usize)
|
2013-05-17 21:12:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn distinct_variant() {
|
2014-11-06 00:05:53 -08:00
|
|
|
let mut y = Foo::Y(1, 2);
|
2013-05-17 21:12:50 -04:00
|
|
|
|
|
|
|
let a = match y {
|
2014-11-06 00:05:53 -08:00
|
|
|
Foo::Y(ref mut a, _) => a,
|
|
|
|
Foo::X => panic!()
|
2013-05-17 21:12:50 -04:00
|
|
|
};
|
|
|
|
|
2019-04-22 08:40:08 +01:00
|
|
|
// While `a` and `b` are disjoint, borrowck doesn't know that `a` is not
|
|
|
|
// also used for the discriminant of `Foo`, which it would be if `a` was a
|
|
|
|
// reference.
|
2013-05-17 21:12:50 -04:00
|
|
|
let b = match y {
|
2019-09-06 15:47:50 +02:00
|
|
|
//~^ ERROR cannot use `y`
|
2021-07-23 18:55:36 -04:00
|
|
|
Foo::Y(_, ref mut b) => b,
|
2014-11-06 00:05:53 -08:00
|
|
|
Foo::X => panic!()
|
2013-05-17 21:12:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
*a += 1;
|
|
|
|
*b += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn same_variant() {
|
2014-11-06 00:05:53 -08:00
|
|
|
let mut y = Foo::Y(1, 2);
|
2013-05-17 21:12:50 -04:00
|
|
|
|
|
|
|
let a = match y {
|
2014-11-06 00:05:53 -08:00
|
|
|
Foo::Y(ref mut a, _) => a,
|
|
|
|
Foo::X => panic!()
|
2013-05-17 21:12:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
let b = match y {
|
2021-07-23 18:55:36 -04:00
|
|
|
//~^ ERROR cannot use `y`
|
|
|
|
Foo::Y(ref mut b, _) => b,
|
|
|
|
//~^ ERROR cannot borrow `y.0` as mutable
|
2014-11-06 00:05:53 -08:00
|
|
|
Foo::X => panic!()
|
2013-05-17 21:12:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
*a += 1;
|
|
|
|
*b += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-09-23 17:20:36 -07:00
|
|
|
}
|