Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
max-ishere opened this issue May 28, 2023 · 2 comments · Fixed by #112057
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@max-ishere
Copy link

max-ishere commented May 28, 2023

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

@max-ishere max-ishere added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 28, 2023
@mu001999
Copy link
Contributor

@rustbot claim

@compiler-errors
Copy link
Member

For the record, this line needs to be fixed:

let sugg = match ExplicitSelf::determine(ty, |_| ty == impl_trait_ref.self_ty()) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants