tests: Avoid transmuting from fn item types.

This commit is contained in:
Eduard Burtescu 2016-02-18 15:19:38 +02:00
parent 644d6390be
commit 61a77b38e2
4 changed files with 43 additions and 51 deletions

View File

@ -34,7 +34,8 @@ extern "C" fn foo(_x: usize) -> Foo { Foo::B }
pub fn main() {
unsafe {
let f: extern "C" fn(usize) -> u32 = ::std::mem::transmute(foo);
let f: extern "C" fn(usize) -> u32 =
::std::mem::transmute(foo as extern "C" fn(usize) -> Foo);
assert_eq!(f(0xDEADBEEF), Foo::B as u32);
}
}

View File

@ -205,13 +205,10 @@ fn t24() -> fn(u8) -> S {
}
fn main() {
unsafe {
assert_eq!(t1()(), regular());
assert!(::std::mem::transmute::<_, *mut ()>(t2()) ==
::std::mem::transmute::<_, *mut ()>(E::U));
assert!(::std::mem::transmute::<_, *mut ()>(t3()) ==
::std::mem::transmute::<_, *mut ()>(S));
assert_eq!(t2() as *mut (), E::U as *mut ());
assert_eq!(t3() as *mut (), S as *mut ());
assert_eq!(t4()(), S::hey());
let s = S(42);
@ -219,18 +216,15 @@ fn main(){
assert_eq!(t6()(), ext::regular_fn());
assert!(::std::mem::transmute::<_, *mut ()>(t7()) ==
::std::mem::transmute::<_, *mut ()>(ext::E::U));
assert!(::std::mem::transmute::<_, *mut ()>(t8()) ==
::std::mem::transmute::<_, *mut ()>(ext::S));
assert_eq!(t7() as *mut (), ext::E::U as *mut ());
assert_eq!(t8() as *mut (), ext::S as *mut ());
assert_eq!(t9()(), ext::S::hey());
let sext = ext::S(6);
assert_eq!(t10()(&sext), <ext::S as ext::X>::hoy(&sext));
let p = parametric::<u8>;
assert!(::std::mem::transmute::<_, *mut ()>(t11()) ==
::std::mem::transmute::<_, *mut ()>(p));
assert_eq!(t11() as *mut (), p as *mut ());
assert_eq!(t12(), C);
assert_eq!(t13(), C2);
@ -248,4 +242,3 @@ fn main(){
assert_eq!(t23(), (CEnum::A, CEnum::B));
assert_eq!(t24(), C4);
}
}

View File

@ -24,13 +24,14 @@
use std::mem;
#[inline(never)]
extern "C" fn foo<'a>(x: &'a isize) -> Option<&'a isize> { Some(x) }
extern "C" fn foo(x: &isize) -> Option<&isize> { Some(x) }
static FOO: isize = 0xDEADBEE;
pub fn main() {
unsafe {
let f: for<'a> extern "C" fn(&'a isize) -> &'a isize = mem::transmute(foo);
let f: extern "C" fn(&isize) -> &isize =
mem::transmute(foo as extern "C" fn(&isize) -> Option<&isize>);
assert_eq!(*f(&FOO), FOO);
}
}

View File

@ -12,8 +12,6 @@
#![allow(unknown_features)]
#![feature(box_syntax)]
use std::{option, mem};
// 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
// behaves as expected". -- http://coq.inria.fr/doc/Reference-Manual006.html
@ -43,9 +41,9 @@ macro_rules! check_option {
check_option!($e, $T, |ptr| assert_eq!(*ptr, $e));
}};
($e:expr, $T:ty, |$v:ident| $chk:expr) => {{
assert!(option::Option::None::<$T>.is_none());
assert!(None::<$T>.is_none());
let e = $e;
let s_ = option::Option::Some::<$T>(e);
let s_ = Some::<$T>(e);
let $v = s_.as_ref().unwrap();
$chk
}}
@ -79,8 +77,7 @@ pub fn main() {
check_type!(box 18, Box<isize>);
check_type!("foo".to_string(), String);
check_type!(vec!(20, 22), Vec<isize>);
let mint: usize = unsafe { mem::transmute(main) };
check_type!(main, fn(), |pthing| {
assert_eq!(mint, unsafe { mem::transmute(*pthing) })
assert_eq!(main as fn(), *pthing as fn())
});
}