2018-09-04 12:05:53 +02:00
|
|
|
//@ run-pass
|
2018-09-06 13:51:09 +02:00
|
|
|
#![allow(non_camel_case_types)]
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2013-12-31 15:46:27 -08:00
|
|
|
use std::cell::Cell;
|
|
|
|
|
2015-03-30 09:38:27 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2012-06-12 12:05:26 -07:00
|
|
|
enum newtype {
|
2015-03-25 17:06:52 -07:00
|
|
|
newvar(isize)
|
2012-06-12 12:05:26 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2012-06-12 12:05:26 -07:00
|
|
|
|
|
|
|
// Test that borrowck treats enums with a single variant
|
|
|
|
// specially.
|
|
|
|
|
2014-10-02 08:10:09 +03:00
|
|
|
let x = &Cell::new(5);
|
2014-11-06 00:05:53 -08:00
|
|
|
let y = &Cell::new(newtype::newvar(3));
|
2013-12-31 15:46:27 -08:00
|
|
|
let z = match y.get() {
|
2014-11-06 00:05:53 -08:00
|
|
|
newtype::newvar(b) => {
|
2013-12-31 15:46:27 -08:00
|
|
|
x.set(x.get() + 1);
|
|
|
|
x.get() * b
|
2012-06-12 12:05:26 -07:00
|
|
|
}
|
|
|
|
};
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(z, 18);
|
2013-02-14 11:47:00 -08:00
|
|
|
}
|