Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thestinger opened this issue Feb 8, 2013 · 3 comments
Closed

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

thestinger opened this issue Feb 8, 2013 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@thestinger
Copy link
Contributor

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.

@alexcrichton
Copy link
Member

This may be somewhat related to #4666

@emberian
Copy link
Member

emberian commented Jul 7, 2013

Cannot reproduce; needs test.

@alexcrichton
Copy link
Member

I think that this has been fixed in the past borrowck changes. The test case which now passes I believe was:

struct A;

impl A {
    fn foo(&mut self) {}
}

fn main() {
    let mut a = A;
    (a).foo();
}

If there's something else at play though, this should definitely be reopened!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

3 participants