Skip to content

Commit e3f458e

Browse files
committed
docs: Explain underscore prefix in tutorial
1 parent 096bcd5 commit e3f458e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

doc/tutorial.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,13 @@ let monster_size: int = 50;
240240
~~~~
241241

242242
Local variables may shadow earlier declarations, as in the previous
243-
example in which `my_favorite_value` is first declared as a `float`
244-
then a second `my_favorite_value` is declared as an int.
243+
example in which `monster_size` is first declared as a `float`
244+
then a second `monster_size` is declared as an int. If you were to actually
245+
compile this example though, the compiler will see that the second
246+
`monster_size` is unused, assume that you have made a mistake, and issue
247+
a warning. For occasions where unused variables are intentional, their
248+
name may be prefixed with an underscore to silence the warning, like
249+
`let _monster_size = 50;`.
245250

246251
Rust identifiers follow the same rules as C; they start with an alphabetic
247252
character or an underscore, and after that may contain any sequence of

0 commit comments

Comments
 (0)