Skip to content

Document the effect of main's return value? #1196

@mattheww

Description

@mattheww

#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 calls report() on its result (which necessarily implements Termination), which gives an ExitCode.

  • 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 status

Further, 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, and ExitCode::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 a Result<_, 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 for Result<_, Debug>, because those are in std.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions