rust-lang / rust-lang/rust-clippy

New lint: replace place statement with drop(place)

Open
#5,206 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint L-complexity
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

As featured in this Twitter poll.

The statement <place>; causes a move from and drop of the value at place. For clarity of intent, this is better written as drop(<place>); to emphasize the destructor is what is being invoked.

> 65% of votes on the linked poll had intuition that this (var;) did not invoke the destructor, so this lint would definitely help avoid potentially misleading code. (rustc does already lint this as path_statements, so perhaps this should instead be an improvement to that lint. https://github.com/rust-lang/rust/issues/48852 is a 2018 issue to remove the lint (which is currently incorrect) for path statements that invoke a destructor.

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 reading Clippy's existing handling of rustc's path_statements lint and the linked discussion in rust-lang/rust#48852. The change is complete when place statements that move and drop a value are clearly diagnosed and drop(<place>); is recommended, without incorrectly covering cases where the behavior differs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.