collection_is_never_read says never used when hashing

Open
#11,923 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Run the linked Rust Playground reproducer and inspect the collection_is_never_read lint implementation and its tests. Confirm why hashing the collection is treated as unread, then add coverage and ensure the lint no longer reports this reproducer while still detecting genuinely unread collections.

Written by the indexing model from the issue text.

Description

C-bug I-false-positive L-nursery
Summary

Real code:

impl<'ctx, S> Hash for DependencyGraph<'ctx, S> {
    fn hash<H: Hasher>(&self, state: &mut H) {
        let mut ops = Vec::with_capacity(self.edges.len());
        for (from, nodes) in self.edges.values() {
            ops.push(from.get_opcode());
            for node in nodes {
                ops.push(node.get_opcode());
            }
        }
        ops.sort_unstable_by_key(|&op| op as u32);

        ops.hash(state);
    }
}
Lint Name

collection_is_never_read

Reproducer

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f56ee19eab842503346eb77f36c6cb51

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

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.

More from rust-lang/rust-clippy

All issues in rust-lang/rust-clippy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.