mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
tests: Avoid transmuting from fn item types.
This commit is contained in:
parent
644d6390be
commit
61a77b38e2
@ -25,16 +25,17 @@
|
|||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
enum Foo {
|
enum Foo {
|
||||||
A = 0,
|
A = 0,
|
||||||
B = 23
|
B = 23
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
extern "C" fn foo(_x: usize) -> Foo { Foo::B }
|
extern "C" fn foo(_x: usize) -> Foo { Foo::B }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let f: extern "C" fn(usize) -> u32 = ::std::mem::transmute(foo);
|
let f: extern "C" fn(usize) -> u32 =
|
||||||
assert_eq!(f(0xDEADBEEF), Foo::B as u32);
|
::std::mem::transmute(foo as extern "C" fn(usize) -> Foo);
|
||||||
}
|
assert_eq!(f(0xDEADBEEF), Foo::B as u32);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,48 +204,41 @@ fn t24() -> fn(u8) -> S {
|
|||||||
C4
|
C4
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
fn main() {
|
||||||
unsafe {
|
assert_eq!(t1()(), regular());
|
||||||
assert_eq!(t1()(), regular());
|
|
||||||
|
|
||||||
assert!(::std::mem::transmute::<_, *mut ()>(t2()) ==
|
assert_eq!(t2() as *mut (), E::U as *mut ());
|
||||||
::std::mem::transmute::<_, *mut ()>(E::U));
|
assert_eq!(t3() as *mut (), S as *mut ());
|
||||||
assert!(::std::mem::transmute::<_, *mut ()>(t3()) ==
|
|
||||||
::std::mem::transmute::<_, *mut ()>(S));
|
|
||||||
|
|
||||||
assert_eq!(t4()(), S::hey());
|
assert_eq!(t4()(), S::hey());
|
||||||
let s = S(42);
|
let s = S(42);
|
||||||
assert_eq!(t5()(&s), <S as X>::hoy(&s));
|
assert_eq!(t5()(&s), <S as X>::hoy(&s));
|
||||||
|
|
||||||
|
|
||||||
assert_eq!(t6()(), ext::regular_fn());
|
assert_eq!(t6()(), ext::regular_fn());
|
||||||
assert!(::std::mem::transmute::<_, *mut ()>(t7()) ==
|
assert_eq!(t7() as *mut (), ext::E::U as *mut ());
|
||||||
::std::mem::transmute::<_, *mut ()>(ext::E::U));
|
assert_eq!(t8() as *mut (), ext::S as *mut ());
|
||||||
assert!(::std::mem::transmute::<_, *mut ()>(t8()) ==
|
|
||||||
::std::mem::transmute::<_, *mut ()>(ext::S));
|
|
||||||
|
|
||||||
assert_eq!(t9()(), ext::S::hey());
|
assert_eq!(t9()(), ext::S::hey());
|
||||||
let sext = ext::S(6);
|
let sext = ext::S(6);
|
||||||
assert_eq!(t10()(&sext), <ext::S as ext::X>::hoy(&sext));
|
assert_eq!(t10()(&sext), <ext::S as ext::X>::hoy(&sext));
|
||||||
|
|
||||||
let p = parametric::<u8>;
|
let p = parametric::<u8>;
|
||||||
assert!(::std::mem::transmute::<_, *mut ()>(t11()) ==
|
assert_eq!(t11() as *mut (), p as *mut ());
|
||||||
::std::mem::transmute::<_, *mut ()>(p));
|
|
||||||
|
|
||||||
assert_eq!(t12(), C);
|
assert_eq!(t12(), C);
|
||||||
assert_eq!(t13(), C2);
|
assert_eq!(t13(), C2);
|
||||||
assert_eq!(t13_2(), C3);
|
assert_eq!(t13_2(), C3);
|
||||||
|
|
||||||
assert_eq!(t14()(), <S as X>::hoy2());
|
assert_eq!(t14()(), <S as X>::hoy2());
|
||||||
assert_eq!(t15()(&s), S::hey2(&s));
|
assert_eq!(t15()(&s), S::hey2(&s));
|
||||||
assert_eq!(t16()(10u32, 20u32), F::f(10u32, 20u32));
|
assert_eq!(t16()(10u32, 20u32), F::f(10u32, 20u32));
|
||||||
assert_eq!(t17()(30u32, 10u64), F::f(30u32, 10u64));
|
assert_eq!(t17()(30u32, 10u64), F::f(30u32, 10u64));
|
||||||
assert_eq!(t18()(50u64, 5u64), F::f(50u64, 5u64));
|
assert_eq!(t18()(50u64, 5u64), F::f(50u64, 5u64));
|
||||||
assert_eq!(t19()(322u64, 2u32), F::f(322u64, 2u32));
|
assert_eq!(t19()(322u64, 2u32), F::f(322u64, 2u32));
|
||||||
assert_eq!(t20()(123u64, 38u32), <u32 as T<_, _>>::staticmeth(123, 38));
|
assert_eq!(t20()(123u64, 38u32), <u32 as T<_, _>>::staticmeth(123, 38));
|
||||||
assert_eq!(t21(), Unit);
|
assert_eq!(t21(), Unit);
|
||||||
assert_eq!(t22(), None);
|
assert_eq!(t22(), None);
|
||||||
assert_eq!(t23(), (CEnum::A, CEnum::B));
|
assert_eq!(t23(), (CEnum::A, CEnum::B));
|
||||||
assert_eq!(t24(), C4);
|
assert_eq!(t24(), C4);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,14 @@
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
#[inline(never)]
|
#[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;
|
static FOO: isize = 0xDEADBEE;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
unsafe {
|
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);
|
assert_eq!(*f(&FOO), FOO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
#![allow(unknown_features)]
|
#![allow(unknown_features)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::{option, mem};
|
|
||||||
|
|
||||||
// Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
|
// 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
|
// which "says that a destructor applied to an object built from a constructor
|
||||||
// behaves as expected". -- http://coq.inria.fr/doc/Reference-Manual006.html
|
// 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));
|
check_option!($e, $T, |ptr| assert_eq!(*ptr, $e));
|
||||||
}};
|
}};
|
||||||
($e:expr, $T:ty, |$v:ident| $chk:expr) => {{
|
($e:expr, $T:ty, |$v:ident| $chk:expr) => {{
|
||||||
assert!(option::Option::None::<$T>.is_none());
|
assert!(None::<$T>.is_none());
|
||||||
let e = $e;
|
let e = $e;
|
||||||
let s_ = option::Option::Some::<$T>(e);
|
let s_ = Some::<$T>(e);
|
||||||
let $v = s_.as_ref().unwrap();
|
let $v = s_.as_ref().unwrap();
|
||||||
$chk
|
$chk
|
||||||
}}
|
}}
|
||||||
@ -78,9 +76,8 @@ pub fn main() {
|
|||||||
check_type!(&17, &isize);
|
check_type!(&17, &isize);
|
||||||
check_type!(box 18, Box<isize>);
|
check_type!(box 18, Box<isize>);
|
||||||
check_type!("foo".to_string(), String);
|
check_type!("foo".to_string(), String);
|
||||||
check_type!(vec!(20, 22), Vec<isize> );
|
check_type!(vec!(20, 22), Vec<isize>);
|
||||||
let mint: usize = unsafe { mem::transmute(main) };
|
|
||||||
check_type!(main, fn(), |pthing| {
|
check_type!(main, fn(), |pthing| {
|
||||||
assert_eq!(mint, unsafe { mem::transmute(*pthing) })
|
assert_eq!(main as fn(), *pthing as fn())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user