-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.