We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f69c5aa commit af44a2aCopy full SHA for af44a2a
library/core/tests/cell.rs
@@ -327,6 +327,29 @@ fn cell_exterior() {
327
assert_eq!(b.get().z, 13);
328
}
329
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
353
#[test]
354
fn refcell_default() {
355
let cell: RefCell<u64> = Default::default();
src/test/ui/cell-does-not-clone.rs
0 commit comments