Skip to content

Commit d024cf7

Browse files
committed
Document evaluation order
1 parent 56a13c0 commit d024cf7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/expressions.md

+24
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,30 @@ in the order given by their associativity.
8585
| `=` `+=` `-=` `*=` `/=` `%=` <br> `&=` <code>&#124;=</code> `^=` `<<=` `>>=` | right to left |
8686
| `return` `break` closures | |
8787

88+
## Evaluation order
89+
90+
Most expressions include subexpressions. Unless otherwise stated on the
91+
expression's page, evaluation of these inner expressions is left to right as
92+
written in the source code.
93+
94+
For example, the two `next` method calls will always be called in the same
95+
order:
96+
97+
```rust
98+
# // Using vec instead of array to avoid references
99+
# // since there is no stable owned array iterator
100+
# // at the time this example was written.
101+
let mut one_two = vec![1, 2].into_iter();
102+
assert_eq!(
103+
(1, 2),
104+
(one_two.next().unwrap(), one_two.next().unwrap())
105+
);
106+
```
107+
108+
> **Note**: Since this is applied recursively, expressions are also evaluated
109+
> from innermost to outermost, ignoring siblings until there are no inner
110+
> subexpressions.
111+
88112
## Place Expressions and Value Expressions
89113

90114
Expressions are divided into two main categories: place expressions and

0 commit comments

Comments
 (0)