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

Lint calling mem::swap on a reference #1968

Open
pengowen123 opened this issue Aug 18, 2017 · 2 comments · May be fixed by #14046
Open

Lint calling mem::swap on a reference #1968

pengowen123 opened this issue Aug 18, 2017 · 2 comments · May be fixed by #14046
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-correctness Lint: Belongs in the correctness lint group S-needs-discussion Status: Needs further discussion before merging or work can be started T-middle Type: Probably requires verifiying types

Comments

@pengowen123
Copy link
Contributor

It is possible to accidentally swap references instead of the data itself, just like it is possible to call mem::drop on a reference. It may be useful in some cases to swap references to something like slices, but the lint could be disabled in those cases or just be allow by default.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 18, 2017

I'm not sure about this one. We should add it as allow by default and run it on some crates

@oli-obk oli-obk added L-correctness Lint: Belongs in the correctness lint group S-needs-discussion Status: Needs further discussion before merging or work can be started good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-middle Type: Probably requires verifiying types labels Aug 18, 2017
@pengowen123
Copy link
Contributor Author

I think limiting this lint to references that are temporaries, such as a function returning a reference, would fit most cases. For example, doing mem::swap(&mut self.foo(), &mut self.bar()), where foo and bar return references to something, should warn, because it can't do anything useful. However, this shouldn't warn:

let mut x = &5;
let mut y = &7;
mem::swap(&mut x, &mut y);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-correctness Lint: Belongs in the correctness lint group S-needs-discussion Status: Needs further discussion before merging or work can be started T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants