3 // xfail'd due to a bug in move detection for macros.
5 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
6 // file at the top-level directory of this distribution and at
7 // http://rust-lang.org/COPYRIGHT.
9 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
10 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
11 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
12 // option. This file may not be copied, modified, or distributed
13 // except according to those terms.
15 use std::{option, cast};
17 // Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
18 // which "says that a destructor applied to an object built from a constructor
19 // behaves as expected". -- http://coq.inria.fr/doc/Reference-Manual006.html
21 // It's a little more complicated here, because of pointers and regions and
22 // trying to get assert failure messages that at least identify which case
25 enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
27 fn is_none(&self) -> bool {
33 fn get_ref<'r>(&'r self) -> (int, &'r T) {
35 Nothing(..) => fail!("E::get_ref(Nothing::<%s>)", stringify!($T)),
36 Thing(x, ref y) => (x, y)
41 macro_rules! check_option {
42 ($e:expr: $T:ty) => {{
43 check_option!($e: $T, |ptr| assert!(*ptr == $e));
45 ($e:expr: $T:ty, |$v:ident| $chk:expr) => {{
46 assert!(option::None::<$T>.is_none());
48 let s_ = option::Some::<$T>(e);
49 let $v = s_.get_ref();
54 macro_rules! check_fancy {
55 ($e:expr: $T:ty) => {{
56 check_fancy!($e: $T, |ptr| assert!(*ptr == $e));
58 ($e:expr: $T:ty, |$v:ident| $chk:expr) => {{
59 assert!(Nothing::<$T>((), ((), ()), [23i8, ..0]).is_none());
61 let t_ = Thing::<$T>(23, e);
64 _ => fail!("Thing::<%s>(23, %s).get_ref() != (23, _)",
65 stringify!($T), stringify!($e))
70 macro_rules! check_type {
72 check_option!($($a)*);
78 check_type!(&17: &int);
79 check_type!(~18: ~int);
80 check_type!(@19: @int);
81 check_type!(~"foo": ~str);
82 check_type!(~[20, 22]: ~[int]);
83 check_type!(@[]: @[int]);
84 check_type!(@[24, 26]: @[int]);
85 let mint: uint = unsafe { cast::transmute(main) };
86 check_type!(main: extern fn(), |pthing| {
87 assert!(mint == unsafe { cast::transmute(*pthing) })