Skip to content

fix: [manual_memcpy] reduce indexing suggestions when array length is equal to loop range - #11778

Merged
bors merged 1 commit into
rust-lang:masterfrom
granddaifuku:fix/reduce-indexing-manual_memcpy-when-array-length-is-equal-to-range
Nov 14, 2023
Merged

bors merged 1 commit into
rust-lang:masterfrom
granddaifuku:fix/reduce-indexing-manual_memcpy-when-array-length-is-equal-to-range

Conversation

@granddaifuku

@granddaifuku granddaifuku commented Nov 8, 2023 •

Copy link
Copy Markdown
Contributor

fixes: #11689

This PR improves manual_memcpy suggestions by reducing unnecessary indexing.

For example,

let src = [0, 1, 2, 3, 4];
let mut dest = [0; 4];
for i in 0..4 {
    dest[i] = src[i];
{

Clippy suggests dest[..4].copy_from_slice(&src[..4]);.
I reduced this suggestion as dest.copy_from_slice(&src[..4]);. (Removed needless indexing.)

changelog: [manual_memcpy]: Reduce indexing suggestions when array length is equal to loop range

@rustbot

rustbot commented Nov 8, 2023

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @blyxyas (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 8, 2023

@blyxyas blyxyas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good first iteration, just some minor fixes and I think this should be merge-ready!

Comment thread clippy_lints/src/loops/manual_memcpy.rs Outdated
Comment thread clippy_lints/src/loops/manual_memcpy.rs
Comment thread clippy_lints/src/loops/manual_memcpy.rs

@blyxyas blyxyas left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks for you first contribution and welcome to Clippy! ❤️
Could you please squash these 4 commits into a single one?

@granddaifuku
granddaifuku force-pushed the fix/reduce-indexing-manual_memcpy-when-array-length-is-equal-to-range branch from 4e85e41 to cb528e7 Compare November 14, 2023 11:39
@granddaifuku

Copy link
Copy Markdown
Contributor Author

It appears that the if_chain macro has been removed in #11750, leading to a CI failure. I will provide a fix for this issue.

…oop range

Format

refactor: extract function to shrink function length

fix: remove cmp to calculate range

fix: replace if_chain with let chains
@granddaifuku
granddaifuku force-pushed the fix/reduce-indexing-manual_memcpy-when-array-length-is-equal-to-range branch from cb528e7 to a9d42e6 Compare November 14, 2023 13:10
@granddaifuku

Copy link
Copy Markdown
Contributor Author

I squashed my commits into one, and I really appreciate your guidance!

@blyxyas

blyxyas commented Nov 14, 2023

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Nov 14, 2023

Copy link
Copy Markdown
Contributor

📌 Commit a9d42e6 has been approved by blyxyas

It is now in the queue for this repository.

@bors

bors commented Nov 14, 2023

Copy link
Copy Markdown
Contributor

⌛ Testing commit a9d42e6 with merge ca8f33e...

@bors

bors commented Nov 14, 2023

Copy link
Copy Markdown
Contributor

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: blyxyas
Pushing ca8f33e to master...

@bors
bors merged commit ca8f33e into rust-lang:master Nov 14, 2023
@granddaifuku
granddaifuku deleted the fix/reduce-indexing-manual_memcpy-when-array-length-is-equal-to-range branch November 14, 2023 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

manual_memcpy suggest slicing array when not necessary

4 participants