Closed
Description
I tried this code (playground):
use std::collections::HashMap;
fn main() {
HashMap::<String, i32>::new().iter().filter( |&(&k, &v)| { true });
}
I expected to see this happen:
error[E0507]: cannot move out of a shared reference
[...]
help: consider removing the borrow
|
4 - HashMap::<String, i32>::new().iter().filter( |&(&k, &v)| { true });
4 + HashMap::<String, i32>::new().iter().filter( |&(k, &v)| { true });
|
Instead, this happened:
error[E0507]: cannot move out of a shared reference
[...]
help: consider removing the borrow
|
4 - HashMap::<String, i32>::new().iter().filter( |&(&k, &v)| { true });
4 + HashMap::<String, i32>::new().iter().filter( |(&k, &v)| { true });
|
Diff between the two (red is actual, green is expected):
- 4 + HashMap::<String, i32>::new().iter().filter( |(&k, &v)| { true });
+ 4 + HashMap::<String, i32>::new().iter().filter( |&(k, &v)| { true });
That is, it is suggesting removing the borrow on the tuple, which is not the correct borrow to remove; instead, it should suggest removing the borrow on k
, the element that isn't Copy
.
Happens in playground nightly: 1.8.0-nightly (2024-11-08 59cec72)