]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: expand: Added a more complete test
authorJayant Chauhan <0001jayant@gmail.com>
Tue, 6 Jan 2026 10:09:23 +0000 (15:39 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 14 Apr 2026 21:48:37 +0000 (23:48 +0200)
This patch adds a regression test ensuring that deriving on invalid items
(such as functions or traits) triggers a diagnostic error instead of an
Internal Compiler Error (ICE). It also verifies that Tuple Structs are
accepted as valid targets for derivation.

Fixes Rust-GCC#3875

gcc/testsuite/ChangeLog:

* rust/compile/issue-3875.rs: New test.

Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
gcc/testsuite/rust/compile/issue-3875.rs [new file with mode: 0644]

diff --git a/gcc/testsuite/rust/compile/issue-3875.rs b/gcc/testsuite/rust/compile/issue-3875.rs
new file mode 100644 (file)
index 0000000..025cd93
--- /dev/null
@@ -0,0 +1,28 @@
+#![crate_type = "lib"]
+#![feature(no_core)]
+#![feature(lang_items)]
+#![no_core]
+// { dg-options "-w" }
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "clone"]
+pub trait Clone: Sized {
+    fn clone(&self) -> Self;
+}
+
+#[lang = "copy"]
+pub trait Copy: Clone {}
+
+#[derive(Clone)] // { dg-error "derive may only be applied to structs, enums and unions" }
+fn foo() {}
+
+#[derive(Clone)] // { dg-error "derive may only be applied to structs, enums and unions" }
+trait Bar {}
+
+// Valid test: Derive Copy and Clone on a unit struct
+#[derive(Copy, Clone)]
+struct TupleStruct;
+
+// { dg-prune-output "could not resolve" }
\ No newline at end of file