Skip to content

mem::replace -> mem::take lint is too aggressive  #5586

Closed
@benesch

Description

@benesch

Clippy will suggest replacing

let x = mem::replace(&mut thing, Thing::default());

with:

let x = mem::take(&mut thing);

This is great! But it will also suggest replacing

mem::replace(&mut thing, Thing::default());

with:

mem::take(&mut thing);

This is not great. The construction using mem::replace in the second case is much clearer IMO as it indicates that the function is being executed for its side effects. The construction using mem::take looks like a mistake.

Would you folks be open to making the lint not apply in the second case?

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveS-needs-discussionStatus: Needs further discussion before merging or work can be startedgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions