Skip to content

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

Description

@SimonSapin

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyE-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