Skip to content

Commit e86d43c

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 e86d43c

File tree

1 file changed

+23
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)