Cannot understand this error: HashMap::Keys::rev()

@semicoleon Do you want to open an issue on the rust-lang/rust repository for that change? It sounds like a good enough idea to be worth consideration.

Yeah I can do that tonight

1 Like

Opened #100433 and included a link back here

2 Likes

Thank you @semicoleon for opening that ticket.

When these conversations get too heated I find that having a concrete proposal for what the ideal output would have been help a lot.

Also, lets keep in mind that rust-analyzer doesn't show the full output that rustc does, it does an effort to map the span labels and messages, but the translation ends up leaving some context on the floor, which is a common thread on the confusion of newcomers when facing new errors.

@worik, now that it seems you might have enough context on why this didn't work, what would have been the ideal output that would have helped you understand this on your own? Feel free to include it in the ticket as well.

1 Like

Starts with:

for (k, _) in self.palette.keys().
...........................^^^^^  Error!

That would have been enough for me, at the time.

For what is worth, the compiler's output on the terminal is slightly easier to read, and does point at the place:

error[E0277]: the trait bound `std::collections::hash_map::Keys<'_, String, String>: DoubleEndedIterator` is not satisfied
 --> src/main.rs:5:28
  |
5 |     for (k, _) in x.keys().rev() {
  |                            ^^^ the trait `DoubleEndedIterator` is not implemented for `std::collections::hash_map::Keys<'_, String, String>`
  |
note: required by a bound in `rev`

error[E0277]: the trait bound `std::collections::hash_map::Keys<'_, String, String>: DoubleEndedIterator` is not satisfied
 --> src/main.rs:5:19
  |
5 |     for (k, _) in x.keys().rev() {
  |                   ^^^^^^^^^^^^^^ the trait `DoubleEndedIterator` is not implemented for `std::collections::hash_map::Keys<'_, String, String>`
  |
  = note: required because of the requirements on the impl of `Iterator` for `Rev<std::collections::hash_map::Keys<'_, String, String>>`
  = note: required because of the requirements on the impl of `IntoIterator` for `Rev<std::collections::hash_map::Keys<'_, String, String>>`

error[E0308]: mismatched types
 --> src/main.rs:5:9
  |
5 |     for (k, _) in x.keys().rev() {
  |         ^^^^^^    -------------- this is an iterator with items of type `&String`
  |         |
  |         expected struct `String`, found tuple
  |
  = note: expected struct `String`
              found tuple `(_, _)`

It is a shame, and I hope it won't be needed in the future, but it is a good idea to run cargo build when encountering errors that puzzle you in the IDE.

1 Like

I'm afraid it will, since it's highly unlikely that IDEs will cease trying to help the programmer by removing the "unnecessary" bits of information.

2 Likes

rust-analyzer is limited on what it can show by the VSCode APIs. Ideally the popup tooltip would show an iterface similar to the popup diff UI or the show references UI, where other parts of the editor are shown floating in place. The next best thing is to leverage the HTML pane API and take responsibility of consuming and emitting every relevant event and using that new pane to show the full context we can.

As a temporary solution, rust-analyzer could put a pre block in the tooltip (as it accepts markdown) with the full contents of the rustc error as-is. It'd be subpar, but it would eliminate these kind of problems in the meantime, and maybe act as justification to the VSCode maintainers to provide richer APIs for the tooltips.

I have another one at: Problematic errormessage: " `IndexMut` is required to modify indexed content"

As a C++ refuge I have come to love the error messages in Rust. They are still much better than the indecipherable gobeldy gook that comes out of the Standard Template Library but I fear there is a drift towards messages that only the authors of the library can decipher!