Skip to content

better suggestion for HashMap::mut_values #145276

@martindemello

Description

@martindemello

Code

use std::collections::HashMap

pub fn main() {
let a = HashMap::new();
    for v in a.mut_values() {
        ();
    }
}

Current output

help: there is a method `values` with a similar name
  |
5 - for v in a.mut_values() {
5 + for v in a.values() {

Desired output

help: there is a method `values` with a similar name
  |
5 - for v in a.mut_values() {
5 + for v in a.values() {

help: there is a method `values_mut` with a similar name
  |
5 - for v in a.mut_values() {
5 + for v in a.values_mut() {

Rationale and extra context

calling a method mut_foo when foo_mut exists seems like a fairly obvious attempt to get at the latter, and also a mistake i can imagine other people making

Other cases

Rust Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions