diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/panic-handler | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/panic-handler')
23 files changed, 299 insertions, 0 deletions
diff --git a/src/test/ui/panic-handler/auxiliary/some-panic-impl.rs b/src/test/ui/panic-handler/auxiliary/some-panic-impl.rs new file mode 100644 index 000000000..0348b3a2d --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/auxiliary/weak-lang-items.rs b/src/test/ui/panic-handler/auxiliary/weak-lang-items.rs new file mode 100644 index 000000000..7a698cf76 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-1.rs b/src/test/ui/panic-handler/panic-handler-bad-signature-1.rs new file mode 100644 index 000000000..775961d3f --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-1.stderr b/src/test/ui/panic-handler/panic-handler-bad-signature-1.stderr new file mode 100644 index 000000000..8b044f766 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-2.rs b/src/test/ui/panic-handler/panic-handler-bad-signature-2.rs new file mode 100644 index 000000000..727934000 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-2.stderr b/src/test/ui/panic-handler/panic-handler-bad-signature-2.stderr new file mode 100644 index 000000000..5ab693420 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-3.rs b/src/test/ui/panic-handler/panic-handler-bad-signature-3.rs new file mode 100644 index 000000000..ab9c9d7f4 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-3.stderr b/src/test/ui/panic-handler/panic-handler-bad-signature-3.stderr new file mode 100644 index 000000000..0a70181fd --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-4.rs b/src/test/ui/panic-handler/panic-handler-bad-signature-4.rs new file mode 100644 index 000000000..8240ab083 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-bad-signature-4.stderr b/src/test/ui/panic-handler/panic-handler-bad-signature-4.stderr new file mode 100644 index 000000000..5e46da121 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-duplicate.rs b/src/test/ui/panic-handler/panic-handler-duplicate.rs new file mode 100644 index 000000000..bd99af999 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-duplicate.stderr b/src/test/ui/panic-handler/panic-handler-duplicate.stderr new file mode 100644 index 000000000..8cdc4888d --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-missing.rs b/src/test/ui/panic-handler/panic-handler-missing.rs new file mode 100644 index 000000000..6bb062ba6 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-requires-panic-info.rs b/src/test/ui/panic-handler/panic-handler-requires-panic-info.rs new file mode 100644 index 000000000..f13c12fc5 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-requires-panic-info.stderr b/src/test/ui/panic-handler/panic-handler-requires-panic-info.stderr new file mode 100644 index 000000000..2bae12efb --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-std.rs b/src/test/ui/panic-handler/panic-handler-std.rs new file mode 100644 index 000000000..6183c886c --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-std.stderr b/src/test/ui/panic-handler/panic-handler-std.stderr new file mode 100644 index 000000000..e4069b196 --- /dev/null +++ b/src/test/ui/panic-handler/panic-handler-std.stderr @@ -0,0 +1,19 @@ +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: argument should be `&PanicInfo` + --> $DIR/panic-handler-std.rs:8:16 + | +LL | fn panic(info: PanicInfo) -> ! { + | ^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0152`. diff --git a/src/test/ui/panic-handler/panic-handler-twice.rs b/src/test/ui/panic-handler/panic-handler-twice.rs new file mode 100644 index 000000000..05bef66d8 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-wrong-location.rs b/src/test/ui/panic-handler/panic-handler-wrong-location.rs new file mode 100644 index 000000000..dca591018 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/panic-handler-wrong-location.stderr b/src/test/ui/panic-handler/panic-handler-wrong-location.stderr new file mode 100644 index 000000000..ae3ed5ab1 --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/weak-lang-item-2.rs b/src/test/ui/panic-handler/weak-lang-item-2.rs new file mode 100644 index 000000000..a429d8fab --- /dev/null +++ b/src/test/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/src/test/ui/panic-handler/weak-lang-item.rs b/src/test/ui/panic-handler/weak-lang-item.rs new file mode 100644 index 000000000..df31e614c --- /dev/null +++ b/src/test/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 compiled with panic=abort, personality not required + +#![no_std] + +extern crate core; +extern crate weak_lang_items; + +fn main() {} diff --git a/src/test/ui/panic-handler/weak-lang-item.stderr b/src/test/ui/panic-handler/weak-lang-item.stderr new file mode 100644 index 000000000..202f3309d --- /dev/null +++ b/src/test/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`. |