]> git.proxmox.com Git - rustc.git/blame - src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / migrations / mir_calls_to_shims.rs
CommitLineData
17df50a5
XL
1// run-rustfix
2
136023e0
XL
3#![deny(rust_2021_incompatible_closure_captures)]
4//~^ NOTE: the lint level is defined here
17df50a5 5// ignore-wasm32-bare compiled with panic=abort by default
17df50a5
XL
6#![feature(fn_traits)]
7#![feature(never_type)]
8
9use std::panic;
10
136023e0
XL
11fn foo_diverges() -> ! {
12 panic!()
13}
17df50a5 14
136023e0
XL
15fn assert_panics<F>(f: F)
16where
17 F: FnOnce(),
18{
17df50a5
XL
19 let f = panic::AssertUnwindSafe(f);
20 let result = panic::catch_unwind(move || {
136023e0
XL
21 //~^ ERROR: `UnwindSafe`, `RefUnwindSafe` trait implementation for closure
22 //~| NOTE: in Rust 2018, this closure would implement `UnwindSafe`, `RefUnwindSafe` as `f` implements `UnwindSafe`, `RefUnwindSafe`, but in Rust 2021, this closure would no longer implement `UnwindSafe`, `RefUnwindSafe` as `f.0` does not implement `UnwindSafe`, `RefUnwindSafe`
23 //~| NOTE: for more information, see
17df50a5
XL
24 //~| HELP: add a dummy let to cause `f` to be fully captured
25 f.0()
136023e0 26 //~^ NOTE: in Rust 2018, closure captures all of `f`, but in Rust 2021, it only captures `f.0`
17df50a5
XL
27 });
28 if let Ok(..) = result {
29 panic!("diverging function returned");
30 }
31}
32
33fn test_fn_ptr_panic<T>(mut t: T)
136023e0
XL
34where
35 T: Fn() -> !,
17df50a5
XL
36{
37 let as_fn = <T as Fn<()>>::call;
38 assert_panics(|| as_fn(&t, ()));
39 let as_fn_mut = <T as FnMut<()>>::call_mut;
40 assert_panics(|| as_fn_mut(&mut t, ()));
41 let as_fn_once = <T as FnOnce<()>>::call_once;
42 assert_panics(|| as_fn_once(t, ()));
43}
44
45fn main() {
46 test_fn_ptr_panic(foo_diverges);
47 test_fn_ptr_panic(foo_diverges as fn() -> !);
48}