Skip to content

Commit 7bdad89

Browse files
committed
Stabilize Termination and ExitCode
1 parent 75d9a0a commit 7bdad89

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed

library/std/src/process.rs

+44-19
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,15 @@ impl From<fs::File> for Stdio {
14041404
/// For proper error reporting of failed processes, print the value of `ExitStatus` or
14051405
/// `ExitStatusError` using their implementations of [`Display`](crate::fmt::Display).
14061406
///
1407+
/// # Differences from `ExitStatus`
1408+
///
1409+
/// `ExitCode` is intended for terminating the currently running process, via
1410+
/// the `Termination` trait, in contrast to [`ExitStatus`], which represents the
1411+
/// termination of a child process. These APIs are separate due to platform
1412+
/// compatibility differences and their expected usage; it is not generally
1413+
/// possible to exactly reproduce an ExitStatus from a child for the current
1414+
/// process after the fact.
1415+
///
14071416
/// [`status`]: Command::status
14081417
/// [`wait`]: Child::wait
14091418
//
@@ -1636,8 +1645,16 @@ impl fmt::Display for ExitStatusError {
16361645
#[unstable(feature = "exit_status_error", issue = "84908")]
16371646
impl crate::error::Error for ExitStatusError {}
16381647

1639-
/// This type represents the status code a process can return to its
1640-
/// parent under normal termination.
1648+
/// This type represents the status code the current process can return
1649+
/// to its parent under normal termination.
1650+
///
1651+
/// ExitCode is intended to be consumed only by the standard library (via
1652+
/// `Termination::report()`), and intentionally does not provide accessors like
1653+
/// `PartialEq`, `Eq`, or `Hash`. Instead the standard library provides the
1654+
/// canonical `SUCCESS` and `FAILURE` exit codes as well as `From<u8> for
1655+
/// ExitCode` for constructing other arbitrary exit codes.
1656+
///
1657+
/// # Portability
16411658
///
16421659
/// Numeric values used in this type don't have portable meanings, and
16431660
/// different platforms may mask different amounts of them.
@@ -1648,31 +1665,34 @@ impl crate::error::Error for ExitStatusError {}
16481665
/// [`SUCCESS`]: ExitCode::SUCCESS
16491666
/// [`FAILURE`]: ExitCode::FAILURE
16501667
///
1651-
/// **Warning**: While various forms of this were discussed in [RFC #1937],
1652-
/// it was ultimately cut from that RFC, and thus this type is more subject
1653-
/// to change even than the usual unstable item churn.
1668+
/// # Differences from `ExitStatus`
16541669
///
1655-
/// [RFC #1937]: https://github.com/rust-lang/rfcs/pull/1937
1670+
/// `ExitCode` is intended for terminating the currently running process, via
1671+
/// the `Termination` trait, in contrast to [`ExitStatus`], which represents the
1672+
/// termination of a child process. These APIs are separate due to platform
1673+
/// compatibility differences and their expected usage; it is not generally
1674+
/// possible to exactly reproduce an ExitStatus from a child for the current
1675+
/// process after the fact.
16561676
#[derive(Clone, Copy, Debug)]
1657-
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1677+
#[stable(feature = "process_exitcode", since = "1.60.0")]
16581678
pub struct ExitCode(imp::ExitCode);
16591679

1660-
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1680+
#[stable(feature = "process_exitcode", since = "1.60.0")]
16611681
impl ExitCode {
16621682
/// The canonical ExitCode for successful termination on this platform.
16631683
///
16641684
/// Note that a `()`-returning `main` implicitly results in a successful
16651685
/// termination, so there's no need to return this from `main` unless
16661686
/// you're also returning other possible codes.
1667-
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1687+
#[stable(feature = "process_exitcode", since = "1.60.0")]
16681688
pub const SUCCESS: ExitCode = ExitCode(imp::ExitCode::SUCCESS);
16691689

16701690
/// The canonical ExitCode for unsuccessful termination on this platform.
16711691
///
16721692
/// If you're only returning this and `SUCCESS` from `main`, consider
16731693
/// instead returning `Err(_)` and `Ok(())` respectively, which will
16741694
/// return the same codes (but will also `eprintln!` the error).
1675-
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1695+
#[stable(feature = "process_exitcode", since = "1.60.0")]
16761696
pub const FAILURE: ExitCode = ExitCode(imp::ExitCode::FAILURE);
16771697
}
16781698

@@ -1684,14 +1704,18 @@ impl ExitCode {
16841704
//
16851705
// More info: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426
16861706
/// Convert an ExitCode into an i32
1687-
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1707+
#[unstable(
1708+
feature = "process_exitcode_internals",
1709+
reason = "exposed only for libstd",
1710+
issue = "none"
1711+
)]
16881712
#[inline]
16891713
pub fn to_i32(self) -> i32 {
16901714
self.0.as_i32()
16911715
}
16921716
}
16931717

