-
Notifications
You must be signed in to change notification settings - Fork 504
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
Document the effect of main's return value? #1196
Comments
This sounds reasonable to me. The reference has historically not touched on platform-specifics like this, and has also somewhat ignored life before/after main as well. But I think making these statements about @rust-lang/lang I would appreciate if someone could weigh in here. Are you OK with the reference specifying the exit-status behavior with respect to the |
Despite And we should explicitly document how we pass through values. |
Also, a bit more context from the lang team meeting. When we discussed this we agreed that we want the reference to include documentation about the runtime half of the return from main system. Such as specifying how it interacts with the |
RE. the above (w/ the context from reading the minutes of that aformentioned meeting after the fact), C requires that a status code |
I don't think we'd necessarily want to copy C here, but we did discuss whether the |
More concretely, the idea being that constructing an ExitCode from 0u8 will
always give you ExitCode::SUCCESS, and any other value would always give
you ExitCode::FAILURE, but ExitCode::SUCCESS doesn't necessarily need to
map to 0 on any specific platform.
We should be able to construct arbitrary ExitCodes, though.
One of the reasons I believe for ExitCode (and indeed, one reason I need
it) is to return arbitrary status's to the environment, thus communicating
with w/e program may be `wait`ing.
I'd expect ExitCode::new(20u8) to return 20 to the environment, not 1,
usually because I've prearranged the value "20" to have some special
meaning with something I know will be running the program (for example, for
cargo-native-install, a program that does an autotools-like install for
cargo projects, an exit status of 20 from a run target means
"Skipped.Target, Report, Continue Instalation", whereas 1 means "Fatal
install Error, Report, Abort Installation").
…On Tue, 3 May 2022 at 14:43, Jane Lusby ***@***.***> wrote:
RE. the above (w/ the context from reading the minutes of that
aformentioned meeting after the fact), C requires that a status code 0
(and incidentally also EXIT_SUCCESS which may be the same or distinct)
mean "successful" termination, though it doesn't require anything other
than EXIT_FAILURE to mean "failed" termination.
I don't think we'd necessarily want to copy C here, but we did discuss
whether the u8 value an ExitCode is constructed from in rust should be
distinct from the value it gets translated to for any specific platform.
More concretely, the idea being that constructing an ExitCode from 0u8
will always give you ExitCode::SUCCESS, and any other value would always
give you ExitCode::FAILURE, but ExitCode::SUCCESS doesn't necessarily
need to map to 0 on any specific platform.
—
Reply to this email directly, view it on GitHub
<#1196 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGLD232NFAUGND7H5VK4WTVIFXWLANCNFSM5T2CGF5A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I think there's been some confusion here. I didn't mean to imply that Then, if we run into a situation where someone is running on a platform where |
We discussed this again in today's @rust-lang/lang meeting, and we want to confirm that we'd be happy to have the lang/runtime aspects of this documented in the reference. (The library semantics should remain in the library docs.) |
#1194 (comment) suggests documenting how
main()
s return value affects the process's exit status.I think the Reference doesn't currently have anything to say about what happens after
main()
returns.I suggest adding a section in runtime.md saying roughly the following:
When (if)
main()
returns, the runtime callsreport()
on its result (which necessarily implementsTermination
), which gives anExitCode
.The runtime uses that
ExitCode
in a platform-specific way to report information to the environment hosting the Rust program.Note: on Unix-like systems and Windows, the
ExitCode
determines the process's exit statusFurther, I think some part of Rust's documentation ought to be saying that, on Unix-like systems and Windows,
ExitCode::SUCCESS
leads to exit status 0, andExitCode::FAILURE
leads to exit status 1 (because we have to expect that users will rely on that behaviour). I think that part would be better in the standard library docs, but it isn't currently there.I think it's important to say that
report()
is called, because that's what has the side-effect of printing a message to standard error (in the case where the returned value was aResult<_, Debug>
).So I think ideally the standard library docs would have entries for the specific
Termination
impls, saying how each of them behaves.I think this approach would avoid the worry expressed in rust-lang/rust#93448: a no_std binary won't be using the
Termination
impls forResult<_, Debug>
, because those are in std.The text was updated successfully, but these errors were encountered: