Skip to content

Incorrect fix for E0040 on qualified method call #156017

@ada4a

Description

@ada4a

Code

struct Foo;

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

fn foo(mut f: Foo) {
    Drop::drop(&mut f);
}

Current output

error[E0040]: explicit use of destructor method
 --> src/lib.rs:8:5
  |
8 |     Drop::drop(&mut f);
  |     ^^^^^^^^^^
  |     |
  |     explicit destructor calls not allowed
  |     help: consider using `drop` function: `drop`

Desired output

error[E0040]: explicit use of destructor method
 --> src/lib.rs:8:7
  |
8 |     Drop::drop(&mut f);
  |     ^^^^^^^^^^
  |     |
  |     explicit destructor calls not allowed
  |
help: consider using `drop` function
  |
8 -     Drop::drop(&mut f);
8 +     drop(f);
  |

Rationale and extra context

The existing fix results in drop(&mut f), which doesn't actually drop f, as it's behind a reference.

Other cases

error[E0040]: explicit use of destructor method
 --> src/lib.rs:8:7
  |
8 |     f.drop();
  |       ^^^^ explicit destructor calls not allowed
  |
help: consider using `drop` function
  |
8 -     f.drop();
8 +     drop(f);
  |

Rust Version

rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: x86_64-unknown-linux-gnu
release: 1.95.0
LLVM version: 22.1.2

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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions