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

Better error message for semicolon on last line of function #8005

Closed
kmcallister opened this issue Jul 23, 2013 · 4 comments
Closed

Better error message for semicolon on last line of function #8005

kmcallister opened this issue Jul 23, 2013 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-medium Medium priority
Milestone

Comments

@kmcallister
Copy link
Contributor

Putting a semicolon on the last line of a non-void function produces

error: not all control paths return a value

which is fairly confusing. It would be good to have a special error message for this common case.

@catamorphism
Copy link
Contributor

I think this error message is confusing for beginners. Nominating.

@catamorphism
Copy link
Contributor

1.0, high

@fhahn
Copy link
Contributor

fhahn commented Oct 22, 2013

I had a look at this issue and I was wondering how (and if) a single semicolon in a line is represented in the AST?
My first approach to solve this issue was passing the body block of the function to check_ret and check if the last statement is a single semicolon. (the code, which prints the number of statements in a block from check_ret can be found here: fhahn@4033420)
But it seems there is no statement for a single semicolon. Is it possible that a single semicolon gets dropped from the AST?

@lambda-fairy
Copy link
Contributor

@fhahn I found this definition in libsyntax/ast.rs:

pub struct Block {
    view_items: ~[view_item],
    stmts: ~[@Stmt],
    expr: Option<@Expr>,
    id: NodeId,
    rules: BlockCheckMode,
    span: Span,
}

You might like to look at the expr field.

bors added a commit that referenced this issue Jan 13, 2014
…st-stmt, r=alexcrichton

This is a patch for #8005, thanks @lfairy for the hint.

It seems like `block.expr` is None, if the last line of a function has a semi colon (= it ends with a statement).

@kmcallister does this error message cover the intended use cases? 
I'm not sure about the message, the wording and the span could probably be improved.
@bors bors closed this as completed in c74c854 Jan 13, 2014
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

4 participants