1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
11 #![feature(tool_lints)]
13 #![warn(clippy::clone_on_ref_ptr)]
16 use std::collections::HashSet;
17 use std::collections::VecDeque;
18 use std::rc::{self, Rc};
19 use std::sync::{self, Arc};
23 impl SomeTrait for SomeImpl {}
30 vec![1].clone(); // ok, not a Copy type
31 Some(vec![1]).clone(); // ok, not a Copy type
35 fn clone_on_ref_ptr() {
36 let rc = Rc::new(true);
37 let arc = Arc::new(true);
39 let rcweak = Rc::downgrade(&rc);
40 let arc_weak = Arc::downgrade(&arc);
49 rc::Weak::clone(&rcweak);
52 sync::Weak::clone(&arc_weak);
54 let x = Arc::new(SomeImpl);
55 let _: Arc<SomeTrait> = x.clone();
58 fn clone_on_copy_generic<T: Copy>(t: T) {
64 fn clone_on_double_ref() {
67 let z: &Vec<_> = y.clone();
69 println!("{:p} {:p}",*y, z);
72 fn iter_clone_collect() {
74 let v2 : Vec<isize> = v.iter().cloned().collect();
75 let v3 : HashSet<isize> = v.iter().cloned().collect();
76 let v4 : VecDeque<isize> = v.iter().cloned().collect();