Skip to content

cannot borrow argument X as mutable should give suggestion to fix #16410

@Swatinem

Description

@Swatinem

I’m trying to learn Rust from scratch right now, and I still have some difficulty grasping the concepts of mutability and move-semantics.

I think especially for mutability, the compiler could do a better job for suggesting fixes.
Consider the following code:

fn iter<T: Iterator<int>>(l: T) {
    for e in l {
        println!("{}", e);
    }
}

It simply says:

error: cannot borrow immutable argument `l` as mutable
    for e in l {
             ^

Which is kind of confusing. It should suggest to me that I add mut to the function argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions