Why do functions implicitly return an empty tuple?

Hi, I wanna know why do functions implicitly return an empty tuple (). This is given as a compile error when the value the function returns mismatches the return type defined.

fn main() {
do_something(1);
}

fn do_something(x: i32) -> i32 {
let x = 5;
}

A link that points to the rust-lang/rust repo page that depicts this functionality in the compiler will be greatly appreciated.

Thanks

The empty tuple type is also known as “unit.” It's used whenever an expression or function doesn't return any data. The unit type docs have more details.

1 Like

Here's the compiler code where unit is set as the output type for a function with no explicit return type (DefaultReturn):

1 Like

Thank you so much.

1 Like

Thanks.

1 Like