1694-
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1718+
#[stable(feature = "process_exitcode", since = "1.60.0")]
16951719
impl From<u8> for ExitCode {
16961720
/// Construct an exit code from an arbitrary u8 value.
16971721
fn from(code: u8) -> Self {
@@ -2031,26 +2055,27 @@ pub fn id() -> u32 {
20312055
/// The default implementations are returning `libc::EXIT_SUCCESS` to indicate
20322056
/// a successful execution. In case of a failure, `libc::EXIT_FAILURE` is returned.
20332057
#[cfg_attr(not(test), lang = "termination")]
2034-
#[unstable(feature = "termination_trait_lib", issue = "43301")]
2058+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20352059
#[rustc_on_unimplemented(
20362060
message = "`main` has invalid return type `{Self}`",
20372061
label = "`main` can only return types that implement `{Termination}`"
20382062
)]
20392063
pub trait Termination {
20402064
/// Is called to get the representation of the value as status code.
20412065
/// This status code is returned to the operating system.
2066+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20422067
fn report(self) -> ExitCode;
20432068
}
20442069

2045-
#[unstable(feature = "termination_trait_lib", issue = "43301")]
2070+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20462071
impl Termination for () {
20472072
#[inline]
20482073
fn report(self) -> ExitCode {
20492074
ExitCode::SUCCESS.report()
20502075
}
20512076
}
20522077

2053-
#[unstable(feature = "termination_trait_lib", issue = "43301")]
2078+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20542079
impl<E: fmt::Debug> Termination for Result<(), E> {
20552080
fn report(self) -> ExitCode {
20562081
match self {
@@ -2060,14 +2085,14 @@ impl<E: fmt::Debug> Termination for Result<(), E> {
20602085
}
20612086
}
20622087

2063-
#[unstable(feature = "termination_trait_lib", issue = "43301")]
2088+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20642089
impl Termination for ! {
20652090
fn report(self) -> ExitCode {
20662091
self
20672092
}
20682093
}
20692094

2070-
#[unstable(feature = "termination_trait_lib", issue = "43301")]
2095+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20712096
impl<E: fmt::Debug> Termination for Result<!, E> {
20722097
fn report(self) -> ExitCode {
20732098
let Err(err) = self;
@@ -2076,15 +2101,15 @@ impl<E: fmt::Debug> Termination for Result<!, E> {
20762101
}
20772102
}
20782103

2079-
#[unstable(feature = "termination_trait_lib", issue = "43301")]
2104+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20802105
impl<E: fmt::Debug> Termination for Result<Infallible, E> {
20812106
fn report(self) -> ExitCode {
20822107
let Err(err) = self;
20832108
Err::<!, _>(err).report()
20842109
}
20852110
}
20862111

2087-
#[unstable(feature = "termination_trait_lib", issue = "43301")]
2112+
#[stable(feature = "termination_trait_lib", since = "1.60.0")]
20882113
impl Termination for ExitCode {
20892114
#[inline]
20902115
fn report(self) -> ExitCode {

library/test/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#![feature(bench_black_box)]
2020
#![feature(internal_output_capture)]
2121
#![feature(staged_api)]
22-
#![feature(termination_trait_lib)]
23-
#![feature(process_exitcode_placeholder)]
22+
#![feature(process_exitcode_internals)]
2423
#![feature(test)]
2524
#![feature(total_cmp)]
2625

src/test/ui/rfcs/rfc-1937-termination-trait/termination-trait-for-exitcode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// run-pass
2-
#![feature(process_exitcode_placeholder)]
32

43
use std::process::ExitCode;
54

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
// run-pass
2-
#![feature(termination_trait_lib)]
32

43
fn main() -> impl std::process::Termination { }

0 commit comments

Comments
 (0)