Skip to content

Commit e8de2e4

Browse files
committed
Add test for unused in builtin derives
1 parent f8dd09b commit e8de2e4

File tree

2 files changed

+308
-30
lines changed

2 files changed

+308
-30
lines changed

src/test/ui/deriving/deriving-all-codegen.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-pass
2-
// compile-flags: -Zunpretty=expanded
32
// edition:2021
3+
// revisions: check unpretty
4+
// [unpretty] compile-flags: -Zunpretty=expanded
45
//
56
// This test checks the code generated for all[*] the builtin derivable traits
67
// on a variety of structs and enums. It protects against accidental changes to
@@ -14,34 +15,33 @@
1415
// also require the `rustc_serialize` crate.
1516

1617
#![crate_type = "lib"]
17-
#![allow(dead_code)]
18-
#![allow(deprecated)]
18+
#![warn(unused)] // test that lints are not triggerred in derived code
1919

2020
// Empty struct.
2121
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
22-
struct Empty;
22+
pub struct Empty;
2323

2424
// A basic struct.
2525
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
26-
struct Point {
26+
pub struct Point {
2727
x: u32,
2828
y: u32,
2929
}
3030

3131
// A large struct.
3232
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
33-
struct Big {
33+
pub struct Big {
3434
b1: u32, b2: u32, b3: u32, b4: u32, b5: u32, b6: u32, b7: u32, b8: u32,
3535
}
3636

3737
// A struct with an unsized field. Some derives are not usable in this case.
3838
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
39-
struct Unsized([u32]);
39+
pub struct Unsized([u32]);
4040

4141
// A packed tuple struct that impls `Copy`.
4242
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
4343
#[repr(packed)]
44-
struct PackedCopy(u32);
44+
pub struct PackedCopy(u32);
4545

4646
// A packed tuple struct that does not impl `Copy`. Note that the alignment of
4747
// the field must be 1 for this code to be valid. Otherwise it triggers an
@@ -50,28 +50,28 @@ struct PackedCopy(u32);
5050
// it's possible that this struct is not supposed to work, but for now it does.
5151
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
5252
#[repr(packed)]
53-
struct PackedNonCopy(u8);
53+
pub struct PackedNonCopy(u8);
5454

5555
// An empty enum.
5656
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
57-
enum Enum0 {}
57+
pub enum Enum0 {}
5858

5959
// A single-variant enum.
6060
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
61-
enum Enum1 {
61+
pub enum Enum1 {
6262
Single { x: u32 }
6363
}
6464

6565
// A C-like, fieldless enum with a single variant.
6666
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
67-
enum Fieldless1 {
67+
pub enum Fieldless1 {
6868
#[default]
6969
A,
7070
}
7171

7272
// A C-like, fieldless enum.
7373
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
74-
enum Fieldless {
74+
pub enum Fieldless {
7575
#[default]
7676
A,
7777
B,
@@ -80,7 +80,7 @@ enum Fieldless {
8080

8181
// An enum with multiple fieldless and fielded variants.
8282
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
83-
enum Mixed {
83+
pub enum Mixed {
8484
#[default]
8585
P,
8686
Q,
@@ -91,7 +91,7 @@ enum Mixed {
9191
// An enum with no fieldless variants. Note that `Default` cannot be derived
9292
// for this enum.
9393
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
94-
enum Fielded {
94+
pub enum Fielded {
9595
X(u32),
9696
Y(bool),
9797
Z(Option<i32>),
@@ -104,3 +104,20 @@ pub union Union {
104104
pub u: u32,
105105
pub i: i32,
106106
}
107+
108+
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
109+
pub enum Void {}
110+
111+
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
112+
pub struct WithUninhabited {
113+
x: u32,
114+
v: Void,
115+
y: u32,
116+
}
117+
118+
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
119+
pub enum EnumWithUninhabited {
120+
A(u32),
121+
B(Void),
122+
C(u16),
123+
}

0 commit comments

Comments
 (0)