2 //! Test that #[derive(Copy, Clone)] produces a shallow copy
3 //! even when a member violates RFC 1521
5 use std::sync::atomic::{AtomicBool, Ordering};
7 /// A struct that pretends to be Copy, but actually does something
12 /// Static cooperating with the rogue Clone impl
13 static CLONED: AtomicBool = AtomicBool::new(false);
16 fn clone(&self) -> Self {
17 // this makes Clone vs Copy observable
18 CLONED.store(true, Ordering::SeqCst);
24 /// This struct is actually Copy... at least, it thinks it is!
25 #[derive(Copy, Clone)]
26 struct Innocent(#[allow(unused_tuple_struct_fields)] Liar);
35 let _ = Innocent::new().clone();
36 // if Innocent was byte-for-byte copied, CLONED will still be false
37 assert!(!CLONED.load(Ordering::SeqCst));