rust
rust copied to clipboard
Arrays not coercing a mutable reference in the first position
Given i, j and k of type &mut isize, then &mut [i,j,k]
moves i, but not j or k. I discovered this when calling vec![i,j,k]
.
Similar issues: Arise from let r = &mut 0; [&mut 0, r]; *r += 1;
works, but let r = &mut 0; [r, &mut 0]; *r += 1;
complains about use of moved value *r
.
See an example full program here: https://play.rust-lang.org/?gist=13c2a934ae9d3f6c22b62c433fee4244&version=stable&mode=debug&edition=2015
CC @eddyb @nikomatsakis
Both [&mut 0, &mut &mut 0]
and [&mut &mut 0, &mut 0]
work, so I'm guessing deref coercions happen when the "LUB (aka join) coercion" mechanism "goes back" in the array, but reborrows don't.
Probably just a whitelist? But I don't remember the code exactly.
Just as an update, I tried this in the latest nightly and it still present.
triage: no change