Skip to content

Block expression should warning about missing return value #26577

Closed

Description

This is part of the Rust tutorial session. The whole purpose of the exercise was to find a mistake in the block expression.

See Exercise 2.1
http://pnkfelix.github.io/cyot/tutorial/exercises/ex_part_2

With rust compile this:

fn foo() -> i32 {
   42
}

pub fn main() {

    let the_sum :i32 = {
        foo();
    };

    let the_other_sum = {
        foo();
    };

}

It outputs this error:

bug_block.rs:7:24: 9:6 error: mismatched types:
 expected `i32`,
    found `()`
(expected i32,
    found ()) [E0308]
bug_block.rs:7     let the_sum :i32 = {
bug_block.rs:8         foo();
bug_block.rs:9     };
error: aborting due to previous error

It should also put a warning for line 12: "possibly missing return value". This would catch the bug.

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

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.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