Skip to content

Improve 'not all control paths return a value' message #29307

Closed
@Wilfred

Description

@Wilfred

Given the code:

fn foo() -> u16 {
    1;
}

Rustc shows the error:

error: not all control paths return a value [E0269]

However, I think this is slightly misleading. There isn't actual a control path here, just a semicolon that shouldn't be there.

I think rustc should say something like "function does not return a value" when the last expression in a function is a simple expression without any control flow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions