Skip to content

Return Result from main #1176

Closed
Closed
@Ericson2314

Description

@Ericson2314

Rust's current error handling story is quite good for programming in the large. But for small programs, the overhead of matching the outermost Result, printing the error, and returning the proper error code is quite tedious in comparison to temptation of just panicking.

Furthermore, interactive tools shouldn't print a message implying the program is broken on bad manual input, yet such an "internal error" is exactly what the panic message applies. So there is no nice, succinct way to handle input errors with bubbling results or panics.

Allowing main to return a result would make our error handling story both compositional and succinct on programs on all sizes. Furthermore, should there be any platform-specific requirements/idioms for error-codes, etc, we can handle them transparently. While this does make main a bit more complex, there is already a shim between start and main with both C and Rust, so we're already down that rabbit hole.

I was told by @eddyb this was already a wanted feature, but @steveklabnik didn't see an open issue so I made this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions