Ban pyo3(get, set) on tuple struct field

This commit is contained in:
messense 2021-03-18 18:27:18 +08:00
parent 773a371ba5
commit 2cec240b0e
3 changed files with 23 additions and 11 deletions

View File

@ -506,7 +506,7 @@ fn impl_descriptors(
.flat_map(|(field, fns)| {
fns.iter()
.map(|desc| {
let name = field.ident.as_ref().unwrap().unraw();
if let Some(name) = field.ident.as_ref().map(|ident| ident.unraw()) {
let doc = utils::get_doc(&field.attrs, None, true)
.unwrap_or_else(|_| syn::LitStr::new(&name.to_string(), name.span()));
let property_type = PropertyType::Descriptor(&field);
@ -519,6 +519,9 @@ fn impl_descriptors(
}
_ => unreachable!(),
}
} else {
bail_spanned!(field.span() => "get/set are not supported on tuple struct field");
}
})
.collect::<Vec<syn::Result<TokenStream>>>()
})

View File

@ -24,4 +24,7 @@ impl ClassWithSetter {
fn setter_with_too_many_args(&mut self, py: Python, foo: u32, bar: u32) {}
}
#[pyclass]
struct TupleGetterSetter(#[pyo3(get, set)] i32);
fn main() {}

View File

@ -15,3 +15,9 @@ error: setter function can have at most two arguments ([pyo3::Python,] and value
|
24 | fn setter_with_too_many_args(&mut self, py: Python, foo: u32, bar: u32) {}
| ^^^
error: get/set are not supported on tuple struct field
--> $DIR/invalid_property_args.rs:28:44
|
28 | struct TupleGetterSetter(#[pyo3(get, set)] i32);
| ^^^