Skip to content

Running diverging closure coerced to fn ptr fails: "invalid use of NULL pointer" #1075

Closed
rust-lang/rust
#66827
@RalfJung

Description

@RalfJung

The following code fails to run in Miri:

fn main() {
    let f: fn() -> ! = || std::process::exit(0);  
    f();
}

The error is

error: Miri evaluation error: invalid use of NULL pointer
   --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:227:5
    |
227 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Miri evaluation error: invalid use of NULL pointer
    |
note: inside call to `<[closure@src/main.rs:2:24: 2:48] as std::ops::FnOnce<()>>::call_once - shim` at src/main.rs:3:5
   --> src/main.rs:3:5
    |
3   |     f();
    |     ^^^

I am not entirely sure what is happening; it looks like this has something to do with the shim that is used to coerce non-capturing closures to function pointers.

Cc @eddyb @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-interpreterArea: affects the core interpreterC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions