From f75ea3d93a87fb8a77069595147d8f02d451e268 Mon Sep 17 00:00:00 2001 From: BlueGlassBlock Date: Thu, 27 Apr 2023 12:44:38 +0800 Subject: [PATCH] test: improve cov --- pyo3-macros-backend/src/frompyobject.rs | 4 +++- tests/ui/invalid_frompy_derive.rs | 18 ++++++++++------ tests/ui/invalid_frompy_derive.stderr | 28 +++++++++++++++---------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/pyo3-macros-backend/src/frompyobject.rs b/pyo3-macros-backend/src/frompyobject.rs index 3565bc8c..bb8b4954 100644 --- a/pyo3-macros-backend/src/frompyobject.rs +++ b/pyo3-macros-backend/src/frompyobject.rs @@ -181,7 +181,9 @@ impl<'a> Container<'a> { attrs.getter = Some(FieldGetter::GetItem(Some(item_name))); } FieldGetter::GetItem(None) => bail_spanned!(from_item_all.span() => "Useless `item` - the struct is already annotated with `from_item_all`"), - FieldGetter::GetAttr(_) => bail_spanned!(from_item_all.span() => "The struct is already annotated with `from_item_all`, `attr` is not allowed"), + FieldGetter::GetAttr(_) => bail_spanned!( + from_item_all.span() => "The struct is already annotated with `from_item_all`, `attribute` is not allowed" + ), } } } diff --git a/tests/ui/invalid_frompy_derive.rs b/tests/ui/invalid_frompy_derive.rs index 8063e33c..f123b149 100644 --- a/tests/ui/invalid_frompy_derive.rs +++ b/tests/ui/invalid_frompy_derive.rs @@ -177,12 +177,18 @@ struct InvalidTransparentWithGetter { #[derive(FromPyObject)] #[pyo3(from_item_all)] -struct ItemAllOnTuple(String); +struct FromItemAllOnTuple(String); #[derive(FromPyObject)] #[pyo3(from_item_all)] #[pyo3(transparent)] -struct ItemAllWithTransparent { +struct FromItemAllWithTransparent { + field: String, +} + +#[derive(FromPyObject)] +#[pyo3(from_item_all, from_item_all)] +struct MultipleFromItemAll { field: String, } @@ -195,15 +201,15 @@ struct UselessItemAttr { #[derive(FromPyObject)] #[pyo3(from_item_all)] -struct ItemAllConflictAttr { - #[pyo3(attr)] +struct FromItemAllConflictAttr { + #[pyo3(attribute)] field: String, } #[derive(FromPyObject)] #[pyo3(from_item_all)] -struct ItemAllConflictAttrWithArgs { - #[pyo3(attr("f"))] +struct FromItemAllConflictAttrWithArgs { + #[pyo3(attribute("f"))] field: String, } diff --git a/tests/ui/invalid_frompy_derive.stderr b/tests/ui/invalid_frompy_derive.stderr index 2a5f12a6..8ed03caa 100644 --- a/tests/ui/invalid_frompy_derive.stderr +++ b/tests/ui/invalid_frompy_derive.stderr @@ -200,20 +200,26 @@ error: `transparent` structs may not have a `getter` for the inner field 186 | field: String, | ^^^^^ -error: Useless `item` - the struct is already annotated with `from_item_all` - --> tests/ui/invalid_frompy_derive.rs:190:8 +error: `from_item_all` may only be provided once + --> tests/ui/invalid_frompy_derive.rs:190:23 | -190 | #[pyo3(from_item_all)] +190 | #[pyo3(from_item_all, from_item_all)] + | ^^^^^^^^^^^^^ + +error: Useless `item` - the struct is already annotated with `from_item_all` + --> tests/ui/invalid_frompy_derive.rs:196:8 + | +196 | #[pyo3(from_item_all)] | ^^^^^^^^^^^^^ -error: expected one of: `attribute`, `item`, `from_py_with` - --> tests/ui/invalid_frompy_derive.rs:199:12 +error: The struct is already annotated with `from_item_all`, `attribute` is not allowed + --> tests/ui/invalid_frompy_derive.rs:203:8 | -199 | #[pyo3(attr)] - | ^^^^ +203 | #[pyo3(from_item_all)] + | ^^^^^^^^^^^^^ -error: expected one of: `attribute`, `item`, `from_py_with` - --> tests/ui/invalid_frompy_derive.rs:206:12 +error: The struct is already annotated with `from_item_all`, `attribute` is not allowed + --> tests/ui/invalid_frompy_derive.rs:210:8 | -206 | #[pyo3(attr("f"))] - | ^^^^ +210 | #[pyo3(from_item_all)] + | ^^^^^^^^^^^^^