Skip to content

Suggest fix when encountering different mutability from impl to trait #52412

Closed
@estebank

Description

@estebank

Given

trait Foo {
    fn bar(&mut self, other: &mut Foo);
}
struct Baz;
impl Foo for Baz {
    fn bar(&mut self, other: &Foo) {}
}

the current output is


error[E0053]: method `bar` has an incompatible type for trait
  --> $DIR/issue-13033.rs:18:30
   |
LL |     fn bar(&mut self, other: &mut Foo);
   |                              -------- type in trait
...
LL |     fn bar(&mut self, other: &Foo) {}
   |                              ^^^^ types differ in mutability
   |
   = note: expected type `fn(&mut Baz, &mut dyn Foo)`
              found type `fn(&mut Baz, &dyn Foo)`

It should suggest to change the impl method signature to match the trait.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions