Skip to content

"nothing is returned" contradicts compiler output in Functions chapter #4678

@bp7968h

Description

@bp7968h

In the last paragraph of chapter 3.3 sub chapter Functions with Return Values states that nothing is returned when x + 1 is turned into a statement by adding a semicolon:

fn main() {
    let x = plus_one(5);

    println!("The value of x is: {x}");
}

fn plus_one(x: i32) -> i32 {
    x + 1; // Here
}

But the compiler error shown on the same page says implicitly returns (). The book also correctly identifies () as "the unit type" in the same sentence, making the explanation internally contradictory.

A more accurate phrasing might be: "statements evaluate to (), the unit type, which doesn't satisfy the declared i32 return type."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions