Skip to content

same X, both X == 0 and X != 0 are triggered #145163

@loynoir

Description

@loynoir

I tried this code:

    if status == napi_ok {
        eprintln!("[reproduce] status == napi_ok, should not error");
    } else {
        eprintln!("[reproduce] status != napi_ok, should be error");
    }

    if status != napi_ok {
        unsafe {
            napi_throw_error(env, null_mut(), c"[reproduce] Error: status != napi_ok".as_ptr());
        }
        return null_mut();
    }

    let result = MaybeUninit::<napi_value>::uninit();

I expected to see this happen: explanation

X == 0 and X != 0 can not be both triggered

=== Calling debug reproduce ===
[reproduce] status == napi_ok, should not error
=== Calling release workaround ===
[workaround] status == napi_ok, should not error

Instead, this happened: explanation

X == 0 and X != 0 can be both triggered

=== Calling release reproduce ===
[reproduce] status == napi_ok, should not error
Error: [reproduce] Error: status != napi_ok
    at Object.<anonymous> (/workspaces/loynoir/repo/reproduce-rust-145163/reproduce.js:9:15)
    at Module._compile (node:internal/modules/cjs/loader:1738:14)
    at Object..js (node:internal/modules/cjs/loader:1871:10)
    at Module.load (node:internal/modules/cjs/loader:1470:32)
    at Module._load (node:internal/modules/cjs/loader:1290:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:238:24)
    at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
    at node:internal/main/run_main_module:33:47

workaround

let result = MaybeUninit::<napi_value>::uninit();
let result = MaybeUninit::<[napi_value; 1]>::uninit();

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.91.0-nightly (ec7c02612 2025-08-05)
binary: rustc
commit-hash: ec7c02612527d185c379900b613311bc1dcbf7dc
commit-date: 2025-08-05
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 20.1.8
Backtrace

<backtrace>

reproduce

https://github.com/loynoir/reproduce-rust-145163

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-gubCategory: the reverse of a compiler bug is generally UB

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions