Skip to content

Commit ab1d19a

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 <0001jayant@gmail.com>
1 parent c35ffdb commit ab1d19a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
#[lang = "copy"]
16+
pub trait Copy: Clone {}
17+
18+
#[derive(Clone)] // { dg-error "derive may only be applied to structs, enums and unions" }
19+
fn foo() {}
20+
21+
#[derive(Clone)] // { dg-error "derive may only be applied to structs, enums and unions" }
22+
trait Bar {}
23+
24+
// Valid test: Derive Copy and Clone on a unit struct
25+
#[derive(Copy, Clone)]
26+
struct TupleStruct;

0 commit comments

Comments
 (0)