rust/tests/ui/newtype.rs

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

24 lines
447 B
Rust
Raw Normal View History

//@ run-pass
#![allow(non_camel_case_types)]
2015-03-30 13:38:27 +00:00
#[derive(Copy, Clone)]
struct mytype(Mytype);
2015-03-30 13:38:27 +00:00
#[derive(Copy, Clone)]
struct Mytype {
compute: fn(mytype) -> isize,
val: isize,
}
fn compute(i: mytype) -> isize {
let mytype(m) = i;
return m.val + 20;
}
2011-07-01 13:55:20 +00:00
pub fn main() {
let myval = mytype(Mytype{compute: compute, val: 30});
println!("{}", compute(myval));
let mytype(m) = myval;
assert_eq!((m.compute)(myval), 50);
}