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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/bde2985a486cf5f5c000fc186f508471cdf20d12

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4359

 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 000000000..025cd93d1
--- /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

base-commit: cfc5ac9dd82f06d8b9cfacd151dd3738e9e995b4
-- 
2.53.0

Reply via email to