summaryrefslogtreecommitdiffstats
path: root/tests/ui/panic-handler
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/panic-handler
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/panic-handler')
-rw-r--r--tests/ui/panic-handler/auxiliary/some-panic-impl.rs11
-rw-r--r--tests/ui/panic-handler/auxiliary/weak-lang-items.rs22
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-1.rs13
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-1.stderr14
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-2.rs14
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-2.stderr8
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-3.rs11
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-3.stderr8
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-4.rs12
-rw-r--r--tests/ui/panic-handler/panic-handler-bad-signature-4.stderr8
-rw-r--r--tests/ui/panic-handler/panic-handler-duplicate.rs17
-rw-r--r--tests/ui/panic-handler/panic-handler-duplicate.stderr15
-rw-r--r--tests/ui/panic-handler/panic-handler-missing.rs9
-rw-r--r--tests/ui/panic-handler/panic-handler-requires-panic-info.rs15
-rw-r--r--tests/ui/panic-handler/panic-handler-requires-panic-info.stderr4
-rw-r--r--tests/ui/panic-handler/panic-handler-std.rs12
-rw-r--r--tests/ui/panic-handler/panic-handler-std.stderr13
-rw-r--r--tests/ui/panic-handler/panic-handler-twice.rs19
-rw-r--r--tests/ui/panic-handler/panic-handler-wrong-location.rs8
-rw-r--r--tests/ui/panic-handler/panic-handler-wrong-location.stderr11
-rw-r--r--tests/ui/panic-handler/weak-lang-item-2.rs15
-rw-r--r--tests/ui/panic-handler/weak-lang-item.rs12
-rw-r--r--tests/ui/panic-handler/weak-lang-item.stderr22
23 files changed, 293 insertions, 0 deletions
diff --git a/tests/ui/panic-handler/auxiliary/some-panic-impl.rs b/tests/ui/panic-handler/auxiliary/some-panic-impl.rs
new file mode 100644
index 000000000..0348b3a2d
--- /dev/null
+++ b/tests/ui/panic-handler/auxiliary/some-panic-impl.rs
@@ -0,0 +1,11 @@
+// no-prefer-dynamic
+
+#![crate_type = "rlib"]
+#![no_std]
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic(info: &PanicInfo) -> ! {
+ loop {}
+}
diff --git a/tests/ui/panic-handler/auxiliary/weak-lang-items.rs b/tests/ui/panic-handler/auxiliary/weak-lang-items.rs
new file mode 100644
index 000000000..7a698cf76
--- /dev/null
+++ b/tests/ui/panic-handler/auxiliary/weak-lang-items.rs
@@ -0,0 +1,22 @@
+// no-prefer-dynamic
+
+// This aux-file will require the eh_personality function to be codegen'd, but
+// it hasn't been defined just yet. Make sure we don't explode.
+
+#![no_std]
+#![crate_type = "rlib"]
+
+struct A;
+
+impl core::ops::Drop for A {
+ fn drop(&mut self) {}
+}
+
+pub fn foo() {
+ let _a = A;
+ panic!("wut");
+}
+
+mod std {
+ pub use core::{option, fmt};
+}
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-1.rs b/tests/ui/panic-handler/panic-handler-bad-signature-1.rs
new file mode 100644
index 000000000..775961d3f
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-1.rs
@@ -0,0 +1,13 @@
+// compile-flags:-C panic=abort
+
+#![no_std]
+#![no_main]
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic(
+ info: PanicInfo, //~ ERROR argument should be `&PanicInfo`
+) -> () //~ ERROR return type should be `!`
+{
+}
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-1.stderr b/tests/ui/panic-handler/panic-handler-bad-signature-1.stderr
new file mode 100644
index 000000000..8b044f766
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-1.stderr
@@ -0,0 +1,14 @@
+error: return type should be `!`
+ --> $DIR/panic-handler-bad-signature-1.rs:11:6
+ |
+LL | ) -> ()
+ | ^^
+
+error: argument should be `&PanicInfo`
+ --> $DIR/panic-handler-bad-signature-1.rs:10:11
+ |
+LL | info: PanicInfo,
+ | ^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-2.rs b/tests/ui/panic-handler/panic-handler-bad-signature-2.rs
new file mode 100644
index 000000000..727934000
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-2.rs
@@ -0,0 +1,14 @@
+// compile-flags:-C panic=abort
+
+#![no_std]
+#![no_main]
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic(
+ info: &'static PanicInfo, //~ ERROR argument should be `&PanicInfo`
+) -> !
+{
+ loop {}
+}
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-2.stderr b/tests/ui/panic-handler/panic-handler-bad-signature-2.stderr
new file mode 100644
index 000000000..5ab693420
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-2.stderr
@@ -0,0 +1,8 @@
+error: argument should be `&PanicInfo`
+ --> $DIR/panic-handler-bad-signature-2.rs:10:11
+ |
+LL | info: &'static PanicInfo,
+ | ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-3.rs b/tests/ui/panic-handler/panic-handler-bad-signature-3.rs
new file mode 100644
index 000000000..ab9c9d7f4
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-3.rs
@@ -0,0 +1,11 @@
+// compile-flags:-C panic=abort
+
+#![no_std]
+#![no_main]
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic() -> ! { //~ ERROR function should have one argument
+ loop {}
+}
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-3.stderr b/tests/ui/panic-handler/panic-handler-bad-signature-3.stderr
new file mode 100644
index 000000000..0a70181fd
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-3.stderr
@@ -0,0 +1,8 @@
+error: function should have one argument
+ --> $DIR/panic-handler-bad-signature-3.rs:9:1
+ |
+LL | fn panic() -> ! {
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-4.rs b/tests/ui/panic-handler/panic-handler-bad-signature-4.rs
new file mode 100644
index 000000000..8240ab083
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-4.rs
@@ -0,0 +1,12 @@
+// compile-flags:-C panic=abort
+
+#![no_std]
+#![no_main]
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic<T>(pi: &PanicInfo) -> ! {
+ //~^ ERROR should have no type parameters
+ loop {}
+}
diff --git a/tests/ui/panic-handler/panic-handler-bad-signature-4.stderr b/tests/ui/panic-handler/panic-handler-bad-signature-4.stderr
new file mode 100644
index 000000000..5e46da121
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-bad-signature-4.stderr
@@ -0,0 +1,8 @@
+error: should have no type parameters
+ --> $DIR/panic-handler-bad-signature-4.rs:9:1
+ |
+LL | fn panic<T>(pi: &PanicInfo) -> ! {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/panic-handler/panic-handler-duplicate.rs b/tests/ui/panic-handler/panic-handler-duplicate.rs
new file mode 100644
index 000000000..bd99af999
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-duplicate.rs
@@ -0,0 +1,17 @@
+// compile-flags:-C panic=abort
+
+#![feature(lang_items)]
+#![no_std]
+#![no_main]
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic(info: &PanicInfo) -> ! {
+ loop {}
+}
+
+#[lang = "panic_impl"]
+fn panic2(info: &PanicInfo) -> ! { //~ ERROR found duplicate lang item `panic_impl`
+ loop {}
+}
diff --git a/tests/ui/panic-handler/panic-handler-duplicate.stderr b/tests/ui/panic-handler/panic-handler-duplicate.stderr
new file mode 100644
index 000000000..8cdc4888d
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-duplicate.stderr
@@ -0,0 +1,15 @@
+error[E0152]: found duplicate lang item `panic_impl`
+ --> $DIR/panic-handler-duplicate.rs:15:1
+ |
+LL | fn panic2(info: &PanicInfo) -> ! {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: the lang item is first defined here
+ --> $DIR/panic-handler-duplicate.rs:10:1
+ |
+LL | fn panic(info: &PanicInfo) -> ! {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0152`.
diff --git a/tests/ui/panic-handler/panic-handler-missing.rs b/tests/ui/panic-handler/panic-handler-missing.rs
new file mode 100644
index 000000000..6bb062ba6
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-missing.rs
@@ -0,0 +1,9 @@
+// dont-check-compiler-stderr
+// error-pattern: `#[panic_handler]` function required, but not found
+
+#![feature(lang_items)]
+#![no_main]
+#![no_std]
+
+#[lang = "eh_personality"]
+fn eh() {}
diff --git a/tests/ui/panic-handler/panic-handler-requires-panic-info.rs b/tests/ui/panic-handler/panic-handler-requires-panic-info.rs
new file mode 100644
index 000000000..f13c12fc5
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-requires-panic-info.rs
@@ -0,0 +1,15 @@
+// compile-flags:-C panic=abort
+// error-pattern: language item required, but not found: `panic_info`
+
+#![feature(lang_items)]
+#![feature(no_core)]
+#![no_core]
+#![no_main]
+
+#[panic_handler]
+fn panic() -> ! {
+ loop {}
+}
+
+#[lang = "sized"]
+trait Sized {}
diff --git a/tests/ui/panic-handler/panic-handler-requires-panic-info.stderr b/tests/ui/panic-handler/panic-handler-requires-panic-info.stderr
new file mode 100644
index 000000000..2bae12efb
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-requires-panic-info.stderr
@@ -0,0 +1,4 @@
+error: language item required, but not found: `panic_info`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/panic-handler/panic-handler-std.rs b/tests/ui/panic-handler/panic-handler-std.rs
new file mode 100644
index 000000000..6183c886c
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-std.rs
@@ -0,0 +1,12 @@
+// normalize-stderr-test "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
+// error-pattern: found duplicate lang item `panic_impl`
+
+
+use std::panic::PanicInfo;
+
+#[panic_handler]
+fn panic(info: PanicInfo) -> ! {
+ loop {}
+}
+
+fn main() {}
diff --git a/tests/ui/panic-handler/panic-handler-std.stderr b/tests/ui/panic-handler/panic-handler-std.stderr
new file mode 100644
index 000000000..7c7feffe7
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-std.stderr
@@ -0,0 +1,13 @@
+error[E0152]: found duplicate lang item `panic_impl`
+ --> $DIR/panic-handler-std.rs:8:1
+ |
+LL | fn panic(info: PanicInfo) -> ! {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
+ = note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
+ = note: second definition in the local crate (`panic_handler_std`)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0152`.
diff --git a/tests/ui/panic-handler/panic-handler-twice.rs b/tests/ui/panic-handler/panic-handler-twice.rs
new file mode 100644
index 000000000..05bef66d8
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-twice.rs
@@ -0,0 +1,19 @@
+// dont-check-compiler-stderr
+// aux-build:some-panic-impl.rs
+
+#![feature(lang_items)]
+#![no_std]
+#![no_main]
+
+extern crate some_panic_impl;
+
+use core::panic::PanicInfo;
+
+#[panic_handler]
+fn panic(info: &PanicInfo) -> ! {
+ //~^ ERROR found duplicate lang item `panic_impl`
+ loop {}
+}
+
+#[lang = "eh_personality"]
+fn eh() {}
diff --git a/tests/ui/panic-handler/panic-handler-wrong-location.rs b/tests/ui/panic-handler/panic-handler-wrong-location.rs
new file mode 100644
index 000000000..dca591018
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-wrong-location.rs
@@ -0,0 +1,8 @@
+// compile-flags:-C panic=abort
+
+#![no_std]
+#![no_main]
+
+#[panic_handler] //~ ERROR `panic_impl` language item must be applied to a function
+#[no_mangle]
+static X: u32 = 42;
diff --git a/tests/ui/panic-handler/panic-handler-wrong-location.stderr b/tests/ui/panic-handler/panic-handler-wrong-location.stderr
new file mode 100644
index 000000000..ae3ed5ab1
--- /dev/null
+++ b/tests/ui/panic-handler/panic-handler-wrong-location.stderr
@@ -0,0 +1,11 @@
+error[E0718]: `panic_impl` language item must be applied to a function
+ --> $DIR/panic-handler-wrong-location.rs:6:1
+ |
+LL | #[panic_handler]
+ | ^^^^^^^^^^^^^^^^ attribute should be applied to a function, not a static item
+
+error: `#[panic_handler]` function required, but not found
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0718`.
diff --git a/tests/ui/panic-handler/weak-lang-item-2.rs b/tests/ui/panic-handler/weak-lang-item-2.rs
new file mode 100644
index 000000000..a429d8fab
--- /dev/null
+++ b/tests/ui/panic-handler/weak-lang-item-2.rs
@@ -0,0 +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;
+
+use std::thread;
+
+fn main() {
+ let _ = thread::spawn(move|| {
+ other::foo()
+ });
+}
diff --git a/tests/ui/panic-handler/weak-lang-item.rs b/tests/ui/panic-handler/weak-lang-item.rs
new file mode 100644
index 000000000..14a07a9ef
--- /dev/null
+++ b/tests/ui/panic-handler/weak-lang-item.rs
@@ -0,0 +1,12 @@
+// aux-build:weak-lang-items.rs
+// error-pattern: `#[panic_handler]` function required, but not found
+// error-pattern: language item required, but not found: `eh_personality`
+// needs-unwind since it affects the error output
+// ignore-emscripten missing eh_catch_typeinfo lang item
+
+#![no_std]
+
+extern crate core;
+extern crate weak_lang_items;
+
+fn main() {}
diff --git a/tests/ui/panic-handler/weak-lang-item.stderr b/tests/ui/panic-handler/weak-lang-item.stderr
new file mode 100644
index 000000000..202f3309d
--- /dev/null
+++ b/tests/ui/panic-handler/weak-lang-item.stderr
@@ -0,0 +1,22 @@
+error[E0259]: the name `core` is defined multiple times
+ --> $DIR/weak-lang-item.rs:9:1
+ |
+LL | extern crate core;
+ | ^^^^^^^^^^^^^^^^^^ `core` reimported here
+ |
+ = note: `core` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | extern crate core as other_core;
+ |
+
+error: `#[panic_handler]` function required, but not found
+
+error: language item required, but not found: `eh_personality`
+ |
+ = note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
+ = help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0259`.