Skip to content

Incorrect "Trait not implemented for &mut A" message #17746

New issue

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

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

Already on GitHub? # to your account

Closed
SimonSapin opened this issue Oct 3, 2014 · 4 comments · Fixed by #23921
Closed

Incorrect "Trait not implemented for &mut A" message #17746

SimonSapin opened this issue Oct 3, 2014 · 4 comments · Fixed by #23921
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@SimonSapin
Copy link
Contributor

Test case:

fn main() {}

struct A;

impl A {
    fn b(&mut self) {
        self.a()
    }
}

trait Foo {}
trait Bar {
    fn a(&self);
}

impl Foo for A {}
impl<T> Bar for T where T: Foo {
    fn a(&self) {}
}

rustc output:

a.rs:7:9: 7:17 error: the trait `Foo` is not implemented for the type `&mut A`
a.rs:7         self.a()
               ^~~~~~~~
error: aborting due to previous error

Expected behavior: &mut self is automatically converted to &self in the self.a() call.

The bug disappears if fn b is changed to take &self, if fn a is changed to take &mut self, or if the call is changed to (&*self).a().

CC @aturon

@aturon
Copy link
Member

aturon commented Oct 3, 2014

cc @pcwalton @nikomatsakis

@nikomatsakis
Copy link
Contributor

I can sort of imagine why this happens. I'm planning on picking at the method dispatch code over next week and I imagine I can fix this as I go.

@kmcallister kmcallister added I-wrong A-resolve Area: Name/path resolution done by `rustc_resolve` specifically labels Oct 5, 2014
@aturon
Copy link
Member

aturon commented Mar 30, 2015

Triage visit: this appears to be fixed. Tagging as needs test.

@aturon aturon added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 30, 2015
@SimonSapin
Copy link
Contributor Author

The original message includes a test case. Does it need to be modified somehow or just be in a PR?

aturon added a commit to aturon/rust that referenced this issue Mar 31, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 1, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically 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

Successfully merging a pull request may close this issue.

4 participants