Is it just because we're trying to change the value of a constant? (changing ATOMS to static works as I had expected)
It makes sense from the interfaces that it would compile, but if that really is the case then it seems like a (slightly obscure) footgun for sure.
Yes clippy points out. But i misconfigured it in one of the editors. And I spent some time trying to figure out why the code didn't behave the way i expected. Finally found the culprit 😵
Ah, clippy, I was just trying it on the rust playground (with clippy off) and didn't think clippy would give me anything useful in this case 😅, pleasant surprise for sure. Thanks for posting this! I'm glad you were able to track down the problem, it's very subtle.
@AstraKernel Oooh, I know this one ^_^
The Ordering is a red herring. Every use of a const just copy-pastes the const expression into a new temporary. So ATOMS is replaced with [AtomicUsize::new(0); 4] in both lines, and accordingly the program prints 0.
The weird part is that mutating this temporary does not cause a compilation error - that's because AtomicUsize uses interior mutability, so AtomicUsize::store only requires a shared reference.
@AstraKernel 26% of respondents think you can mutate a const
*glares at JavaScript*