2013-05-18 01:12:50 +00:00
|
|
|
enum Foo {
|
2015-01-08 11:02:42 +00:00
|
|
|
X, Y(usize, usize)
|
2013-05-18 01:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn distinct_variant() {
|
2014-11-06 08:05:53 +00:00
|
|
|
let mut y = Foo::Y(1, 2);
|
2013-05-18 01:12:50 +00:00
|
|
|
|
|
|
|
let a = match y {
|
2014-11-06 08:05:53 +00:00
|
|
|
Foo::Y(ref mut a, _) => a,
|
|
|
|
Foo::X => panic!()
|
2013-05-18 01:12:50 +00:00
|
|
|
};
|
|
|
|
|
2019-04-22 07:40:08 +00: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-18 01:12:50 +00:00
|
|
|
let b = match y {
|
2019-09-06 13:47:50 +00:00
|
|
|
//~^ ERROR cannot use `y`
|
2021-07-23 22:55:36 +00:00
|
|
|
Foo::Y(_, ref mut b) => b,
|
2014-11-06 08:05:53 +00:00
|
|
|
Foo::X => panic!()
|
2013-05-18 01:12:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*a += 1;
|
|
|
|
*b += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn same_variant() {
|
2014-11-06 08:05:53 +00:00
|
|
|
let mut y = Foo::Y(1, 2);
|
2013-05-18 01:12:50 +00:00
|
|
|
|
|
|
|
let a = match y {
|
2014-11-06 08:05:53 +00:00
|
|
|
Foo::Y(ref mut a, _) => a,
|
|
|
|
Foo::X => panic!()
|
2013-05-18 01:12:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let b = match y {
|
2021-07-23 22:55:36 +00:00
|
|
|
//~^ ERROR cannot use `y`
|
|
|
|
Foo::Y(ref mut b, _) => b,
|
|
|
|
//~^ ERROR cannot borrow `y.0` as mutable
|
2014-11-06 08:05:53 +00:00
|
|
|
Foo::X => panic!()
|
2013-05-18 01:12:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
*a += 1;
|
|
|
|
*b += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-09-24 00:20:36 +00:00
|
|
|
}
|