Skip to content

Mention function return type explictly in errors #39909

Closed
@ChrisJefferson

Description

@ChrisJefferson

I, like many other rust beginners, hit the "no try! in main problem". I'm not saying it should be fixed, but the error message should be more helpful. Could it explictly mention the fact this is to do with return values? It is currently:

 --> test.rs:13:5
   |
13 |     try!(io::stdin().read_line(&mut guess));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `std::result::Result`
   |
   = note: expected type `()`
              found type `std::result::Result<_, _>`
   = help: here are some functions which might fulfill your needs:
           - .unwrap()
           - .unwrap_err()
           - .unwrap_or_default()
   = note: this error originates in a macro outside of the current crate

Perhaps the error could change to something like: return type of main is (), trying to return enum std::result::Result (obviously don't hard-wire for main). This makes it more clear why we expected ().

I suspected this would already be reported somewhere, but I can't find it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions