-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix the bugs of manual_memcpy, simplify the suggestion and refactor it
#5536
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
Conversation
|
Thanks for splitting up the commits as they are, that makes reviewing significantly more easy 👍 I'll try and review this by the end of the day. |
|
For your question about the tests: You already have them in the PR description, why not just throw them in the test file, with the short comments you wrote, what they are supposed to test? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes LGTM but the 2 tests would indeed be nice to have.
|
Thanks you for your reviews. I've added the 2 tests. |
|
@bors r+ |
|
📌 Commit 461f4a3 has been approved by |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
While I’m working on the long procrastinated work to expand
manual_memcpy(#1670), I found a few minor bugs and probably unidiomatic or old coding style. There is a brief explanation of changes to the behaviour this PR will make below. And, I have a questoin: do I need to add tests for the first and second fixed bugs? I thought it might be too rare cases to include the tests for those. I added for the last one though.Bug fix
It negates resulted offsets (
src/dst_offset) whenoffsetis subtraction by 0. This PR will remove any subtraction by 0 as a part of minification.warning: it looks like you're manually copying between slices --> src/main.rs:2:14 | LL | for i in 0..5 { - | ^^^^ help: try replacing the loop by: `dst[..-5].clone_from_slice(&src[..5])` + | ^^^^ help: try replacing the loop by: `dst[..5].clone_from_slice(&src[..5])` |It prints
RangeToorRangeFullwhen both ofendandoffsetare 0, which have different meaning. This PR will print 0. I could reject the casesendis 0, but I thought I won’t catch other casesreverse_range_loopwill trigger, and it’s over to catch every such cases.warning: it looks like you're manually copying between slices --> src/main.rs:2:14 | LL | for i in 0..0 { - | ^^^^ help: try replacing the loop by: `dst.clone_from_slice(&src[..])` + | ^^^^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0])` |it prints four dots when
endisNone. This PR will ignore anyforloops withoutendbecause aforloop that takesRangeFromas its argument and contains indexing without the statements or the expressions that end loops such asbreakwill definitely panic, andmanual_memcpyshould ignore the loops with such control flow.Simplification of the suggestion
startorendandoffsetare same (from Simplify manual_memcpy suggestion in some cases #3323). This PR will useRangeTochangelog: fixed the bugs of
manual_memcpyand also simplify the suggestion.