More precisely point out what is immutable, in E0596 "cannot borrow data in a &
reference as mutable"
#113842
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Rationale and extra context
The current output is confusing because it does not indicate which part of the input is the source of the immutability, and especially because the span contains the
&mut
(which in this case is irrelevant, but is often attempted and may be needed to triggerDerefMut
).Many newcomers to Rust are not yet familiar with the idea that in order to get mutable access to some data, every part of the path by which they get that data must be mutable.
I have proposed that the compiler suggest calling
bar_mut()
per the naming convention, but this is questionable since the function might have different semantics, and it is secondary to the main issue here of pointing to the immutability clearly.Other cases
Without the
&mut
,the error is much clearer, but completely different since no reborrowing is involved:
The text was updated successfully, but these errors were encountered: