Closed
Description
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?