Why no semicolon after Ok(()) at the end of a function in rust?

Viewed 431

Code snippet taken from the documentation on current_dir:

use std::env;

fn main() -> std::io::Result<()> {
    let path = env::current_dir()?;
    println!("The current directory is {}", path.display());
    Ok(())
}

I noticed that only by adding a semicolon after Ok(()), the program does not compile with the following error:

error[E0308]: mismatched types
expected enum `std::result::Result`, found `()`

Why is that?

1 Answers
Related