]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/mir/mir_calls_to_shims.rs
2 // ignore-wasm32-bare compiled with panic=abort by default
5 #![feature(never_type)]
9 fn foo(x
: u32, y
: u32) -> u32 { x/y }
10 fn foo_diverges() -> ! { panic!() }
12 fn test_fn_ptr
<T
>(mut t
: T
)
13 where T
: Fn(u32, u32) -> u32,
15 let as_fn
= <T
as Fn
<(u32, u32)>>::call
;
16 assert_eq
!(as_fn(&t
, (9, 3)), 3);
17 let as_fn_mut
= <T
as FnMut
<(u32, u32)>>::call_mut
;
18 assert_eq
!(as_fn_mut(&mut t
, (18, 3)), 6);
19 let as_fn_once
= <T
as FnOnce
<(u32, u32)>>::call_once
;
20 assert_eq
!(as_fn_once(t
, (24, 3)), 8);
23 fn assert_panics
<F
>(f
: F
) where F
: FnOnce() {
24 let f
= panic
::AssertUnwindSafe(f
);
25 let result
= panic
::catch_unwind(move || {
28 if let Ok(..) = result
{
29 panic
!("diverging function returned");
33 fn test_fn_ptr_panic
<T
>(mut t
: T
)
36 let as_fn
= <T
as Fn
<()>>::call
;
37 assert_panics(|| as_fn(&t
, ()));
38 let as_fn_mut
= <T
as FnMut
<()>>::call_mut
;
39 assert_panics(|| as_fn_mut(&mut t
, ()));
40 let as_fn_once
= <T
as FnOnce
<()>>::call_once
;
41 assert_panics(|| as_fn_once(t
, ()));
46 test_fn_ptr(foo
as fn(u32, u32) -> u32);
47 test_fn_ptr_panic(foo_diverges
);
48 test_fn_ptr_panic(foo_diverges
as fn() -> !);