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