1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(macro_rules)]
13 use std::{option, cast};
15 // Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
16 // which "says that a destructor applied to an object built from a constructor
17 // behaves as expected". -- http://coq.inria.fr/doc/Reference-Manual006.html
19 // It's a little more complicated here, because of pointers and regions and
20 // trying to get assert failure messages that at least identify which case
23 enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
25 fn is_none(&self) -> bool {
31 fn get_ref<'r>(&'r self) -> (int, &'r T) {
33 Nothing(..) => fail!("E::get_ref(Nothing::<{}>)", stringify!(T)),
34 Thing(x, ref y) => (x, y)
39 macro_rules! check_option {
40 ($e:expr: $T:ty) => {{
41 check_option!($e: $T, |ptr| assert!(*ptr == $e));
43 ($e:expr: $T:ty, |$v:ident| $chk:expr) => {{
44 assert!(option::None::<$T>.is_none());
46 let s_ = option::Some::<$T>(e);
47 let $v = s_.get_ref();
52 macro_rules! check_fancy {
53 ($e:expr: $T:ty) => {{
54 check_fancy!($e: $T, |ptr| assert!(*ptr == $e));
56 ($e:expr: $T:ty, |$v:ident| $chk:expr) => {{
57 assert!(Nothing::<$T>((), ((), ()), [23i8, ..0]).is_none());
59 let t_ = Thing::<$T>(23, e);
62 _ => fail!("Thing::<{}>(23, {}).get_ref() != (23, _)",
63 stringify!($T), stringify!($e))
68 macro_rules! check_type {
70 check_option!($($a)*);
76 check_type!(&17: &int);
77 check_type!(box 18: Box<int>);
78 check_type!(@19: @int);
79 check_type!("foo".to_owned(): ~str);
80 check_type!(vec!(20, 22): Vec<int> );
81 let mint: uint = unsafe { cast::transmute(main) };
82 check_type!(main: fn(), |pthing| {
83 assert!(mint == unsafe { cast::transmute(*pthing) })