@@ -1404,6 +1404,15 @@ impl From<fs::File> for Stdio {
1404
1404
/// For proper error reporting of failed processes, print the value of `ExitStatus` or
1405
1405
/// `ExitStatusError` using their implementations of [`Display`](crate::fmt::Display).
1406
1406
///
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
+ ///
1407
1416
/// [`status`]: Command::status
1408
1417
/// [`wait`]: Child::wait
1409
1418
//
@@ -1636,8 +1645,16 @@ impl fmt::Display for ExitStatusError {
1636
1645
#[ unstable( feature = "exit_status_error" , issue = "84908" ) ]
1637
1646
impl crate :: error:: Error for ExitStatusError { }
1638
1647
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
1641
1658
///
1642
1659
/// Numeric values used in this type don't have portable meanings, and
1643
1660
/// different platforms may mask different amounts of them.
@@ -1648,31 +1665,34 @@ impl crate::error::Error for ExitStatusError {}
1648
1665
/// [`SUCCESS`]: ExitCode::SUCCESS
1649
1666
/// [`FAILURE`]: ExitCode::FAILURE
1650
1667
///
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`
1654
1669
///
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.
1656
1676
#[ derive( Clone , Copy , Debug ) ]
1657
- #[ unstable ( feature = "process_exitcode_placeholder " , issue = "48711 " ) ]
1677
+ #[ stable ( feature = "process_exitcode " , since = "1.60.0 " ) ]
1658
1678
pub struct ExitCode ( imp:: ExitCode ) ;
1659
1679
1660
- #[ unstable ( feature = "process_exitcode_placeholder " , issue = "48711 " ) ]
1680
+ #[ stable ( feature = "process_exitcode " , since = "1.60.0 " ) ]
1661
1681
impl ExitCode {
1662
1682
/// The canonical ExitCode for successful termination on this platform.
1663
1683
///
1664
1684
/// Note that a `()`-returning `main` implicitly results in a successful
1665
1685
/// termination, so there's no need to return this from `main` unless
1666
1686
/// you're also returning other possible codes.
1667
- #[ unstable ( feature = "process_exitcode_placeholder " , issue = "48711 " ) ]
1687
+ #[ stable ( feature = "process_exitcode " , since = "1.60.0 " ) ]
1668
1688
pub const SUCCESS : ExitCode = ExitCode ( imp:: ExitCode :: SUCCESS ) ;
1669
1689
1670
1690
/// The canonical ExitCode for unsuccessful termination on this platform.
1671
1691
///
1672
1692
/// If you're only returning this and `SUCCESS` from `main`, consider
1673
1693
/// instead returning `Err(_)` and `Ok(())` respectively, which will
1674
1694
/// 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 " ) ]
1676
1696
pub const FAILURE : ExitCode = ExitCode ( imp:: ExitCode :: FAILURE ) ;
1677
1697
}
1678
1698
@@ -1684,14 +1704,18 @@ impl ExitCode {
1684
1704
//
1685
1705
// More info: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426
1686
1706
/// 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
+ ) ]
1688
1712
#[ inline]
1689
1713
pub fn to_i32 ( self ) -> i32 {
1690
1714
self . 0 . as_i32 ( )
1691
1715
}
1692
1716
}
1693
1717
1694
- #[ unstable ( feature = "process_exitcode_placeholder " , issue = "48711 " ) ]
1718
+ #[ stable ( feature = "process_exitcode " , since = "1.60.0 " ) ]
1695
1719
impl From < u8 > for ExitCode {
1696
1720
/// Construct an exit code from an arbitrary u8 value.
1697
1721
fn from ( code : u8 ) -> Self {
@@ -2031,26 +2055,27 @@ pub fn id() -> u32 {
2031
2055
/// The default implementations are returning `libc::EXIT_SUCCESS` to indicate
2032
2056
/// a successful execution. In case of a failure, `libc::EXIT_FAILURE` is returned.
2033
2057
#[ cfg_attr( not( test) , lang = "termination" ) ]
2034
- #[ unstable ( feature = "termination_trait_lib" , issue = "43301 " ) ]
2058
+ #[ stable ( feature = "termination_trait_lib" , since = "1.60.0 " ) ]
2035
2059
#[ rustc_on_unimplemented(
2036
2060
message = "`main` has invalid return type `{Self}`" ,
2037
2061
label = "`main` can only return types that implement `{Termination}`"
2038
2062
) ]
2039
2063
pub trait Termination {
2040
2064
/// Is called to get the representation of the value as status code.
2041
2065
/// This status code is returned to the operating system.
2066
+ #[ stable( feature = "termination_trait_lib" , since = "1.60.0" ) ]
2042
2067
fn report ( self ) -> ExitCode ;
2043
2068
}
2044
2069
2045
- #[ unstable ( feature = "termination_trait_lib" , issue = "43301 " ) ]
2070
+ #[ stable ( feature = "termination_trait_lib" , since = "1.60.0 " ) ]
2046
2071
impl Termination for ( ) {
2047
2072
#[ inline]
2048
2073
fn report ( self ) -> ExitCode {
2049
2074
ExitCode :: SUCCESS . report ( )
2050
2075
}
2051
2076
}
2052
2077
2053
- #[ unstable ( feature = "termination_trait_lib" , issue = "43301 " ) ]
2078
+ #[ stable ( feature = "termination_trait_lib" , since = "1.60.0 " ) ]
2054
2079
impl < E : fmt:: Debug > Termination for Result < ( ) , E > {
2055
2080
fn report ( self ) -> ExitCode {
2056
2081
match self {
@@ -2060,14 +2085,14 @@ impl<E: fmt::Debug> Termination for Result<(), E> {
2060
2085
}
2061
2086
}
2062
2087
2063
- #[ unstable ( feature = "termination_trait_lib" , issue = "43301 " ) ]
2088
+ #[ stable ( feature = "termination_trait_lib" , since = "1.60.0 " ) ]
2064
2089
impl Termination for ! {
2065
2090
fn report ( self ) -> ExitCode {
2066
2091
self
2067
2092
}
2068
2093
}
2069
2094
2070
- #[ unstable ( feature = "termination_trait_lib" , issue = "43301 " ) ]
2095
+ #[ stable ( feature = "termination_trait_lib" , since = "1.60.0 " ) ]
2071
2096
impl < E : fmt:: Debug > Termination for Result < !, E > {
2072
2097
fn report ( self ) -> ExitCode {
2073
2098
let Err ( err) = self ;
@@ -2076,15 +2101,15 @@ impl<E: fmt::Debug> Termination for Result<!, E> {
2076
2101
}
2077
2102
}
2078
2103
2079
- #[ unstable ( feature = "termination_trait_lib" , issue = "43301 " ) ]
2104
+ #[ stable ( feature = "termination_trait_lib" , since = "1.60.0 " ) ]
2080
2105
impl < E : fmt:: Debug > Termination for Result < Infallible , E > {
2081
2106
fn report ( self ) -> ExitCode {
2082
2107
let Err ( err) = self ;
2083
2108
Err :: < !, _ > ( err) . report ( )
2084
2109
}
2085
2110
}
2086
2111
2087
- #[ unstable ( feature = "termination_trait_lib" , issue = "43301 " ) ]
2112
+ #[ stable ( feature = "termination_trait_lib" , since = "1.60.0 " ) ]
2088
2113
impl Termination for ExitCode {
2089
2114
#[ inline]
2090
2115
fn report ( self ) -> ExitCode {
0 commit comments