Index
chosen over IndexMut
incorrectly, with a confusing error message.
#75680
Labels
C-bug
Category: This is a bug.
Retrieving an element from a vector of mutable references works fine calling
index_mut()
directlybut fails when using supposedly equivalent indexing syntax:
(Playground)
The error message is rather surprising:
It's clearly not true that
IndexMut
is not implemented forVec
, as evidenced by the first implementation.The explicit trait call version only works because the explicit type annotation for
_i
triggers an implicit reborrow. My gut feeling is that the compiler is selectingIndex
instead ofIndexMut
here since the assignment looks like a move when not taking into account the implicit reborrow. I feel that the rejected code should be accepted. In any case, the error message should be fixed.This post was inspired by a question of StackOverflow today, and I discussed this on the user forum as well.
The text was updated successfully, but these errors were encountered: