From: Jayant Chauhan <[email protected]>
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 <[email protected]>
---
gcc/testsuite/rust/compile/issue-3875.rs | 28 ++++++++++++++++++++++++
1 file changed, 28 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3875.rs
diff --git a/gcc/testsuite/rust/compile/issue-3875.rs
b/gcc/testsuite/rust/compile/issue-3875.rs
new file mode 100644
index 00000000000..025cd93d1aa
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3875.rs
@@ -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
--
2.50.1