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

False positive for clone_on_copy when the clone is immediately borrowed #1472

Closed
scurest opened this issue Jan 25, 2017 · 1 comment
Closed
Labels
C-bug Category: Clippy is not doing the correct thing E-needs-mcve Call for participation: This issue needs a Minimal Complete and Verifiable Example I-false-positive Issue: The lint was triggered on code it shouldn't have T-middle Type: Probably requires verifiying types

Comments

@scurest
Copy link
Contributor

scurest commented Jan 25, 2017

Consider

extern crate rand;
use rand::Rng;

let r = rand::ChaChaRng::new_unseeded(); // ChaChaRng implements Copy
let x = r.clone().next_u32(); // peek at next u32, without modifying r

This triggers clone_on_copy, suggesting removing the clone call. Taking the suggestion is illegal because r is not mutable. If it were mutable, taking the suggestion would change the behavior of the program.

So it seems like we don't want to lint when the clone is immediately borrowed mutably.

You can also observe a difference (using ref_eq for example) when the clone is borrowed immutably, so perhaps it's better to lint only if the clone is immediately moved from?

@scurest scurest changed the title False positive for clone_on_copy when the clone is immeadiately borrowed False positive for clone_on_copy when the clone is immediately borrowed Jan 25, 2017
@mcarton mcarton added C-bug Category: Clippy is not doing the correct thing T-middle Type: Probably requires verifiying types labels Jan 25, 2017
@phansch phansch added E-needs-mcve Call for participation: This issue needs a Minimal Complete and Verifiable Example I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 21, 2020
@Jarcho
Copy link
Contributor

Jarcho commented Mar 28, 2021

This was fixed in 7d7fef1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-needs-mcve Call for participation: This issue needs a Minimal Complete and Verifiable Example I-false-positive Issue: The lint was triggered on code it shouldn't have T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

5 participants