From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../migrations/mir_calls_to_shims.fixed | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed (limited to 'src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed') diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed new file mode 100644 index 000000000..89f393141 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed @@ -0,0 +1,51 @@ +// run-rustfix +// needs-unwind + +#![deny(rust_2021_incompatible_closure_captures)] +//~^ NOTE: the lint level is defined here +// ignore-wasm32-bare compiled with panic=abort by default +#![feature(fn_traits)] +#![feature(never_type)] + +use std::panic; + +fn foo_diverges() -> ! { + panic!() +} + +fn assert_panics(f: F) +where + F: FnOnce(), +{ + let f = panic::AssertUnwindSafe(f); + let result = panic::catch_unwind(move || { + let _ = &f; + //~^ 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(mut t: T) +where + T: Fn() -> !, +{ + let as_fn = >::call; + assert_panics(|| as_fn(&t, ())); + let as_fn_mut = >::call_mut; + assert_panics(|| as_fn_mut(&mut t, ())); + let as_fn_once = >::call_once; + assert_panics(|| as_fn_once(t, ())); +} + +fn main() { + test_fn_ptr_panic(foo_diverges); + test_fn_ptr_panic(foo_diverges as fn() -> !); +} -- cgit v1.2.3