Skip to content

Commit d4ab3f2

Browse files
author
olivia hugger
authored
Merge pull request #93 from Michael-Lfx/patch-1
More detail about expression and statement
2 parents d33de0c + 3356540 commit d4ab3f2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

functions/functions5.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ fn square(num: i32) -> i32 {
4040

4141
// This is a really common error that can be fixed by removing one character.
4242
// It happens because Rust distinguishes between expressions and statements: expressions return
43-
// a value and statements don't. We want to return a value from the `square` function, but it
44-
// isn't returning one right now...
43+
// a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language.
44+
// We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
45+
// They are not the same. There are two solusions:
46+
// 1. Add a `return` ahead of `num * num;`
47+
// 2. remove `;`, make it to be `num * num`

0 commit comments

Comments
 (0)