2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2013-04-22 10:49:21 -05:00
|
|
|
// Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
|
|
|
|
// which "says that a destructor applied to an object built from a constructor
|
2021-06-23 18:36:51 -05:00
|
|
|
// behaves as expected". -- https://coq.inria.fr/doc/language/core/conversion.html#iota-reduction
|
2013-04-22 10:49:21 -05:00
|
|
|
//
|
|
|
|
// It's a little more complicated here, because of pointers and regions and
|
|
|
|
// trying to get assert failure messages that at least identify which case
|
|
|
|
// failed.
|
|
|
|
|
2022-07-25 15:36:03 -05:00
|
|
|
enum E<T> { Thing(isize, T), #[allow(unused_tuple_struct_fields)] Nothing((), ((), ()), [i8; 0]) }
|
2013-04-22 10:49:21 -05:00
|
|
|
impl<T> E<T> {
|
2013-05-03 18:25:04 -05:00
|
|
|
fn is_none(&self) -> bool {
|
2013-04-22 10:49:21 -05:00
|
|
|
match *self {
|
2014-11-06 02:05:53 -06:00
|
|
|
E::Thing(..) => false,
|
|
|
|
E::Nothing(..) => true
|
2013-04-22 10:49:21 -05:00
|
|
|
}
|
|
|
|
}
|
2015-03-25 19:06:52 -05:00
|
|
|
fn get_ref(&self) -> (isize, &T) {
|
2013-04-22 10:49:21 -05:00
|
|
|
match *self {
|
2014-11-06 02:05:53 -06:00
|
|
|
E::Nothing(..) => panic!("E::get_ref(Nothing::<{}>)", stringify!(T)),
|
|
|
|
E::Thing(x, ref y) => (x, y)
|
2013-04-22 10:49:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! check_option {
|
2015-01-05 00:51:03 -06:00
|
|
|
($e:expr, $T:ty) => {{
|
2015-06-07 13:00:38 -05:00
|
|
|
check_option!($e, $T, |ptr| assert_eq!(*ptr, $e));
|
2013-04-22 10:49:21 -05:00
|
|
|
}};
|
2015-01-05 00:51:03 -06:00
|
|
|
($e:expr, $T:ty, |$v:ident| $chk:expr) => {{
|
2016-02-18 07:19:38 -06:00
|
|
|
assert!(None::<$T>.is_none());
|
2013-07-02 14:47:32 -05:00
|
|
|
let e = $e;
|
2016-02-18 07:19:38 -06:00
|
|
|
let s_ = Some::<$T>(e);
|
2014-10-15 01:05:01 -05:00
|
|
|
let $v = s_.as_ref().unwrap();
|
2013-04-22 10:49:21 -05:00
|
|
|
$chk
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! check_fancy {
|
2015-01-05 00:51:03 -06:00
|
|
|
($e:expr, $T:ty) => {{
|
2015-06-07 13:00:38 -05:00
|
|
|
check_fancy!($e, $T, |ptr| assert_eq!(*ptr, $e));
|
2013-04-22 10:49:21 -05:00
|
|
|
}};
|
2015-01-05 00:51:03 -06:00
|
|
|
($e:expr, $T:ty, |$v:ident| $chk:expr) => {{
|
2015-03-03 02:42:26 -06:00
|
|
|
assert!(E::Nothing::<$T>((), ((), ()), [23; 0]).is_none());
|
2013-07-02 14:47:32 -05:00
|
|
|
let e = $e;
|
2014-11-06 02:05:53 -06:00
|
|
|
let t_ = E::Thing::<$T>(23, e);
|
2013-04-22 10:49:21 -05:00
|
|
|
match t_.get_ref() {
|
|
|
|
(23, $v) => { $chk }
|
2014-10-09 14:17:22 -05:00
|
|
|
_ => panic!("Thing::<{}>(23, {}).get_ref() != (23, _)",
|
2013-05-09 06:52:07 -05:00
|
|
|
stringify!($T), stringify!($e))
|
2013-04-22 10:49:21 -05:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! check_type {
|
|
|
|
($($a:tt)*) => {{
|
|
|
|
check_option!($($a)*);
|
|
|
|
check_fancy!($($a)*);
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2015-03-25 19:06:52 -05:00
|
|
|
check_type!(&17, &isize);
|
2021-08-24 19:39:40 -05:00
|
|
|
check_type!(Box::new(18), Box<isize>);
|
2015-01-05 00:51:03 -06:00
|
|
|
check_type!("foo".to_string(), String);
|
2016-10-29 16:54:04 -05:00
|
|
|
check_type!(vec![20, 22], Vec<isize>);
|
2015-01-05 00:51:03 -06:00
|
|
|
check_type!(main, fn(), |pthing| {
|
2016-02-18 07:19:38 -06:00
|
|
|
assert_eq!(main as fn(), *pthing as fn())
|
2013-04-22 10:49:21 -05:00
|
|
|
});
|
|
|
|
}
|