# Why does std::process::exit take an i32 when there is a dedicated ExitCode type

**URL:** <https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830>\
**Category:** libs\
**Created:** [November 21, 2026, 4:45pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830 "2026-11-21T16:45:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheese\_space](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cheese_space/32/14586_2.png) [@cheese\_space](https://internals.rust-lang.org/u/cheese_space)\
**Post date:** [November 21, 2026, 4:45pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/1 "2026-11-21T16:45:29Z")

</div>

Seems a bit strange to me why instead of taking the ExitCode type it takes an i32? Could it be that they forgot to update the exit function as ExitCode was introduced way later than the exit fn. And should I open an issue about this?

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [November 21, 2026, 4:55pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/2 "2026-11-21T16:55:04Z")

</div>

ExitCode got stabilized in 1.61, while exit was already part of 1.0.

---

<div class="post-metadata">

**Author:** ![RustyYato](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rustyyato/32/13627_2.png) [@RustyYato](https://internals.rust-lang.org/u/RustyYato)\
**Post date:** [November 21, 2026, 5:21pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/3 "2026-11-21T17:21:49Z")

</div>

Changing the signature would be a breaking change and will not be accepted.

---

<div class="post-metadata">

**Author:** ![cheese\_space](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cheese_space/32/14586_2.png) [@cheese\_space](https://internals.rust-lang.org/u/cheese_space)\
**Post date:** [November 21, 2026, 5:56pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/4 "2026-11-21T17:56:57Z")

</div>

Could this not be done via an edition? And if it can’t be done via an edition, then they could make a new exit function something like:

```rust
pub fn exit_with_code(code: ExitCode) {
    // …
}

```

The old exit function could then be deprecated which isn’t a breaking change (I think?)

---

<div class="post-metadata">

**Author:** ![RustyYato](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rustyyato/32/13627_2.png) [@RustyYato](https://internals.rust-lang.org/u/RustyYato)\
**Post date:** [November 21, 2026, 6:43pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/5 "2026-11-21T18:43:38Z")

</div>

It looks like you could use [`ExitCode::exit_process`](https://doc.rust-lang.org/std/process/struct.ExitCode.html#method.exit_process) when that stabilizes

---

<div class="post-metadata">

**Author:** ![lucasparker](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@lucasparker](https://internals.rust-lang.org/u/lucasparker)\
**Post date:** [November 21, 2026, 7:21pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/6 "2026-11-21T19:21:55Z")

</div>

`ExitCode::exit_process()` is already stable (I believe since 1.61, alongside `ExitCode`), so `ExitCode::from(n).exit_process()` covers the typed case without adding `exit_with_code`. Editions can’t change the signature of an existing std function, and deprecating `exit` would break a huge amount of existing code for little gain.

---

<div class="post-metadata">

**Author:** ![SkiFire13](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/skifire13/32/7579_2.png) [@SkiFire13](https://internals.rust-lang.org/u/SkiFire13)\
**Post date:** [November 21, 2026, 7:25pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/7 "2026-11-21T19:25:36Z")

</div>

> [@lucasparker](#):
>
> Editions can’t change the signature of an existing std function

However in theory editions can affect name resolution in such a way that crates in different editions see different functions.

---

<div class="post-metadata">

**Author:** ![toc](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/toc/32/6692_2.png) [@toc](https://internals.rust-lang.org/u/toc)\
**Post date:** [November 21, 2026, 8:39pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/8 "2026-11-21T20:39:27Z")

</div>

Depends on how it was changed.

```rust
pub fn exit(code: impl Into<ExitCode>) -> !

```

Or more hypothetically

```rust
pub fn exit(code: impl Into<ExitCode> default i32) -> !

```

Or something which allowed for multiple implementations. `ExitCode` doesn't implement `From<i32>`. My guess is there's a comment on a random PR about that. But the point is there are options.

---

<div class="post-metadata">

**Author:** ![RustyYato](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rustyyato/32/13627_2.png) [@RustyYato](https://internals.rust-lang.org/u/RustyYato)\
**Post date:** [November 21, 2026, 10:37pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/9 "2026-11-21T22:37:09Z")

</div>

No, it's still unstable. I linked to the stable docs which has a tag that it's unstable 😄

Here's the tracking issue: [Tracking Issue for ExitCode::exit\_process() · Issue #97100 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/issues/97100)

> [@toc](#):
>
> Depends on how it was changed.

From the tracing issue, one concern was inference failures. See this [comment](https://github.com/rust-lang/rust/issues/97100#issuecomment-5687657467)

---

<div class="post-metadata">

**Author:** ![chrefr](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chrefr](https://internals.rust-lang.org/u/chrefr)\
**Post date:** [November 21, 2026, 11:27pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/10 "2026-11-21T23:27:08Z")

</div>

[Not just in theory](https://github.com/rust-lang/rust/pull/160227).

(Whether it'll be used in this case, I don't know).

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/quinedot/32/7294_2.png) [@quinedot](https://internals.rust-lang.org/u/quinedot)\
**Post date:** [November 22, 2026, 6:48am UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/11 "2026-11-22T06:48:25Z")

</div>

> [@toc](#):
>
> `ExitCode` doesn't implement `From<i32>`. My guess is there's a comment on a random PR about that.

> **[Differences from process::exit() - ExitCode in std::process - Rust](https://doc.rust-lang.org/std/process/struct.ExitCode.html#differences-from-processexit)**
>
> Exit the current process with the given ExitCode. | This type represents the status code the current process can return to its parent under normal termination.

> `process::exit()` accepts any `i32` value as the exit code for the process; however, there are platforms that only use a subset of that value (see `process::exit` platform-specific behavior). `ExitCode` exists because of this; only `ExitCodes` that are supported by a majority of our platforms can be created, so those problems don’t exist (as much) with this method.

---

<div class="post-metadata">

**Author:** ![cheese\_space](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cheese_space/32/14586_2.png) [@cheese\_space](https://internals.rust-lang.org/u/cheese_space)\
**Post date:** [November 22, 2026, 11:28am UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/12 "2026-11-22T11:28:20Z")

</div>

I mean set\_var used to be a [safe fn](https://doc.rust-lang.org/1.0.0/std/env/fn.set_var.html) and is now an [unsafe fn](https://doc.rust-lang.org/std/env/fn.set_var.html), how did they do that if that also is a breaking change?

---

<div class="post-metadata">

**Author:** ![RustyYato](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rustyyato/32/13627_2.png) [@RustyYato](https://internals.rust-lang.org/u/RustyYato)\
**Post date:** [November 22, 2026, 12:23pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/13 "2026-11-22T12:23:01Z")

</div>

Because the other option was failing Rust's safety guarantee, this was seen as significantly worse and making `env::set_var` "safe" was a mistake.

The bar for a high impact breaking change is very high, and changing `set_var` to `unsafe` cleared that bar.

This is also a high impact breaking change, but the motivation doesn't clear that high bar. A type signature being inconvenient or theoretically sub-par is not sufficient.

---

<div class="post-metadata">

**Author:** ![afetisov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/afetisov/32/8508_2.png) [@afetisov](https://internals.rust-lang.org/u/afetisov)\
**Post date:** [November 23, 2026, 3:46pm UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/14 "2026-11-23T15:46:33Z")

</div>

That may break type inference if the type i32 was inferred based on use site. Technically, it's allowed to break inference in new versions, but it's still very disruptive. This specific change looks gratuitous.

---

<div class="post-metadata">

**Author:** ![toc](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/toc/32/6692_2.png) [@toc](https://internals.rust-lang.org/u/toc)\
**Post date:** [November 24, 2026, 2:36am UTC](https://internals.rust-lang.org/t/why-does-std-exit-take-an-i32-when-there-is-a-dedicated-exitcode-type/24830/15 "2026-11-24T02:36:00Z")

</div>

That's why I also had

```rust
pub fn exit(code: impl Into<ExitCode> default i32) -> !
// or
pub fn exit(code: impl Into<ExitCode> please_infer i32) -> !
// or
pub fn exit(code: impl Into<ExitCode> 🦈 i32) -> !

```

We could get to a point where this specific change _isn't_ gratuitous and disruptive, and that would be nice, and then it would probably be a good change to make\[1\]. To be clear, I don't think the API should be changed _right now_ for reasons already mentioned in the thread.

* * *

1. Kinda sorta. The specific change would probably involve creating a brand new trait implemented by `i32` and `ExitCode` and defaulting inference to `i32` and who knows, maybe other stuff. It doesn't really matter. Should `exit` also be able to take an `ExitCode`? Yes. For various reasons the language is not at a point where that isn't either too much work, too disruptive, or both, and changing this one function would be about 0.00008% of the total motivation for any of that mess so it's not happening now.
