summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs')
-rw-r--r--tests/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs b/tests/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
new file mode 100644
index 000000000..52e96d013
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
@@ -0,0 +1,49 @@
+// run-rustfix
+// needs-unwind
+
+#![deny(rust_2021_incompatible_closure_captures)]
+//~^ NOTE: the lint level is defined here
+#![feature(fn_traits)]
+#![feature(never_type)]
+
+use std::panic;
+
+fn foo_diverges() -> ! {
+ panic!()
+}
+
+fn assert_panics<F>(f: F)
+where
+ F: FnOnce(),
+{
+ let f = panic::AssertUnwindSafe(f);
+ let result = panic::catch_unwind(move || {
+ //~^ ERROR: changes to closure capture in Rust 2021 will affect which traits the closure implements [rust_2021_incompatible_closure_captures]
+ //~| NOTE: in Rust 2018, this closure implements `UnwindSafe`
+ //~| NOTE: in Rust 2018, this closure implements `RefUnwindSafe`
+ //~| NOTE: for more information, see
+ //~| HELP: add a dummy let to cause `f` to be fully captured
+ f.0()
+ //~^ NOTE: in Rust 2018, this closure captures all of `f`, but in Rust 2021, it will only capture `f.0`
+ });
+ if let Ok(..) = result {
+ panic!("diverging function returned");
+ }
+}
+
+fn test_fn_ptr_panic<T>(mut t: T)
+where
+ T: Fn() -> !,
+{
+ let as_fn = <T as Fn<()>>::call;
+ assert_panics(|| as_fn(&t, ()));
+ let as_fn_mut = <T as FnMut<()>>::call_mut;
+ assert_panics(|| as_fn_mut(&mut t, ()));
+ let as_fn_once = <T as FnOnce<()>>::call_once;
+ assert_panics(|| as_fn_once(t, ()));
+}
+
+fn main() {
+ test_fn_ptr_panic(foo_diverges);
+ test_fn_ptr_panic(foo_diverges as fn() -> !);
+}