Skip to content

confusing error message from (object).method() with &mut self #4842

Closed
@thestinger

Description

@thestinger
foo.rs:11:5: 11:6 error: moving out of mutable local variable prohibited due to outstanding loan
foo.rs:11     (a).bar();
               ^
foo.rs:11:5: 11:6 note: loan of mutable local variable granted here
foo.rs:11     (a).bar();
             ^
error: aborting due to previous error

The compiler seems to consider (a) as an evaluation to a temporary value of the same type, which results in a quite confusing error. This doesn't occur with function((&mut x)). @bstrie discovered this while removing mut fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsA-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions