rust/tests/ui/borrowck/borrowck-univariant-enum.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
440 B
Rust
Raw Normal View History

// run-pass
#![allow(non_camel_case_types)]
2013-12-31 23:46:27 +00:00
use std::cell::Cell;
2015-03-30 13:38:27 +00:00
#[derive(Copy, Clone)]
enum newtype {
newvar(isize)
}
pub fn main() {
// Test that borrowck treats enums with a single variant
// specially.
2014-10-02 05:10:09 +00:00
let x = &Cell::new(5);
let y = &Cell::new(newtype::newvar(3));
2013-12-31 23:46:27 +00:00
let z = match y.get() {
newtype::newvar(b) => {
2013-12-31 23:46:27 +00:00
x.set(x.get() + 1);
x.get() * b
}
};
assert_eq!(z, 18);
}