From 2a3e4c547b35c44461bc8c3c2dcf4b99c3bafd63 Mon Sep 17 00:00:00 2001
From: Oneirical <manchot@videotron.ca>
Date: Mon, 22 Jul 2024 11:55:20 -0400
Subject: [PATCH] rewrite foreign-rust-exceptions to rmake

---
 .../tidy/src/allowed_run_make_makefiles.txt   |  1 -
 .../run-make/foreign-rust-exceptions/Makefile | 13 -----------
 .../run-make/foreign-rust-exceptions/rmake.rs | 23 +++++++++++++++++++
 3 files changed, 23 insertions(+), 14 deletions(-)
 delete mode 100644 tests/run-make/foreign-rust-exceptions/Makefile
 create mode 100644 tests/run-make/foreign-rust-exceptions/rmake.rs

diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 469bec31e47..e35b69449ac 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -14,7 +14,6 @@ run-make/extern-fn-reachable/Makefile
 run-make/fmt-write-bloat/Makefile
 run-make/foreign-double-unwind/Makefile
 run-make/foreign-exceptions/Makefile
-run-make/foreign-rust-exceptions/Makefile
 run-make/incr-add-rust-src-component/Makefile
 run-make/issue-35164/Makefile
 run-make/issue-36710/Makefile
diff --git a/tests/run-make/foreign-rust-exceptions/Makefile b/tests/run-make/foreign-rust-exceptions/Makefile
deleted file mode 100644
index 59cee284200..00000000000
--- a/tests/run-make/foreign-rust-exceptions/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-# ignore-cross-compile
-# ignore-i686-pc-windows-gnu
-# needs-unwind
-
-# This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder
-# so cross-DLL unwinding does not work.
-
-include ../tools.mk
-
-all:
-	$(RUSTC) bar.rs --crate-type=cdylib
-	$(RUSTC) foo.rs
-	$(call RUN,foo) 2>&1 | $(CGREP) "Rust cannot catch foreign exceptions"
diff --git a/tests/run-make/foreign-rust-exceptions/rmake.rs b/tests/run-make/foreign-rust-exceptions/rmake.rs
new file mode 100644
index 00000000000..06f7a07c62d
--- /dev/null
+++ b/tests/run-make/foreign-rust-exceptions/rmake.rs
@@ -0,0 +1,23 @@
+// Rust exceptions can be foreign (from C code, in this test) or local. Foreign
+// exceptions should not be caught, as that can cause undefined behaviour. Instead
+// of catching them, #102721 made it so that the binary panics in execution with a helpful message.
+// This test checks that the correct message appears and that execution fails when trying to catch
+// a foreign exception.
+// See https://github.com/rust-lang/rust/issues/102715
+
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+//@ needs-unwind
+// Reason: unwinding panics is exercised in this test
+
+//FIXME(Oneirical): ignore-i686-pc-windows-gnu
+// This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder
+// so cross-DLL unwinding does not work.
+
+use run_make_support::{run_fail, rustc};
+
+fn main() {
+    rustc().input("bar.rs").crate_type("cdylib").run();
+    rustc().input("foo.rs").run();
+    run_fail("foo").assert_stderr_contains("Rust cannot catch foreign exceptions");
+}