rust-lang / rust-lang/rust-clippy

The lint docs misrepresent trait `Drop`

Open
#9,227 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-documentation C-enhancement
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

The reason why Drop is a trait is because adding a drop method to a type is similar to implementing a trait on it.
Other than that, Drop does not really behave like a trait. If a type doesn’t implement Drop, then that doesn’t mean it lacks destructor code. For instance, String and HashMap currently don’t implement it.

Instead, core::mem::needs_drop::<T>() is used to check if dropping a T invokes a destructor.

drop_non_drop and forget_non_drop should ideally not mention the trait Drop in their name or documentation, it is misleading.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the definitions and documentation for the drop_non_drop and forget_non_drop lints. Compare their wording with core::mem::needs_drop::<T>() and determine how the lint names and documentation should avoid implying that only types implementing Drop have destructor code; done means the misleading references are corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.