Skip to content

memory allocation failure should print backtrace #147385

@e00E

Description

@e00E

When memory allocation fails (for example when extending a Vec), a Rust program prints "memory allocation of xxx bytes failed" and aborts This message would be more helpful if it told you where the allocation happened by printing a backtrace. No backtrace is inconsistent with panics, which print a backtrace. A memory allocation feels like a panic so I expect to get a backtrace.

I understand there might be technical reasons for why this is hard. I'm still reporting this because from a user perspective this is wrong and we might be able to improve it. I didn't find a previous issue talking about this.

Linux, Rust 1.90.0

example program, playground

fn main() {
    foo();
}

fn foo() {
    // panic!();
    let mut v = Vec::new();
    v.resize(1000000000000, 1u8);
    // Print pointer so vector doesn't get optimized out.
    let ptr = v.as_ptr();
    println!("{ptr:?}");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions