Document explicitly ignoring expression values

master
Henry Nelson 2018-12-10 00:50:12 -05:00 committed by Andrew Kelley
parent 1b0f4d5976
commit 68b0fce62f
1 changed files with 12 additions and 4 deletions

View File

@ -4264,13 +4264,21 @@ fn foo() i32 {
return 1234;
}
{#code_end#}
<p>However, if the expression has type {#syntax#}void{#endsyntax#}:</p>
<p>However, if the expression has type {#syntax#}void{#endsyntax#}, there will be no error. Function return values can also be explicitly ignored by assigning them to {#syntax#}_{#endsyntax#}. </p>
{#code_begin|test#}
test "ignoring expression value" {
foo();
test "void is ignored" {
returnsVoid();
}
fn foo() void {}
test "explicitly ignoring expression value" {
_ = foo();
}
fn returnsVoid() void {}
fn foo() i32 {
return 1234;
}
{#code_end#}
{#header_close#}