1 // does not test any rustfixable lints
3 #![warn(clippy::clone_on_ref_ptr)]
6 use std::cell::RefCell;
7 use std::rc::{self, Rc};
8 use std::sync::{self, Arc};
12 impl SomeTrait for SomeImpl {}
19 vec![1].clone(); // ok, not a Copy type
20 Some(vec![1]).clone(); // ok, not a Copy type
23 let rc = RefCell::new(0);
28 let _ = &x.clone(); // ok, getting a ref
29 'a'.clone().make_ascii_uppercase(); // ok, clone and then mutate
32 fn clone_on_ref_ptr() {
33 let rc = Rc::new(true);
34 let arc = Arc::new(true);
36 let rcweak = Rc::downgrade(&rc);
37 let arc_weak = Arc::downgrade(&arc);
46 rc::Weak::clone(&rcweak);
49 sync::Weak::clone(&arc_weak);
51 let x = Arc::new(SomeImpl);
52 let _: Arc<dyn SomeTrait> = x.clone();
55 fn clone_on_copy_generic<T: Copy>(t: T) {
61 fn clone_on_double_ref() {
64 let z: &Vec<_> = y.clone();
66 println!("{:p} {:p}", *y, z);
74 #[derive(Copy, Clone)]
77 macro_rules! impl_deref {
78 ($src:ident, $dst:ident) => {
79 impl std::ops::Deref for $src {
81 fn deref(&self) -> &Self::Target {
91 impl std::ops::Deref for D {
92 type Target = &'static E;
93 fn deref(&self) -> &Self::Target {
100 let _: E = a.clone();