Skip to content

Commit af44a2a

Browse files
committed
move 'cell does not clone' test
1 parent f69c5aa commit af44a2a

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

Diff for: library/core/tests/cell.rs

+23
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,29 @@ fn cell_exterior() {
327327
assert_eq!(b.get().z, 13);
328328
}
329329

330+
#[test]
331+
fn cell_does_not_clone() {
332+
#[derive(Copy)]
333+
#[allow(dead_code)]
334+
struct Foo {
335+
x: isize,
336+
}
337+
338+
impl Clone for Foo {
339+
fn clone(&self) -> Foo {
340+
// Using Cell in any way should never cause clone() to be
341+
// invoked -- after all, that would permit evil user code to
342+
// abuse `Cell` and trigger crashes.
343+
344+
panic!();
345+
}
346+
}
347+
348+
let x = Cell::new(Foo { x: 22 });
349+
let _y = x.get();
350+
let _z = x.clone();
351+
}
352+
330353
#[test]
331354
fn refcell_default() {
332355
let cell: RefCell<u64> = Default::default();

Diff for: src/test/ui/cell-does-not-clone.rs

-26
This file was deleted.

0 commit comments

Comments
 (0)