diff options
Diffstat (limited to 'src/test/ui/alloc-error')
7 files changed, 105 insertions, 0 deletions
diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.rs b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.rs new file mode 100644 index 000000000..41c9a265c --- /dev/null +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.rs @@ -0,0 +1,18 @@ +// compile-flags:-C panic=abort + +#![feature(alloc_error_handler)] +#![no_std] +#![no_main] + +use core::alloc::Layout; + +#[alloc_error_handler] +fn oom( + info: &Layout, //~ ERROR argument should be `Layout` +) -> () //~ ERROR return type should be `!` +{ + loop {} +} + +#[panic_handler] +fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr new file mode 100644 index 000000000..34e09da45 --- /dev/null +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr @@ -0,0 +1,14 @@ +error: return type should be `!` + --> $DIR/alloc-error-handler-bad-signature-1.rs:12:6 + | +LL | ) -> () + | ^^ + +error: argument should be `Layout` + --> $DIR/alloc-error-handler-bad-signature-1.rs:11:11 + | +LL | info: &Layout, + | ^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.rs b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.rs new file mode 100644 index 000000000..49ea3105f --- /dev/null +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.rs @@ -0,0 +1,17 @@ +// compile-flags:-C panic=abort + +#![feature(alloc_error_handler)] +#![no_std] +#![no_main] + +struct Layout; + +#[alloc_error_handler] +fn oom( + info: Layout, //~ ERROR argument should be `Layout` +) { //~ ERROR return type should be `!` + loop {} +} + +#[panic_handler] +fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr new file mode 100644 index 000000000..85544b0c3 --- /dev/null +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr @@ -0,0 +1,14 @@ +error: return type should be `!` + --> $DIR/alloc-error-handler-bad-signature-2.rs:12:3 + | +LL | ) { + | ^ + +error: argument should be `Layout` + --> $DIR/alloc-error-handler-bad-signature-2.rs:11:11 + | +LL | info: Layout, + | ^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.rs b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.rs new file mode 100644 index 000000000..321fd954d --- /dev/null +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.rs @@ -0,0 +1,15 @@ +// compile-flags:-C panic=abort + +#![feature(alloc_error_handler)] +#![no_std] +#![no_main] + +struct Layout; + +#[alloc_error_handler] +fn oom() -> ! { //~ ERROR function should have one argument + loop {} +} + +#[panic_handler] +fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr new file mode 100644 index 000000000..8575e7508 --- /dev/null +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr @@ -0,0 +1,8 @@ +error: function should have one argument + --> $DIR/alloc-error-handler-bad-signature-3.rs:10:1 + | +LL | fn oom() -> ! { + | ^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/alloc-error/default-alloc-error-hook.rs b/src/test/ui/alloc-error/default-alloc-error-hook.rs new file mode 100644 index 000000000..100e97497 --- /dev/null +++ b/src/test/ui/alloc-error/default-alloc-error-hook.rs @@ -0,0 +1,19 @@ +// run-pass +// ignore-emscripten no processes +// ignore-sgx no processes + +use std::alloc::{Layout, handle_alloc_error}; +use std::env; +use std::process::Command; +use std::str; + +fn main() { + if env::args().len() > 1 { + handle_alloc_error(Layout::new::<[u8; 42]>()) + } + + let me = env::current_exe().unwrap(); + let output = Command::new(&me).arg("next").output().unwrap(); + assert!(!output.status.success(), "{:?} is a success", output.status); + assert_eq!(str::from_utf8(&output.stderr).unwrap(), "memory allocation of 42 bytes failed\n"); +} |