Back to questions
JuniorTheoryCommon
What happens when this program is built and run?
fn five() -> i32 {
5;
}
fn main() {
println!("{}", five());
}It does not compile
- Expecting
5, as if;changed nothing:5;is a statement that discards the value, sofivereturns()and breaks its-> i32promise (E0308). - Expecting a default value such as
0: Rust never makes up a return value, and a body without a final expression returns().
- Which two different edits make
fivecompile and return5? - Why does a function without
->compile when its last line ends with;?