aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/compile
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2025-01-30 13:10:51 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-24 13:07:02 +0100
commitd8dc928bad2854129eb7ae28cd6dc694f98fb47f (patch)
tree5d971a950dd3bab88406d5b064736a18cfd3f911 /gcc/testsuite/rust/compile
parent5d1ba7c2243d9bb36718f83322a26e0ce13f89fd (diff)
downloadgcc-d8dc928bad2854129eb7ae28cd6dc694f98fb47f.zip
gcc-d8dc928bad2854129eb7ae28cd6dc694f98fb47f.tar.gz
gcc-d8dc928bad2854129eb7ae28cd6dc694f98fb47f.tar.bz2
gccrs: derive(Default): Add implementation
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::derive): Call DeriveDefault. * expand/rust-derive-default.cc: New file. * expand/rust-derive-default.h: New file. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/derive-default1.rs: New test. * rust/execute/torture/derive-default1.rs: New test. * rust/compile/nr2/exclude: Exclude them.
Diffstat (limited to 'gcc/testsuite/rust/compile')
-rw-r--r--gcc/testsuite/rust/compile/derive-default1.rs29
-rw-r--r--gcc/testsuite/rust/compile/nr2/exclude1
2 files changed, 30 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/derive-default1.rs b/gcc/testsuite/rust/compile/derive-default1.rs
new file mode 100644
index 0000000..902c65e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/derive-default1.rs
@@ -0,0 +1,29 @@
+#[derive(Default)]
+struct Foo { _a: i32, _b: i64, _c: u8 }
+
+#[lang = "sized"]
+trait Sized {}
+
+mod core {
+ mod default {
+ trait Default: Sized {
+ fn default() -> Self;
+ }
+
+ impl Default for i32 {
+ fn default() -> Self { 0 }
+ }
+
+ impl Default for i64 {
+ fn default() -> Self { 27 }
+ }
+
+ impl Default for u8 {
+ fn default() -> Self { 18 }
+ }
+ }
+}
+
+fn main() {
+ let _ = Foo::default();
+}
diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude
index 8229b54..f8e280e 100644
--- a/gcc/testsuite/rust/compile/nr2/exclude
+++ b/gcc/testsuite/rust/compile/nr2/exclude
@@ -124,4 +124,5 @@ traits12.rs
try-trait.rs
derive-debug1.rs
issue-3382.rs
+derive-default1.rs
# please don't delete the trailing newline