New lint: swap_with_temporary
#14046
Open
+409
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This lint detects inefficient or useless
{std,core}::mem::swap()
calls such as:It also takes care of using a form appropriate for a
()
context ifswap()
is part of a larger expression (don't ask me why this wouldn't happen, I have no idea), by suggesting{ x = y; }
(statement in block) or{std,core}::mem::drop((temp1(), temp2())
.changelog: [
swap_with_temporary
]: new lintClose #1968