Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

granddaifuku
Copy link
Contributor

@granddaifuku granddaifuku commented Nov 8, 2023

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
Copy link
Collaborator

rustbot commented Nov 8, 2023

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
Copy link
Member

@blyxyas blyxyas left a comment

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!

clippy_lints/src/loops/manual_memcpy.rs Outdated Show resolved Hide resolved
clippy_lints/src/loops/manual_memcpy.rs Show resolved Hide resolved
Copy link
Member

@blyxyas blyxyas left a comment

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
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
Contributor Author

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

@blyxyas
Copy link
Member

blyxyas commented Nov 14, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 14, 2023

📌 Commit a9d42e6 has been approved by blyxyas

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Nov 14, 2023

⌛ Testing commit a9d42e6 with merge ca8f33e...

@bors
Copy link
Collaborator

bors commented Nov 14, 2023

☀️ 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
5 checks passed
@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