Skip to content

Commit

Permalink
compile error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed Aug 27, 2024
1 parent 26f29c8 commit 17d7cfb
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn test_compile_errors() {
t.compile_fail("tests/ui/invalid_closure.rs");
t.compile_fail("tests/ui/pyclass_send.rs");
t.compile_fail("tests/ui/invalid_argument_attributes.rs");
t.compile_fail("tests/ui/invalid_intopy_derive.rs");
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
t.compile_fail("tests/ui/static_ref.rs");
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
Expand Down
90 changes: 90 additions & 0 deletions tests/ui/invalid_intopy_derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use pyo3::IntoPyObject;

#[derive(IntoPyObject)]
struct Foo();

#[derive(IntoPyObject)]
struct Foo2 {}

#[derive(IntoPyObject)]
enum EmptyEnum {}

#[derive(IntoPyObject)]
enum EnumWithEmptyTupleVar {
EmptyTuple(),
Valid(String),
}

#[derive(IntoPyObject)]
enum EnumWithEmptyStructVar {
EmptyStruct {},
Valid(String),
}

#[derive(IntoPyObject)]
#[pyo3(transparent)]
struct EmptyTransparentTup();

#[derive(IntoPyObject)]
#[pyo3(transparent)]
struct EmptyTransparentStruct {}

#[derive(IntoPyObject)]
enum EnumWithTransparentEmptyTupleVar {
#[pyo3(transparent)]
EmptyTuple(),
Valid(String),
}

#[derive(IntoPyObject)]
enum EnumWithTransparentEmptyStructVar {
#[pyo3(transparent)]
EmptyStruct {},
Valid(String),
}

#[derive(IntoPyObject)]
#[pyo3(transparent)]
struct TransparentTupTooManyFields(String, String);

#[derive(IntoPyObject)]
#[pyo3(transparent)]
struct TransparentStructTooManyFields {
foo: String,
bar: String,
}

#[derive(IntoPyObject)]
enum EnumWithTransparentTupleTooMany {
#[pyo3(transparent)]
EmptyTuple(String, String),
Valid(String),
}

#[derive(IntoPyObject)]
enum EnumWithTransparentStructTooMany {
#[pyo3(transparent)]
EmptyStruct {
foo: String,
bar: String,
},
Valid(String),
}

#[derive(IntoPyObject)]
#[pyo3(unknown = "should not work")]
struct UnknownContainerAttr {
a: String,
}

#[derive(IntoPyObject)]
union Union {
a: usize,
}

#[derive(IntoPyObject)]
enum UnitEnum {
Unit,
}

fn main() {}
105 changes: 105 additions & 0 deletions tests/ui/invalid_intopy_derive.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:4:11
|
4 | struct Foo();
| ^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:7:13
|
7 | struct Foo2 {}
| ^^

error: cannot derive `IntoPyObject` for empty enum
--> tests/ui/invalid_intopy_derive.rs:10:6
|
10 | enum EmptyEnum {}
| ^^^^^^^^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:14:15
|
14 | EmptyTuple(),
| ^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:20:17
|
20 | EmptyStruct {},
| ^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:26:27
|
26 | struct EmptyTransparentTup();
| ^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:30:31
|
30 | struct EmptyTransparentStruct {}
| ^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:35:15
|
35 | EmptyTuple(),
| ^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:42:17
|
42 | EmptyStruct {},
| ^^

error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:48:35
|
48 | struct TransparentTupTooManyFields(String, String);
| ^^^^^^^^^^^^^^^^

error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:52:39
|
52 | struct TransparentStructTooManyFields {
| _______________________________________^
53 | | foo: String,
54 | | bar: String,
55 | | }
| |_^

error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:60:15
|
60 | EmptyTuple(String, String),
| ^^^^^^^^^^^^^^^^

error: transparent structs and variants can only have 1 field
--> tests/ui/invalid_intopy_derive.rs:67:17
|
67 | EmptyStruct {
| _________________^
68 | | foo: String,
69 | | bar: String,
70 | | },
| |_____^

error: expected `transparent` or `crate`
--> tests/ui/invalid_intopy_derive.rs:75:8
|
75 | #[pyo3(unknown = "should not work")]
| ^^^^^^^

error: #[derive(`IntoPyObject`)] is not supported for unions
--> tests/ui/invalid_intopy_derive.rs:81:1
|
81 | union Union {
| ^^^^^

error: cannot derive `IntoPyObject` for empty structs and variants
--> tests/ui/invalid_intopy_derive.rs:85:10
|
85 | #[derive(IntoPyObject)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `IntoPyObject` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit 17d7cfb

Please sign in to comment.