2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
|
|
|
|
2013-04-22 15:49:21 +00: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 23:36:51 +00:00
|
|
|
// behaves as expected". -- https://coq.inria.fr/doc/language/core/conversion.html#iota-reduction
|
2013-04-22 15:49:21 +00: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.
|
|
|
|
|
2023-12-27 22:11:58 +00:00
|
|
|
enum E<T> { Thing(isize, T), #[allow(dead_code)] Nothing((), ((), ()), [i8; 0]) }
|
2013-04-22 15:49:21 +00:00
|
|
|
impl<T> E<T> {
|
2013-05-03 23:25:04 +00:00
|
|
|
fn is_none(&self) -> bool {
|
2013-04-22 15:49:21 +00:00
|
|
|
match *self {
|
2014-11-06 08:05:53 +00:00
|
|
|
E::Thing(..) => false,
|
|
|
|
E::Nothing(..) => true
|
2013-04-22 15:49:21 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_ref(&self) -> (isize, &T) {
|
2013-04-22 15:49:21 +00:00
|
|
|
match *self {
|
2014-11-06 08:05:53 +00:00
|
|
|
E::Nothing(..) => panic!("E::get_ref(Nothing::<{}>)", stringify!(T)),
|
|
|
|
E::Thing(x, ref y) => (x, y)
|
2013-04-22 15:49:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! check_option {
|
2015-01-05 06:51:03 +00:00
|
|
|
($e:expr, $T:ty) => {{
|
2015-06-07 18:00:38 +00:00
|
|
|
check_option!($e, $T, |ptr| assert_eq!(*ptr, $e));
|
2013-04-22 15:49:21 +00:00
|
|
|
}};
|
2015-01-05 06:51:03 +00:00
|
|
|
($e:expr, $T:ty, |$v:ident| $chk:expr) => {{
|
2016-02-18 13:19:38 +00:00
|
|
|
assert!(None::<$T>.is_none());
|
2013-07-02 19:47:32 +00:00
|
|
|
let e = $e;
|
2016-02-18 13:19:38 +00:00
|
|
|
let s_ = Some::<$T>(e);
|
2014-10-15 06:05:01 +00:00
|
|
|
let $v = s_.as_ref().unwrap();
|
2013-04-22 15:49:21 +00:00
|
|
|
$chk
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! check_fancy {
|
2015-01-05 06:51:03 +00:00
|
|
|
($e:expr, $T:ty) => {{
|
2015-06-07 18:00:38 +00:00
|
|
|
check_fancy!($e, $T, |ptr| assert_eq!(*ptr, $e));
|
2013-04-22 15:49:21 +00:00
|
|
|
}};
|
2015-01-05 06:51:03 +00:00
|
|
|
($e:expr, $T:ty, |$v:ident| $chk:expr) => {{
|
2015-03-03 08:42:26 +00:00
|
|
|
assert!(E::Nothing::<$T>((), ((), ()), [23; 0]).is_none());
|
2013-07-02 19:47:32 +00:00
|
|
|
let e = $e;
|
2014-11-06 08:05:53 +00:00
|
|
|
let t_ = E::Thing::<$T>(23, e);
|
2013-04-22 15:49:21 +00:00
|
|
|
match t_.get_ref() {
|
|
|
|
(23, $v) => { $chk }
|
2014-10-09 19:17:22 +00:00
|
|
|
_ => panic!("Thing::<{}>(23, {}).get_ref() != (23, _)",
|
2013-05-09 11:52:07 +00:00
|
|
|
stringify!($T), stringify!($e))
|
2013-04-22 15:49:21 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! check_type {
|
|
|
|
($($a:tt)*) => {{
|
|
|
|
check_option!($($a)*);
|
|
|
|
check_fancy!($($a)*);
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2015-03-26 00:06:52 +00:00
|
|
|
check_type!(&17, &isize);
|
2021-08-25 00:39:40 +00:00
|
|
|
check_type!(Box::new(18), Box<isize>);
|
2015-01-05 06:51:03 +00:00
|
|
|
check_type!("foo".to_string(), String);
|
2016-10-29 21:54:04 +00:00
|
|
|
check_type!(vec![20, 22], Vec<isize>);
|
2015-01-05 06:51:03 +00:00
|
|
|
check_type!(main, fn(), |pthing| {
|
2016-02-18 13:19:38 +00:00
|
|
|
assert_eq!(main as fn(), *pthing as fn())
|
2013-04-22 15:49:21 +00:00
|
|
|
});
|
|
|
|
}
|