Type errors use 'expected' and 'found' in a confusing way #78539
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-inference
Area: Type inference
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Consider this snippet:
This fails because
array.into_iter()
collapses to(&array).into_iter()
, which provides a slice iterator that emits references, butVec::extend
wants values. This gives the following error:This error, read naturally, seems to indicate that we have values but are expecting references. This confused a team member of mine today who didn't realize that arrays aren't iterable by-move. To quote:
From that perspective, the intuition is that the vec wants values, the array iterator is providing values, so why is the error message reporting that something is expecting a reference?
Additionally, while not strictly speaking part of the diagnostic, the first example in the docs (which is shown inline by rust-analyzer) looks like this:
This seems to show a slice being used without issue to extend something without explict copying or cloning. The disconnect is that
String: Extend<&char>
, but in this particular case it seemed to reinforce the idea that slices may be used to extend something by-move.Meta
This issue was originally reported in rust 1.46.0:
However, I've also reproduced it in current stable:
and current nightly:
The text was updated successfully, but these errors were encountered: