File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,22 @@ declaration until the end of the enclosing block scope.
3636
3737## Expression statements
3838
39- An _ expression statement_ is one that evaluates an [ expression] ( expressions.html )
40- and ignores its result. The type of an expression statement ` e; ` is always
41- ` () ` , regardless of the type of ` e ` . As a rule, an expression statement's
42- purpose is to trigger the effects of evaluating its expression.
39+ An _ expression statement_ is one that evaluates an
40+ [ expression] ( expressions.html ) and ignores its result. The type of an
41+ expression statement ` e; ` is always ` () ` , regardless of the type of ` e ` . As a
42+ rule, an expression statement's purpose is to trigger the effects of evaluating
43+ its expression. An expression that consists of only a [ block
44+ expression] ( expressions.html#block-expressions ) or control flow expression,
45+ that doesn't end a block and evaluates to ` () ` can also be used as an
46+ expression statement by omitting the trailing semicolon.
47+
48+ ``` rust
49+ # let mut v = vec! [1 , 2 , 3 ];
50+ v . pop (); // Ignore the element returned from pop
51+ if v . is_empty () {
52+ v . push (5 );
53+ } else {
54+ v . remove (0 );
55+ } // Semicolon can be omitted.
56+ [1 ]; // Separate expression statement, not an indexing expression.
57+ ```
You can’t perform that action at this time.
0 commit comments