rust-lang / rust-lang/fls

Array repeat expression evaluate only once

Open
#523 2 comments 0 reactions 1 assignee View on GitHub

@scrabsha is already working on this.

Since Sep 24, 2024.

A-content C-bug S-waiting-on-author
Dominant language
reStructuredText
Stars
497
Forks
41
Avg merge
3h 52m
Merged PRs (30d)
4

Description

Let's consider the following code snippet:

fn id() -> i32 {
    dbg!();
    42
}

fn main() {
    [id(); 9];
}
Playground link

The value of the repeat expression is not a constant, so (according to 6.8:18) the repeat expression should be evaluated 9 times, leading to nine debug traces being printed on the program output.

However, rustc prints only one debug trace:

   Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.94s
     Running `target/debug/playground`
[src/main.rs:2:5]
<END OF OUTPUT>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.