Mutability issue while indexing static immutable array #46095
Closed
Description
Hello, today we've found some weird behaviour of array indexing.
Here is the example
Code snippet:
fn foo<'a>(a1: &'a mut Bar, a2: &'a mut Bar)
{
let a = [a1, a2];
for i in 0..42
{
let index = i % 2;
//a[i % 2].bar(); //<= error
a[index].bar(); //<= no error
}
}
The question is, why is the indexing operator behaves depending on whether we evaluate index
in place or not.