Skip to content

Commit ea8c59e

Browse files
committed
expand: Added a more complete test .
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 #3875 gcc/testsuite/ChangeLog: * rust/compile/issue-3875.rs: New test. Signed-off-by: Jayant Chauhan <[email protected]>
1 parent c35ffdb commit ea8c59e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(no_core)]
2+
#![feature(lang_items)]
3+
#![no_core]
4+
// { dg-options "-w" }
5+
6+
#[lang = "sized"]
7+
pub trait Sized {}
8+
9+
#[lang = "clone"]
10+
pub trait Clone: Sized {
11+
fn clone(&self) -> Self;
12+
}
13+
14+
#[lang = "copy"]
15+
pub trait Copy: Clone {}
16+
17+
#[derive(Clone)] // { dg-error "derive may only be applied to structs, enums and unions" }
18+
fn foo() {}
19+
20+
#[derive(Clone)] // { dg-error "derive may only be applied to structs, enums and unions" }
21+
trait Bar {}
22+
23+
// Valid test: Derive Copy and Clone on a unit struct
24+
#[derive(Copy, Clone)]
25+
struct TupleStruct;

0 commit comments

Comments
 (0)