about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2023-08-07 15:42:24 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2023-08-07 15:42:24 +0200
commit409d9946cdda6383dbfbabca696ab60f4f7a6dab (patch)
tree4d303b9f4d81c6f073668cd2e95dd59c77dde717
parentd8fb568cf4889ec830e8b092cddc24b7d1c29a34 (diff)
downloadrust-409d9946cdda6383dbfbabca696ab60f4f7a6dab.tar.gz
rust-409d9946cdda6383dbfbabca696ab60f4f7a6dab.zip
change test to use `if black_box(false)`
-rw-r--r--tests/ui/panic-handler/weak-lang-item-2.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/tests/ui/panic-handler/weak-lang-item-2.rs b/tests/ui/panic-handler/weak-lang-item-2.rs
index 6d6e8e04b05..2cc5f23b45e 100644
--- a/tests/ui/panic-handler/weak-lang-item-2.rs
+++ b/tests/ui/panic-handler/weak-lang-item-2.rs
@@ -1,23 +1,15 @@
 // run-pass
 // aux-build:weak-lang-items.rs
 
-// ignore-emscripten no threads support
 // pretty-expanded FIXME #23616
 
 extern crate weak_lang_items as other;
 
 fn main() {
-    let _ = std::thread::spawn(move || {
-        // The goal of the test is just to make sure other::foo() is called. Since the function
-        // panics, it's executed in its own thread. That way, the panic is isolated within the
-        // thread and wont't affect the overall exit code.
-        //
-        // That causes a spurious failures in panic=abort targets though: if the program exits
-        // before the thread is fully initialized the test will pass, but if the thread gets
-        // executed first the whole program will abort. Adding a 60 seconds sleep will (hopefully!)
-        // ensure the program always exits before the thread is executed.
-        std::thread::sleep(std::time::Duration::from_secs(60));
-
-        other::foo()
-    });
+    // The goal of the test is just to make sure other::foo() is referenced at link time. Since
+    // the function panics, to prevent it from running we gate it behind an always-false `if` that
+    // is not going to be optimized away.
+    if std::hint::black_box(false) {
+        other::foo();
+    }
 }