-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add hint about the return code of panic! #42670
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
cc @rust-lang/docs |
src/libstd/macros.rs
Outdated
@@ -24,6 +24,8 @@ | |||
/// The multi-argument form of this macro panics with a string and has the | |||
/// `format!` syntax for building a string. | |||
/// | |||
/// If the main thread panics it will return with code `101`. |
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.
Is this something that is guaranteed to happen across all platforms?
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.
it's currently hard-coded; I don't know if we want to commit to this
@rust-lang/lang
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.
This seems fine but I'm not sure we want to lock into 101
src/libstd/macros.rs
Outdated
@@ -24,6 +24,8 @@ | |||
/// The multi-argument form of this macro panics with a string and has the | |||
/// `format!` syntax for building a string. | |||
/// | |||
/// If the main thread panics it will return with code `101`. |
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.
it's currently hard-coded; I don't know if we want to commit to this
@rust-lang/lang
Is there a particular reason for this return code? |
Something also to consider: although unusual, it's possible to catch panics, in which case this error code mention doesn't really apply |
Seems like we can't change the default, people may be relying on it. Someday maybe we could let you set the error code, no idea how though. |
This seems like a case where we want to document the current behavior but not commit to it. We've done this a few other places in libstd, can we say what happens today and then explicitly state that it may change in the future? |
@alexcrichton yeah we've done
in the past, could do that here as well. See https://doc.rust-lang.org/stable/std/primitive.slice.html#current-implementation |
@dns2utf8 ping! Any chance to update this PR according to the most recent comments? |
Yes, I will make it according to "current implementation" |
I think setting the error code could be done with the macro. Maybe something like this: panic!("my {} panic", "fancy" -> 23); Where 23 would be the returned error code. The |
I noticed something odd Using the following program but the return code is #include <stdlib.h>
int main() {
// this will make the programm return 134 on linux-amd64 platform
abort();
return 42;
} |
@dns2utf8 134 is the return code for a SIGABRT:
|
2b4aa41
to
9e001ce
Compare
Interesting, I did not know that. |
You have an overly-long line, please fix:
I'll also ping @steveklabnik for a review. |
Cool, thank you. |
@bors: r+ rollup |
📌 Commit 133c1bc has been approved by |
…klabnik Add hint about the return code of panic! I hope the link works on all cases, since the `unreachable` doc is copied to `std::` as well.
I hope the link works on all cases, since the
unreachable
doc is copied tostd::
as well.