Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array repeat expression evaluate only once #523

Open
scrabsha opened this issue Sep 24, 2024 · 2 comments
Open

Array repeat expression evaluate only once #523

scrabsha opened this issue Sep 24, 2024 · 2 comments
Assignees
Labels
category:content Issue related to the content of the specification kind:bug

Comments

@scrabsha
Copy link
Contributor

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>
@Veykril Veykril added kind:bug category:content Issue related to the content of the specification labels Sep 24, 2024
@Veykril
Copy link
Member

Veykril commented Sep 24, 2024

Oh yes that is very much incorrect, thanks for catching that!

The operand is evaluated once and then copied n-1 times. Notably, the operands type only needs to satisfy Copy for an n greater than 1.

@scrabsha
Copy link
Contributor Author

Thanks for your reply. This perfectly matches the model I had in mind!

I'd like to fix this. Can this issue be assigned to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:content Issue related to the content of the specification kind:bug
Projects
None yet
Development

No branches or pull requests

2 participants