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.
13 #![warn(clippy::clone_on_ref_ptr)]
16 use std::cell::RefCell;
17 use std::collections::HashSet;
18 use std::collections::VecDeque;
19 use std::rc::{self, Rc};
20 use std::sync::{self, Arc};
24 impl SomeTrait for SomeImpl {}
31 vec![1].clone(); // ok, not a Copy type
32 Some(vec![1]).clone(); // ok, not a Copy type
35 let rc = RefCell::new(0);
39 fn clone_on_ref_ptr() {
40 let rc = Rc::new(true);
41 let arc = Arc::new(true);
43 let rcweak = Rc::downgrade(&rc);
44 let arc_weak = Arc::downgrade(&arc);
53 rc::Weak::clone(&rcweak);
56 sync::Weak::clone(&arc_weak);
58 let x = Arc::new(SomeImpl);
59 let _: Arc<SomeTrait> = x.clone();
62 fn clone_on_copy_generic<T: Copy>(t: T) {
68 fn clone_on_double_ref() {
71 let z: &Vec<_> = y.clone();
73 println!("{:p} {:p}",*y, z);
76 fn iter_clone_collect() {
78 let v2 : Vec<isize> = v.iter().cloned().collect();
79 let v3 : HashSet<isize> = v.iter().cloned().collect();
80 let v4 : VecDeque<isize> = v.iter().cloned().collect();