summary refs log tree commit diff
path: root/src/test/ui/cell-does-not-clone.rs
blob: 587447b54b7fdc038eced045ea862bf0108ed87d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// run-pass

#![allow(dead_code)]

use std::cell::Cell;

#[derive(Copy)]
struct Foo {
    x: isize
}

impl Clone for Foo {
    fn clone(&self) -> Foo {
        // Using Cell in any way should never cause clone() to be
        // invoked -- after all, that would permit evil user code to
        // abuse `Cell` and trigger crashes.

        panic!();
    }
}

pub fn main() {
    let x = Cell::new(Foo { x: 22 });
    let _y = x.get();
    let _z = x.clone();
}