Closed
Description
We don't support whatever magic links in the alloc error handler, it seems:
#![feature(alloc_error_hook, allocator_api)]
use std::alloc::*;
use std::ptr::NonNull;
struct BadAlloc;
unsafe impl Allocator for BadAlloc {
fn allocate(&self, _l: Layout) -> Result<NonNull<[u8]>, AllocError> {
Err(AllocError)
}
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
unreachable!();
}
}
fn main() {
set_alloc_error_hook(|_| panic!("alloc error"));
let _b = Box::new_in(0, BadAlloc);
}
error: unsupported operation: can't call (diverging) foreign function: __rust_alloc_error_handler
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:385:13
|
385 | __rust_alloc_error_handler(layout.size(), layout.align());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't call (diverging) foreign function: __rust_alloc_error_handler
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
= note: inside `std::alloc::handle_alloc_error::rt_error` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:385:13: 385:70
= note: inside `std::alloc::handle_alloc_error` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:391:9: 391:75
= note: inside `std::boxed::Box::<i32, BadAlloc>::new_uninit_in` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:451:23: 451:49
= note: inside `std::boxed::Box::<i32, BadAlloc>::new_in` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:383:25: 383:51
note: inside `main`
--> src/main.rs:20:14
|
20 | let _b = Box::new_in(0, BadAlloc);
| ^^^^^^^^^^^^^^^^^^^^^^^^
Metadata
Metadata
Assignees
Labels
No labels