os-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
441 B
Rust
Raw Permalink Normal View History

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