Skip to content

Incmpatible type for trait fn(self) should suggest fn(&mut self) instead of fn(self: &mut TypenameOfSelf) #112036

Closed
@max-ishere

Description

@max-ishere

Code

struct Foo;

impl Drop for Foo {
    fn drop(self) {}
}

Current output

error[E0053]: method `drop` has an incompatible type for trait
  --> src/lib.rs:46:13
   |
46 |     fn drop(self) {
   |             ^^^^
   |             |
   |             expected `&mut Foo`, found struct `Foo`
   |             help: change the self-receiver type to match the trait: `self: &mut Foo`
   |
   = note: expected signature `fn(&mut Foo)`
              found signature `fn(Foo)`

Desired output

error[E0053]: method `drop` has an incompatible type for trait
  --> src/lib.rs:46:13
   |
46 |     fn drop(self) {
   |             ^^^^
   |             |
   |             expected `&mut self`, found `self`
   |             help: change the self-receiver type to match the trait: `&mut self`
   |
   = note: expected signature `fn(&mut Foo)`
              found signature `fn(Foo)`

Rationale and extra context

The compiler asks to fix drop(self) into drop(self: &mut Foo) and then suggests to just have drop(&mut self). It should just straight up say Change self to &mut self

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions