diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-05-12 15:14:49 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:46:24 +0100 |
commit | c566f9081067c9328a0f07bcc8bac46dc69d1599 (patch) | |
tree | f7fa63c5e5720d0054bd8c46061b6e7741154114 /gcc/testsuite/rust/compile | |
parent | e16397e9963212d8c47fd0cd51544ba373e32172 (diff) | |
download | gcc-c566f9081067c9328a0f07bcc8bac46dc69d1599.zip gcc-c566f9081067c9328a0f07bcc8bac46dc69d1599.tar.gz gcc-c566f9081067c9328a0f07bcc8bac46dc69d1599.tar.bz2 |
gccrs: derive: Add proper derive(Clone) for unions
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (AstBuilder::struct_expr_struct): New function.
(AstBuilder::let): Likewise.
(AstBuilder::struct_expr): Likewise.
(AstBuilder::struct_expr_field): Likewise.
(AstBuilder::field_access): Likewise.
(AstBuilder::wildcard): Likewise.
* ast/rust-ast-builder.h: Likewise.
* expand/rust-derive-clone.cc (DeriveClone::visit_union): Implement
properly.
gcc/testsuite/ChangeLog:
* rust/compile/derive_macro4.rs: New test.
* rust/compile/derive_macro6.rs: New test.
Diffstat (limited to 'gcc/testsuite/rust/compile')
-rw-r--r-- | gcc/testsuite/rust/compile/derive_macro4.rs | 16 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/derive_macro6.rs | 21 |
2 files changed, 37 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/derive_macro4.rs b/gcc/testsuite/rust/compile/derive_macro4.rs new file mode 100644 index 0000000..564555f --- /dev/null +++ b/gcc/testsuite/rust/compile/derive_macro4.rs @@ -0,0 +1,16 @@ +pub trait Copy {} +pub trait Clone { + fn clone(&self) -> Self; +} + +struct PhantomData<T>; + +pub struct AssertParamIsCopy<T: Copy> { + _field: PhantomData<T>, +} + +#[derive(Clone)] // { dg-error "bounds not satisfied for U .Copy. is not satisfied" } +union U { + i: i32, + f: f64, +} diff --git a/gcc/testsuite/rust/compile/derive_macro6.rs b/gcc/testsuite/rust/compile/derive_macro6.rs new file mode 100644 index 0000000..0254754 --- /dev/null +++ b/gcc/testsuite/rust/compile/derive_macro6.rs @@ -0,0 +1,21 @@ +pub trait Copy {} +pub trait Clone { + fn clone(&self) -> Self; +} + +#[lang = "phantom_data"] +pub struct PhantomData<T>; + +pub struct AssertParamIsCopy<T: Copy> { + pub _field: PhantomData<T>, +} + +impl Copy for i32 {} +impl Copy for i64 {} +impl Copy for U {} + +#[derive(Clone)] +union U { + i: i32, + f: f64, +} |