rust-lang / rust-lang/rust-clippy

`manual_memcpy` does not trigger when a loop uses an iterator

Open
#14,009 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary

manual_memcpy doesn't trigger when an iterator is used within a for loop.

Lint Name

manual_memcpy

Reproducer

I tried this code:

let src = [0; 64];
let mut dst = [0; 128];
for (i, &val) in src.iter().enumerate() {
    dst[i + 64] = val;
}

I expected to see this happen: Pointing out memcpy is being re-implemented.

Instead, this happened: No warnings were emitted.

Version
rustc 1.86.0-nightly (a580b5c37 2025-01-08)
binary: rustc
commit-hash: a580b5c379b4fca50dfe5afc0fc0ce00921e4e00
commit-date: 2025-01-08
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.6

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 manual_memcpy lint and its handling of for loops, then reproduce the reported Rust example using src.iter().enumerate(). Done means the lint emits a warning that the loop reimplements memcpy for this pattern, with coverage for the reproducer.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.