Skip to content

Commit 17d7cfb

Browse files
committed
compile error tests
1 parent 26f29c8 commit 17d7cfb

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

tests/test_compile_error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn test_compile_errors() {
2525
t.compile_fail("tests/ui/invalid_closure.rs");
2626
t.compile_fail("tests/ui/pyclass_send.rs");
2727
t.compile_fail("tests/ui/invalid_argument_attributes.rs");
28+
t.compile_fail("tests/ui/invalid_intopy_derive.rs");
2829
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
2930
t.compile_fail("tests/ui/static_ref.rs");
3031
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");

tests/ui/invalid_intopy_derive.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
use pyo3::IntoPyObject;
2+
3+
#[derive(IntoPyObject)]
4+
struct Foo();
5+
6+
#[derive(IntoPyObject)]
7+
struct Foo2 {}
8+
9+
#[derive(IntoPyObject)]
10+
enum EmptyEnum {}
11+
12+
#[derive(IntoPyObject)]
13+
enum EnumWithEmptyTupleVar {
14+
EmptyTuple(),
15+
Valid(String),
16+
}
17+
18+
#[derive(IntoPyObject)]
19+
enum EnumWithEmptyStructVar {
20+
EmptyStruct {},
21+
Valid(String),
22+
}
23+
24+
#[derive(IntoPyObject)]
25+
#[pyo3(transparent)]
26+
struct EmptyTransparentTup();
27+
28+
#[derive(IntoPyObject)]
29+
#[pyo3(transparent)]
30+
struct EmptyTransparentStruct {}
31+
32+
#[derive(IntoPyObject)]
33+
enum EnumWithTransparentEmptyTupleVar {
34+
#[pyo3(transparent)]
35+
EmptyTuple(),
36+
Valid(String),
37+
}
38+
39+
#[derive(IntoPyObject)]
40+
enum EnumWithTransparentEmptyStructVar {
41+
#[pyo3(transparent)]
42+
EmptyStruct {},
43+
Valid(String),
44+
}
45+
46+
#[derive(IntoPyObject)]
47+
#[pyo3(transparent)]
48+
struct TransparentTupTooManyFields(String, String);
49+
50+
#[derive(IntoPyObject)]
51+
#[pyo3(transparent)]
52+
struct TransparentStructTooManyFields {
53+
foo: String,
54+
bar: String,
55+
}
56+
57+
#[derive(IntoPyObject)]
58+
enum EnumWithTransparentTupleTooMany {
59+
#[pyo3(transparent)]
60+
EmptyTuple(String, String),
61+
Valid(String),
62+
}
63+
64+
#[derive(IntoPyObject)]
65+
enum EnumWithTransparentStructTooMany {
66+
#[pyo3(transparent)]
67+
EmptyStruct {
68+
foo: String,
69+
bar: String,
70+
},
71+
Valid(String),
72+
}
73+
74+
#[derive(IntoPyObject)]
75+
#[pyo3(unknown = "should not work")]
76+
struct UnknownContainerAttr {
77+
a: String,
78+
}
79+
80+
#[derive(IntoPyObject)]
81+
union Union {
82+
a: usize,
83+
}
84+
85+
#[derive(IntoPyObject)]
86+
enum UnitEnum {
87+
Unit,
88+
}
89+
90+
fn main() {}

tests/ui/invalid_intopy_derive.stderr

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
error: cannot derive `IntoPyObject` for empty structs and variants
2+
--> tests/ui/invalid_intopy_derive.rs:4:11
3+
|
4+
4 | struct Foo();
5+
| ^^
6+
7+
error: cannot derive `IntoPyObject` for empty structs and variants
8+
--> tests/ui/invalid_intopy_derive.rs:7:13
9+
|
10+
7 | struct Foo2 {}
11+
| ^^
12+
13+
error: cannot derive `IntoPyObject` for empty enum
14+
--> tests/ui/invalid_intopy_derive.rs:10:6
15+
|
16+
10 | enum EmptyEnum {}
17+
| ^^^^^^^^^
18+
19+
error: cannot derive `IntoPyObject` for empty structs and variants
20+
--> tests/ui/invalid_intopy_derive.rs:14:15
21+
|
22+
14 | EmptyTuple(),
23+
| ^^
24+
25+
error: cannot derive `IntoPyObject` for empty structs and variants
26+
--> tests/ui/invalid_intopy_derive.rs:20:17
27+
|
28+
20 | EmptyStruct {},
29+
| ^^
30+
31+
error: cannot derive `IntoPyObject` for empty structs and variants
32+
--> tests/ui/invalid_intopy_derive.rs:26:27
33+
|
34+
26 | struct EmptyTransparentTup();
35+
| ^^
36+
37+
error: cannot derive `IntoPyObject` for empty structs and variants
38+
--> tests/ui/invalid_intopy_derive.rs:30:31
39+
|
40+
30 | struct EmptyTransparentStruct {}
41+
| ^^
42+
43+
error: cannot derive `IntoPyObject` for empty structs and variants
44+
--> tests/ui/invalid_intopy_derive.rs:35:15
45+
|
46+
35 | EmptyTuple(),
47+
| ^^
48+
49+
error: cannot derive `IntoPyObject` for empty structs and variants
50+
--> tests/ui/invalid_intopy_derive.rs:42:17
51+
|
52+
42 | EmptyStruct {},
53+
| ^^
54+
55+
error: transparent structs and variants can only have 1 field
56+
--> tests/ui/invalid_intopy_derive.rs:48:35
57+
|
58+
48 | struct TransparentTupTooManyFields(String, String);
59+
| ^^^^^^^^^^^^^^^^
60+
61+
error: transparent structs and variants can only have 1 field
62+
--> tests/ui/invalid_intopy_derive.rs:52:39
63+
|
64+
52 | struct TransparentStructTooManyFields {
65+
| _______________________________________^
66+
53 | | foo: String,
67+
54 | | bar: String,
68+
55 | | }
69+
| |_^
70+
71+
error: transparent structs and variants can only have 1 field
72+
--> tests/ui/invalid_intopy_derive.rs:60:15
73+
|
74+
60 | EmptyTuple(String, String),
75+
| ^^^^^^^^^^^^^^^^
76+
77+
error: transparent structs and variants can only have 1 field
78+
--> tests/ui/invalid_intopy_derive.rs:67:17
79+
|
80+
67 | EmptyStruct {
81+
| _________________^
82+
68 | | foo: String,
83+
69 | | bar: String,
84+
70 | | },
85+
| |_____^
86+
87+
error: expected `transparent` or `crate`
88+
--> tests/ui/invalid_intopy_derive.rs:75:8
89+
|
90+
75 | #[pyo3(unknown = "should not work")]
91+
| ^^^^^^^
92+
93+
error: #[derive(`IntoPyObject`)] is not supported for unions
94+
--> tests/ui/invalid_intopy_derive.rs:81:1
95+
|
96+
81 | union Union {
97+
| ^^^^^
98+
99+
error: cannot derive `IntoPyObject` for empty structs and variants
100+
--> tests/ui/invalid_intopy_derive.rs:85:10
101+
|
102+
85 | #[derive(IntoPyObject)]
103+
| ^^^^^^^^^^^^
104+
|
105+
= note: this error originates in the derive macro `IntoPyObject` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)