-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict the Termination impls to simplify stabilization #48497
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1080,6 +1080,15 @@ impl fmt::Display for ExitStatus { | |
} | ||
} | ||
|
||
/// This is ridiculously unstable, as it's a completely-punted-upon part | ||
/// of the `?`-in-`main` RFC. It's here only to allow experimenting with | ||
/// returning a code directly from main. It will definitely change | ||
/// drastically before being stabilized, if it doesn't just get deleted. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh. Maybe we should |
||
#[doc(hidden)] | ||
#[derive(Clone, Copy, Debug)] | ||
#[unstable(feature = "process_exitcode_placeholder", issue = "43301")] | ||
pub struct ExitCode(pub i32); | ||
|
||
impl Child { | ||
/// Forces the child to exit. This is equivalent to sending a | ||
/// SIGKILL on unix platforms. | ||
|
@@ -1428,7 +1437,7 @@ impl Termination for () { | |
} | ||
|
||
#[unstable(feature = "termination_trait_lib", issue = "43301")] | ||
impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> { | ||
impl<E: fmt::Debug> Termination for Result<(), E> { | ||
fn report(self) -> i32 { | ||
match self { | ||
Ok(val) => val.report(), | ||
|
@@ -1442,20 +1451,23 @@ impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> { | |
|
||
#[unstable(feature = "termination_trait_lib", issue = "43301")] | ||
impl Termination for ! { | ||
fn report(self) -> i32 { unreachable!(); } | ||
fn report(self) -> i32 { self } | ||
} | ||
|
||
#[unstable(feature = "termination_trait_lib", issue = "43301")] | ||
impl Termination for bool { | ||
impl<E: fmt::Debug> Termination for Result<!, E> { | ||
fn report(self) -> i32 { | ||
if self { exit::SUCCESS } else { exit::FAILURE } | ||
let Err(err) = self; | ||
eprintln!("Error: {:?}", err); | ||
exit::FAILURE | ||
} | ||
} | ||
|
||
#[unstable(feature = "termination_trait_lib", issue = "43301")] | ||
impl Termination for i32 { | ||
impl Termination for ExitCode { | ||
fn report(self) -> i32 { | ||
self | ||
let ExitCode(code) = self; | ||
code | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really care, but I feel like this is overstating the case. Specifying an exit code doesn't seem so "wild and crazy" to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what I meant, but I can see what you mean after rereading. I'll make a follow-up PR weakening the language here.
I definitely agree that
fn main() -> ExitCode
is valuable. I only intended the statement to be about the precise form of this type, since it's not B-RFC-Approved and thus even more subject to change than usual.