Skip to content

Commit

Permalink
Merge #530
Browse files Browse the repository at this point in the history
530: Fix array repetition operand evaluation r=Veykril a=scrabsha

It turns out that `[<repeated>; <length>]` evaluates `<repeated>` only one time, as seen in the following example:

```rust
fn main() {
    let mut counter = 0;
    [{
        counter += 1;
    }; 9];
    assert_eq!(counter, 1);
}
```

###### [Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b7ca3de9ba64675238380acae97fde37)

This PR updates the doc in order to match this behavior.

Co-authored-by: Sasha Pourcelot <[email protected]>
  • Loading branch information
bors-ferrocene[bot] and scrabsha authored Nov 4, 2024
2 parents d5472d9 + c64790c commit 7af39ec
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2864,17 +2864,10 @@ The :t:`evaluation` of an :t:`array expression` with an
:t:`array repetition constructor` proceeds as follows:

#. :dp:`fls_f3izbkm8607z`
If the :t:`value` of the :t:`size operand` is greater than zero, then:

#. :dp:`fls_qbyysx30pjzs`
If the :t:`repeat operand` denotes a :t:`constant`, the
:t:`repeat operand` is evaluated once and its :t:`value` is
:t:`passed <passing convention>` :t:`by copy` :t:`[size operand]'s`
:t:`value` times.

#. :dp:`fls_1m0laldldh7j`
Otherwise the :t:`repeat operand` is evaluated :t:`[size operand]'s`
:t:`value` times.
If the :t:`value` of the :t:`size operand` is greater than zero, then the
:t:`repeat operand` is evaluated once and its :t:`value` is
:t:`passed <passing convention>` :t:`by copy` :t:`[size operand]'s`
:t:`value` times.

#. :dp:`fls_5cs68nm54l31`
Otherwise the :t:`repeat operand` is evaluated once.
Expand Down

0 comments on commit 7af39ec

Please sign in to comment.