Skip to content

Error message for missing return value with Result type is unclear #24889

Closed
@bguiz

Description

@bguiz

The error message that I get looks like this:

src/main.rs:18:9: 18:11 error: unable to infer enough type information about `_`; type annotations required [E0282]
src/main.rs: 18         Ok(Response::with( (status::Ok, payload) ));
error: aborting due to previous error

The highlight is on the leading Ok, which is misleading. The actual fix was to either precede the statement with return, or to drop the trailing ;. It would be great if the compiler were to suggest this as well, as the current error message alone is cryptic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions