]> git.lizzy.rs Git - rust.git/blob - src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
rustdoc: Remove unused Clean impls
[rust.git] / src / test / ui / closures / 2229_closure_analysis / migrations / mir_calls_to_shims.rs
1 // run-rustfix
2
3 #![deny(disjoint_capture_migration)]
4 // ignore-wasm32-bare compiled with panic=abort by default
5
6 #![feature(fn_traits)]
7 #![feature(never_type)]
8
9 use std::panic;
10
11 fn foo_diverges() -> ! { panic!() }
12
13 fn assert_panics<F>(f: F) where F: FnOnce() {
14     let f = panic::AssertUnwindSafe(f);
15     let result = panic::catch_unwind(move || {
16         //~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation
17         //~| HELP: add a dummy let to cause `f` to be fully captured
18         f.0()
19     });
20     if let Ok(..) = result {
21         panic!("diverging function returned");
22     }
23 }
24
25 fn test_fn_ptr_panic<T>(mut t: T)
26     where T: Fn() -> !
27 {
28     let as_fn = <T as Fn<()>>::call;
29     assert_panics(|| as_fn(&t, ()));
30     let as_fn_mut = <T as FnMut<()>>::call_mut;
31     assert_panics(|| as_fn_mut(&mut t, ()));
32     let as_fn_once = <T as FnOnce<()>>::call_once;
33     assert_panics(|| as_fn_once(t, ()));
34 }
35
36 fn main() {
37     test_fn_ptr_panic(foo_diverges);
38     test_fn_ptr_panic(foo_diverges as fn() -> !);
39 }