From 5ac213fac4303a4a697df4ec6675b6e44a6dac49 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 19 Nov 2020 11:37:59 +0000 Subject: [PATCH 1/2] derive-backend: fix clippy warning for strip_prefix --- pyo3-derive-backend/src/method.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pyo3-derive-backend/src/method.rs b/pyo3-derive-backend/src/method.rs index 70957c8ad8d..1285d476759 100644 --- a/pyo3-derive-backend/src/method.rs +++ b/pyo3-derive-backend/src/method.rs @@ -139,12 +139,10 @@ impl<'a> FnSpec<'a> { // strip get_ or set_ let strip_fn_name = |prefix: &'static str| { - let ident = sig.ident.unraw().to_string(); - if ident.starts_with(prefix) { - Some(syn::Ident::new(&ident[prefix.len()..], ident.span())) - } else { - None - } + name.unraw() + .to_string() + .strip_prefix(prefix) + .map(|rest| syn::Ident::new(rest, name.span())) }; // Parse receiver & function type for various method types From 8a8c098a2ee0fdce05cc244e21cb949279b21744 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 19 Nov 2020 12:05:08 +0000 Subject: [PATCH 2/2] rust-1.48: fix tests and warnings --- pyo3-derive-backend/src/from_pyobject.rs | 2 +- src/ffi/methodobject.rs | 40 +++++++++++---------- tests/test_compile_error.rs | 14 ++++++-- tests/ui/abi3_nativetype_inheritance.stderr | 12 +++---- tests/ui/invalid_pymethod_receiver.stderr | 16 ++++----- tests/ui/invalid_result_conversion.stderr | 10 +++--- tests/ui/missing_clone.stderr | 4 +-- tests/ui/wrong_aspyref_lifetimes.stderr | 2 +- 8 files changed, 55 insertions(+), 45 deletions(-) diff --git a/pyo3-derive-backend/src/from_pyobject.rs b/pyo3-derive-backend/src/from_pyobject.rs index 01e281d5e22..b7da07dcb20 100644 --- a/pyo3-derive-backend/src/from_pyobject.rs +++ b/pyo3-derive-backend/src/from_pyobject.rs @@ -161,7 +161,7 @@ impl<'a> Container<'a> { .as_ref() .expect("Named fields should have identifiers"); let attr = FieldAttribute::parse_attrs(&field.attrs)? - .unwrap_or_else(|| FieldAttribute::GetAttr(None)); + .unwrap_or(FieldAttribute::GetAttr(None)); fields.push((ident, attr)) } ContainerType::Struct(fields) diff --git a/src/ffi/methodobject.rs b/src/ffi/methodobject.rs index 921cca847c1..193dde8b4c0 100644 --- a/src/ffi/methodobject.rs +++ b/src/ffi/methodobject.rs @@ -16,25 +16,27 @@ pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int { pub type PyCFunction = unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject) -> *mut PyObject; -#[cfg(all(Py_3_8, not(Py_LIMITED_API)))] -#[cfg_attr(Py_3_8, link_name = "_PyObject_Vectorcall")] -pub type PyObject_Vectorcall = unsafe extern "C" fn( - slf: *mut PyObject, - // positional and keyword arguments - args: *const *mut PyObject, - // number of position arguments in args, after which values are kwargs - nargs: crate::ffi::pyport::Py_ssize_t, - // tuple of kwargs, if given, or null - kwnames: *mut PyObject, -) -> *mut PyObject; - -#[cfg(all(Py_3_8, not(Py_LIMITED_API)))] -#[cfg_attr(Py_3_8, link_name = "PyVectorcall_Call")] -pub type PyVectorcall_Call = unsafe extern "C" fn( - obj: *mut PyObject, - tuple: *mut PyObject, - dict: *mut PyObject, -) -> *mut PyObject; +// TODO(davidhewitt)[1283] - Fix this definition +// #[cfg(all(Py_3_8, not(Py_LIMITED_API)))] +// #[cfg_attr(Py_3_8, link_name = "_PyObject_Vectorcall")] +// pub type PyObject_Vectorcall = unsafe extern "C" fn( +// slf: *mut PyObject, +// // positional and keyword arguments +// args: *const *mut PyObject, +// // number of position arguments in args, after which values are kwargs +// nargs: crate::ffi::pyport::Py_ssize_t, +// // tuple of kwargs, if given, or null +// kwnames: *mut PyObject, +// ) -> *mut PyObject; + +// TODO(davidhewitt)[1283] - Fix this definition +// #[cfg(all(Py_3_8, not(Py_LIMITED_API)))] +// #[cfg_attr(Py_3_8, link_name = "PyVectorcall_Call")] +// pub type PyVectorcall_Call = unsafe extern "C" fn( +// obj: *mut PyObject, +// tuple: *mut PyObject, +// dict: *mut PyObject, +// ) -> *mut PyObject; #[cfg(all(Py_3_7, not(Py_LIMITED_API)))] const PY_VECTORCALL_ARGUMENTS_OFFSET: crate::ffi::pyport::Py_ssize_t = diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 0b2e495cd2b..59f4a03f89c 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -9,19 +9,27 @@ fn test_compile_errors() { t.compile_fail("tests/ui/invalid_pymethod_names.rs"); t.compile_fail("tests/ui/reject_generics.rs"); t.compile_fail("tests/ui/static_ref.rs"); - t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs"); tests_rust_1_46(&t); + tests_rust_1_48(&t); #[rustversion::since(1.46)] fn tests_rust_1_46(t: &trybuild::TestCases) { t.compile_fail("tests/ui/invalid_frompy_derive.rs"); + } + #[rustversion::before(1.46)] + fn tests_rust_1_46(_t: &trybuild::TestCases) {} + + #[rustversion::since(1.48)] + fn tests_rust_1_48(t: &trybuild::TestCases) { t.compile_fail("tests/ui/invalid_pymethod_receiver.rs"); t.compile_fail("tests/ui/invalid_result_conversion.rs"); t.compile_fail("tests/ui/missing_clone.rs"); + t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs"); + #[cfg(Py_LIMITED_API)] t.compile_fail("tests/ui/abi3_nativetype_inheritance.rs"); } - #[rustversion::before(1.46)] - fn tests_rust_1_46(_t: &trybuild::TestCases) {} + #[rustversion::before(1.48)] + fn tests_rust_1_48(_t: &trybuild::TestCases) {} } diff --git a/tests/ui/abi3_nativetype_inheritance.stderr b/tests/ui/abi3_nativetype_inheritance.stderr index 9787700b4a3..54cacd505d9 100644 --- a/tests/ui/abi3_nativetype_inheritance.stderr +++ b/tests/ui/abi3_nativetype_inheritance.stderr @@ -1,13 +1,13 @@ -error[E0277]: the trait bound `pyo3::ffi::PyDictObject: pyo3::type_object::PySizedLayout` is not satisfied +error[E0277]: the trait bound `PyDictObject: PySizedLayout` is not satisfied --> $DIR/abi3_nativetype_inheritance.rs:5:1 | 5 | #[pyclass(extends=PyDict)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `pyo3::type_object::PySizedLayout` is not implemented for `pyo3::ffi::PyDictObject` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PySizedLayout` is not implemented for `PyDictObject` | - ::: $WORKSPACE/src/type_object.rs:96:22 + ::: $WORKSPACE/src/type_object.rs | -96 | type BaseLayout: PySizedLayout; - | ----------------------------- required by this bound in `pyo3::PyTypeInfo` + | type BaseLayout: PySizedLayout; + | ----------------------------- required by this bound in `PyTypeInfo` | - = note: required because of the requirements on the impl of `pyo3::type_object::PySizedLayout` for `pyo3::pycell::PyCellBase` + = note: required because of the requirements on the impl of `PySizedLayout` for `PyCellBase` = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/invalid_pymethod_receiver.stderr b/tests/ui/invalid_pymethod_receiver.stderr index 044678b2fdd..e43a08ed209 100644 --- a/tests/ui/invalid_pymethod_receiver.stderr +++ b/tests/ui/invalid_pymethod_receiver.stderr @@ -1,14 +1,14 @@ -error[E0277]: the trait bound `i32: std::convert::From<&pyo3::PyCell>` is not satisfied +error[E0277]: the trait bound `i32: From<&PyCell>` is not satisfied --> $DIR/invalid_pymethod_receiver.rs:8:43 | 8 | fn method_with_invalid_self_type(slf: i32, py: Python, index: u32) {} - | ^^^ the trait `std::convert::From<&pyo3::PyCell>` is not implemented for `i32` + | ^^^ the trait `From<&PyCell>` is not implemented for `i32` | = help: the following implementations were found: - > - > - > - > + > + > + > + > and 2 others - = note: required because of the requirements on the impl of `std::convert::Into` for `&pyo3::PyCell` - = note: required because of the requirements on the impl of `std::convert::TryFrom<&pyo3::PyCell>` for `i32` + = note: required because of the requirements on the impl of `Into` for `&PyCell` + = note: required because of the requirements on the impl of `TryFrom<&PyCell>` for `i32` diff --git a/tests/ui/invalid_result_conversion.stderr b/tests/ui/invalid_result_conversion.stderr index a7e8a6d0ebf..3209334f0ee 100644 --- a/tests/ui/invalid_result_conversion.stderr +++ b/tests/ui/invalid_result_conversion.stderr @@ -1,14 +1,14 @@ -error[E0277]: the trait bound `std::result::Result<(), MyError>: pyo3::callback::IntoPyCallbackOutput<_>` is not satisfied +error[E0277]: the trait bound `std::result::Result<(), MyError>: IntoPyCallbackOutput<_>` is not satisfied --> $DIR/invalid_result_conversion.rs:22:1 | 22 | #[pyfunction] - | ^^^^^^^^^^^^^ the trait `pyo3::callback::IntoPyCallbackOutput<_>` is not implemented for `std::result::Result<(), MyError>` + | ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `std::result::Result<(), MyError>` | - ::: $WORKSPACE/src/callback.rs:170:8 + ::: $WORKSPACE/src/callback.rs | -170 | T: IntoPyCallbackOutput, + | T: IntoPyCallbackOutput, | ----------------------- required by this bound in `pyo3::callback::convert` | = help: the following implementations were found: - as pyo3::callback::IntoPyCallbackOutput> + as IntoPyCallbackOutput> = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/missing_clone.stderr b/tests/ui/missing_clone.stderr index e828edc8353..cf89ee807ce 100644 --- a/tests/ui/missing_clone.stderr +++ b/tests/ui/missing_clone.stderr @@ -1,7 +1,7 @@ -error[E0277]: the trait bound `TestClass: std::clone::Clone` is not satisfied +error[E0277]: the trait bound `TestClass: Clone` is not satisfied --> $DIR/missing_clone.rs:15:32 | 15 | let t: TestClass = pyvalue.extract(py).unwrap(); - | ^^^^^^^ the trait `std::clone::Clone` is not implemented for `TestClass` + | ^^^^^^^ the trait `Clone` is not implemented for `TestClass` | = note: required because of the requirements on the impl of `pyo3::FromPyObject<'_>` for `TestClass` diff --git a/tests/ui/wrong_aspyref_lifetimes.stderr b/tests/ui/wrong_aspyref_lifetimes.stderr index 7c3b87ce86b..4d4a20c5ead 100644 --- a/tests/ui/wrong_aspyref_lifetimes.stderr +++ b/tests/ui/wrong_aspyref_lifetimes.stderr @@ -5,6 +5,6 @@ error[E0505]: cannot move out of `gil` because it is borrowed | --- borrow of `gil` occurs here 7 | drop(gil); | ^^^ move out of `gil` occurs here -8 | +8 | 9 | let _py: Python = dict.py(); // Obtain a Python<'p> without GIL. | ---- borrow later used here