What Does the Semicolon Do in Rust?

The semicolon terminates statements in Rust, indicating to the compiler that a specific instruction is complete.

The semicolon terminates statements in Rust, signaling the end of an expression that does not need to return a value to the caller. Omitting it causes a compilation error because the compiler expects the statement to conclude.

fn main() {
    let x = 5; // Semicolon ends the statement
    println!("x is {x}"); // Semicolon ends the function call
}