rust-lang / rust-lang/rust-clippy

significant_drop_tightening false positive on loops

Open
#15,510 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

I want to lock my RwLock before the Loop so i don't have to lock it on every iteration saving performance

let mut entities = world.entities.write().await;
for (uuid, entity_nbt) in &chunk.read().await.data {
     ...
     entities.remove(&base_entity.entity_uuid);
}

when having significant_drop_tightening enabled it suggests me to use this, inside the loop

world.entities.write().await.remove(&base_entity.entity_uuid);
Lint Name

significant_drop_tightening

Reproducer

I tried this code:

let mut entities = world.entities.write().await;
for (uuid, entity_nbt) in &chunk.read().await.data {
     ...
     entities.remove(&base_entity.entity_uuid);
}

I saw this happen:

world.entities.write().await.remove(&base_entity.entity_uuid);

I expected to see this happen:

Version
1.89
Additional Labels

No response

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 with the significant_drop_tightening lint and its handling of the reproducer's lock outside the loop. Determine why the suggestion moves the write lock into each iteration, then add a regression case showing that the existing lock should be retained and verify the lint no longer emits this suggestion.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.