diff options
Diffstat (limited to '')
-rw-r--r-- | src/test/ui/issues/issue-22536-copy-mustnt-zero.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/issues/issue-22536-copy-mustnt-zero.rs b/src/test/ui/issues/issue-22536-copy-mustnt-zero.rs new file mode 100644 index 000000000..017f36484 --- /dev/null +++ b/src/test/ui/issues/issue-22536-copy-mustnt-zero.rs @@ -0,0 +1,28 @@ +// run-pass +// Regression test for Issue #22536: If a type implements Copy, then +// moving it must not zero the original memory. + + +trait Resources { + type Buffer: Copy; + fn foo(&self) {} +} + +struct BufferHandle<R: Resources> { + raw: <R as Resources>::Buffer, +} +impl<R: Resources> Copy for BufferHandle<R> {} +impl<R: Resources> Clone for BufferHandle<R> { + fn clone(&self) -> BufferHandle<R> { *self } +} + +enum Res {} +impl Resources for Res { + type Buffer = u32; +} + +fn main() { + let b: BufferHandle<Res> = BufferHandle { raw: 1 }; + let c = b; + assert_eq!(c.raw, b.raw) +} |