rust-lang / rust-lang/rust-clippy

New lint: manual_memmove

Open
#8,335 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What it does

Like manual_memcpy, find for-loops equivalent to slice::copy_within.

Lint Name

manual_memmove

Category

perf

Advantage

It's shorter and faster.

Drawbacks

any case where memmove is not actually faster? (should probably file as bug against rust though)

Example
let mut arr: [u8; 4] = [1, 2, 3, 4];
                                     
for i in 0..2 {
    arr[i] = arr[i + 2];
}

Could be written as:

arr.copy_within(2..4, 0);

Implementation notes

More generally:

for i in a..b {
    arr[i] = arr[i + offset];
}

Could be written as:

arr.copy_within((a + offset)..(b + offset), a);

Definetly need to look at implementation of manual_memmove and its tests to cover all the edgecases around false-positives here.

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 the existing manual_memmove implementation and its tests, then compare them with the proposed for-loop pattern and the slice::copy_within behavior. Extend coverage for overlapping ranges and other edge cases, while checking for false positives. Done means the lint recognizes valid manual memmove loops without suggesting incorrect replacements.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.