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.
10 #![warn(clippy::clone_on_ref_ptr)]
13 use std::cell::RefCell;
14 use std::collections::HashSet;
15 use std::collections::VecDeque;
16 use std::rc::{self, Rc};
17 use std::sync::{self, Arc};
21 impl SomeTrait for SomeImpl {}
28 vec![1].clone(); // ok, not a Copy type
29 Some(vec![1]).clone(); // ok, not a Copy type
32 let rc = RefCell::new(0);
36 fn clone_on_ref_ptr() {
37 let rc = Rc::new(true);
38 let arc = Arc::new(true);
40 let rcweak = Rc::downgrade(&rc);
41 let arc_weak = Arc::downgrade(&arc);
50 rc::Weak::clone(&rcweak);
53 sync::Weak::clone(&arc_weak);
55 let x = Arc::new(SomeImpl);
56 let _: Arc<SomeTrait> = x.clone();
59 fn clone_on_copy_generic<T: Copy>(t: T) {
65 fn clone_on_double_ref() {
68 let z: &Vec<_> = y.clone();
70 println!("{:p} {:p}", *y, z);
73 fn iter_clone_collect() {
74 let v = [1, 2, 3, 4, 5];
75 let v2: Vec<isize> = v.iter().cloned().collect();
76 let v3: HashSet<isize> = v.iter().cloned().collect();
77 let v4: VecDeque<isize> = v.iter().cloned().collect();
85 #[derive(Copy, Clone)]
88 macro_rules! impl_deref {
89 ($src:ident, $dst:ident) => {
90 impl std::ops::Deref for $src {
92 fn deref(&self) -> &Self::Target {
102 impl std::ops::Deref for D {
103 type Target = &'static E;
104 fn deref(&self) -> &Self::Target {
111 let _: E = a.clone();