Skip to content

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

Closed
@SimonSapin

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

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