RFC Mentoring Opportunity: Permit `?` in `main()`

The RFC looks pretty great to me, thanks @zackw! You’re about to make quite a few people happy :slight_smile:

Some thoughts I’d have:

  • If we’re requiring fn main() -> Result<...> to be what you literally write down, do we feel that this adequately solves the “what you write in docs is what you write in normal code” problem? Given today’s rustdoc expansion of tests, we’d have to then do:

    /// /// # fn main() -> Result<(), std::io::Error> { /// let f = File::open("foo")?; /// # } ///

  • For the implementation issues section I think that we’ll basically just want to implement this in the same way that proc macros and the like are implemented today. AFAIK the only stable method to define an entry point is a fn main() so we don’t have to worry that much about all the other entry points, which means we can do:

First update the lang_start lang item with a new signature, such as fn<T: Termination>(main: fn() -> T, argc: isize, argv: *const *const u8) -> isize. To leverage this, the compiler will generate code long before trans/typechecking/etc of the form:

#[start]
fn __rust_injected_start(argc: isize, argv: *const *const u8) -> isize {
    std::rt::lang_start(main, argc, argv)  
}

Then we’ll just naturally pick up #[start] and use that as an entry point in the executable being generated. Using this method we should be able to get nice span information about mis-implemented main functions and such.

1 Like