Skip to content

Commit ea74997

Browse files
committed
Add a test checking the output of builtin derives.
1 parent 788dded commit ea74997

File tree

2 files changed

+1163
-0
lines changed

2 files changed

+1163
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// check-pass
2+
// compile-flags: -Zunpretty=expanded
3+
// edition:2021
4+
//
5+
// This test checks the code generated for all[*] the builtin derivable traits
6+
// on a variety of structs and enums. It protects against accidental changes to
7+
// the generated code, and makes deliberate changes to the generated code
8+
// easier to review.
9+
//
10+
// [*] It excludes `Copy` in some cases, because that changes the code
11+
// generated for `Clone`.
12+
//
13+
// [*] It excludes `RustcEncodable` and `RustDecodable`, which are obsolete and
14+
// also require the `rustc_serialize` crate.
15+
16+
#![crate_type = "lib"]
17+
#![allow(dead_code)]
18+
#![allow(deprecated)]
19+
20+
// Empty struct.
21+
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
22+
struct Empty;
23+
24+
// A basic struct.
25+
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
26+
struct Point {
27+
x: u32,
28+
y: u32,
29+
}
30+
31+
// A long struct.
32+
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
33+
struct Big {
34+
b1: u32, b2: u32, b3: u32, b4: u32, b5: u32, b6: u32, b7: u32, b8:u32,
35+
}
36+
37+
// A C-like, fieldless enum.
38+
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
39+
enum Fieldless {
40+
#[default]
41+
A,
42+
B,
43+
C,
44+
}
45+
46+
// An enum with multiple fieldless and fielded variants.
47+
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
48+
enum Mixed {
49+
#[default]
50+
P,
51+
Q,
52+
R(u32),
53+
S { d1: u32, d2: u32 },
54+
}
55+
56+
// An enum with no fieldless variants. Note that `Default` cannot be derived
57+
// for this enum.
58+
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
59+
enum Fielded {
60+
X(u32),
61+
Y(bool),
62+
Z(Option<i32>),
63+
}

0 commit comments

Comments
 (0)