Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Wilfred opened this issue Oct 25, 2015 · 3 comments
Closed

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

Wilfred opened this issue Oct 25, 2015 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Oct 25, 2015

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.

@nagisa
Copy link
Member

nagisa commented Oct 25, 2015

Dupe-ish of #21838.

EDIT: it does not print semicolon suggestion in this exact case because the integer is infered to u32, while return value is u16. The hint code could be improved in presence of integers.

EDIT 2: this function does have a control path, albeit only a single one.

@sanxiyn sanxiyn added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 26, 2015
@dylanmckay
Copy link
Contributor

This is caused because liveliness analysis will only print the missing semicolon warning if the types of the last statement and the return value of the function are equivalent.

I have a fix incoming.

Note that

fn foo() -> u16 {
    1u16;
}

Will print the "missing semicolon" diagnostic.

@birkenfeld
Copy link
Contributor

Duplicate of #30497.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

6 participants