2 // compile-flags: -Zunpretty=expanded
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
10 // [*] It excludes `Copy` in some cases, because that changes the code
11 // generated for `Clone`.
13 // [*] It excludes `RustcEncodable` and `RustDecodable`, which are obsolete and
14 // also require the `rustc_serialize` crate.
16 #![crate_type = "lib"]
21 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
25 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
32 #[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
34 b1: u32, b2: u32, b3: u32, b4: u32, b5: u32, b6: u32, b7: u32, b8: u32,
37 // A struct with an unsized field. Some derives are not usable in this case.
38 #[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
39 struct Unsized([u32]);
41 // A packed tuple struct that impls `Copy`.
42 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
44 struct PackedCopy(u32);
46 // A packed tuple struct that does not impl `Copy`. Note that the alignment of
47 // the field must be 1 for this code to be valid. Otherwise it triggers an
48 // error "`#[derive]` can't be used on a `#[repr(packed)]` struct that does not
49 // derive Copy (error E0133)" at MIR building time. This is a weird case and
50 // it's possible that this struct is not supposed to work, but for now it does.
51 #[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
53 struct PackedNonCopy(u8);
56 #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
59 // A single-variant enum.
60 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
65 // A C-like, fieldless enum with a single variant.
66 #[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
72 // A C-like, fieldless enum.
73 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
81 // An enum with multiple fieldless and fielded variants.
82 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
88 S { d1: u32, d2: u32 },
91 // An enum with no fieldless variants. Note that `Default` cannot be derived
93 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
100 // A union. Most builtin traits are not derivable for unions.
101 #[derive(Clone, Copy)]