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

Add new lint manual_memmove #8337

Closed
wants to merge 2 commits into from

Conversation

untitaker
Copy link
Contributor

@untitaker untitaker commented Jan 23, 2022

Add a very basic lint that checks against unnecessary reimplementations of copy_within. The lint reuses some now-public parts of the memcpy lint, but supports almost none of the fanciness that the memcpy lint has. The main reason being that overlapping indices/ranges change behavior in memmove, but do not in memcpy (because src is immutable). The secondary reason being that this is my first lint.

Fixes #8335


changelog: New lint [manual_memmove]

@untitaker untitaker marked this pull request as draft January 23, 2022 03:54
@untitaker
Copy link
Contributor Author

Still found some bugs, ignore.

LL | | // left shift by 4
LL | | arr[i] = arr[i + 4];
LL | | }
| |_____^ help: try replacing the loop by: `arr.copy_within(4..((arr.len() - 4) + 4), 0);`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The range bound could be simplified. My suspicion is that MinifyingSugg doesn't work properly here, but I would be "fine" with this output.

@untitaker untitaker marked this pull request as ready for review January 23, 2022 12:45
@untitaker untitaker changed the title Add minimally viable lint for reimplementations of memmove Add new lint manual_memmove Jan 23, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Jan 24, 2022

Is there a reason you didn't just add a small extension to manual_memcpy to handle when the source and destination are the same? The detection code should be identical between this ant manual_memcpy.

I would consider using the same lint as well, possibly renaming to something a little more general.

if let Some(big_sugg) = big_sugg {
span_lint_and_sugg(
cx,
MANUAL_MEMCPY,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to change this

@untitaker
Copy link
Contributor Author

@Jarcho i'll try that next time I work on this, indeed i was reusing a lot of stuff from manual_memcpy, but that comes from cargo-cult, and the potential future challenges with manual_memmove (see testcases) are quite different

@flip1995
Copy link
Member

r? @flip1995 (Is highfive awake?)

@flip1995
Copy link
Member

Wat?

@flip1995 flip1995 assigned flip1995 and unassigned Manishearth Jan 24, 2022
@flip1995 flip1995 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 1, 2022
@bors
Copy link
Collaborator

bors commented Mar 2, 2022

☔ The latest upstream changes (presumably #8174) made this pull request unmergeable. Please resolve the merge conflicts.

@blyxyas
Copy link
Member

blyxyas commented Oct 6, 2023

@untitaker are you interested in continuing with this lint? Or should it be closed ヘ(^・ω・^=)~

@untitaker untitaker closed this Oct 6, 2023
@untitaker untitaker deleted the new-lint-memmove branch October 6, 2023 21:50
@untitaker
Copy link
Contributor Author

untitaker commented Oct 6, 2023

I think this lint was kind of in an OK state from what I can remember but could use further refactor to deduplicate code. No real desire to work on it right now

@blyxyas
Copy link
Member

blyxyas commented Oct 6, 2023

Don't worry, no hard feelings (and you left some public work already done for future contributors). Have fun on other projects! (●ↀωↀ●) ❤️

@flip1995 flip1995 added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive-closed Status: Closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint: manual_memmove
6 participants