Diagnostics for an immutable reference to an iterator #64068
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-iterators
Area: Iterators
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
This problem comes up in generic contexts, but the simplest code to reproduce is:
Results in:
At first glance it looks wrong, because it says that
Iter
is not an iterator. It is not obvious that immutability of the shared reference is what breaks the code.Interestingly, an only a slightly different code produces a better suggestion:
So possibly the condition for the help text is too narrow, and could be extended to work in general case. It could also suggest using
&mut
as another alternative.(#37914 has a similar problem, but a different root cause)
The text was updated successfully, but these errors were encountered: