Skip to content

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

Closed
@kmcallister

Description

@kmcallister
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.

Activity

catamorphism

catamorphism commented on Oct 15, 2013

@catamorphism
Contributor

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

catamorphism

catamorphism commented on Oct 17, 2013

@catamorphism
Contributor

1.0, high

fhahn

fhahn commented on Oct 22, 2013

@fhahn
Contributor

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

lambda-fairy commented on Jan 10, 2014

@lambda-fairy
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.

added a commit that references this issue on Jan 13, 2014

auto merge of #11482 : fhahn/rust/issue-8005-better-error-msg-semi-la…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @catamorphism@kmcallister@fhahn@lambda-fairy

        Issue actions

          Better error message for semicolon on last line of function · Issue #8005 · rust-lang/rust