diff --git a/src/buffer.rs b/src/buffer.rs index 1f4f57fb4b8..f323dbfef3d 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -34,6 +34,7 @@ pub struct PyBuffer(Pin>, PhantomData); // PyBuffer is thread-safe: the shape of the buffer is immutable while a Py_buffer exists. // Accessing the buffer contents is protected using the GIL. +#[allow(clippy::non_send_fields_in_send_ty)] unsafe impl Send for PyBuffer {} unsafe impl Sync for PyBuffer {} diff --git a/src/ffi/unicodeobject.rs b/src/ffi/unicodeobject.rs index 2b02b37e5bb..10c32ca21f2 100644 --- a/src/ffi/unicodeobject.rs +++ b/src/ffi/unicodeobject.rs @@ -77,10 +77,9 @@ extern "C" { ) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] pub fn PyUnicode_FromObject(obj: *mut PyObject) -> *mut PyObject; + // #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormatV")] + // pub fn PyUnicode_FromFormatV(format: *const c_char, vargs: va_list) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormat")] - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormatV")] - //pub fn PyUnicode_FromFormatV(format: *const c_char, - // vargs: va_list) -> *mut PyObject; pub fn PyUnicode_FromFormat(format: *const c_char, ...) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyUnicode_InternInPlace")] pub fn PyUnicode_InternInPlace(arg1: *mut *mut PyObject); diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 7bf7312d74e..2fef7685c6b 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -23,22 +23,18 @@ fn _test_compile_errors() { t.compile_fail("tests/ui/invalid_pyclass_args.rs"); t.compile_fail("tests/ui/invalid_pyclass_enum.rs"); t.compile_fail("tests/ui/invalid_pyclass_item.rs"); - t.compile_fail("tests/ui/invalid_pyfunctions.rs"); - t.compile_fail("tests/ui/invalid_pymethods.rs"); #[cfg(not(Py_LIMITED_API))] t.compile_fail("tests/ui/invalid_pymethods_buffer.rs"); t.compile_fail("tests/ui/invalid_pymethod_names.rs"); t.compile_fail("tests/ui/invalid_pymodule_args.rs"); - t.compile_fail("tests/ui/missing_clone.rs"); t.compile_fail("tests/ui/reject_generics.rs"); - t.compile_fail("tests/ui/not_send.rs"); t.compile_fail("tests/ui/invalid_pymethod_proto_args.rs"); t.compile_fail("tests/ui/invalid_pymethod_proto_args_py.rs"); tests_rust_1_49(&t); - tests_rust_1_55(&t); tests_rust_1_56(&t); tests_rust_1_57(&t); + tests_rust_1_58(&t); #[rustversion::since(1.49)] fn tests_rust_1_49(t: &trybuild::TestCases) { @@ -47,22 +43,11 @@ fn _test_compile_errors() { #[rustversion::before(1.49)] fn tests_rust_1_49(_t: &trybuild::TestCases) {} - #[rustversion::since(1.55)] - fn tests_rust_1_55(t: &trybuild::TestCases) { - t.compile_fail("tests/ui/invalid_pymethod_receiver.rs"); - } - - #[rustversion::before(1.55)] - fn tests_rust_1_55(_t: &trybuild::TestCases) {} - #[rustversion::since(1.56)] fn tests_rust_1_56(t: &trybuild::TestCases) { t.compile_fail("tests/ui/invalid_closure.rs"); t.compile_fail("tests/ui/invalid_result_conversion.rs"); t.compile_fail("tests/ui/pyclass_send.rs"); - - #[cfg(Py_LIMITED_API)] - t.compile_fail("tests/ui/abi3_nativetype_inheritance.rs"); } #[rustversion::before(1.56)] @@ -78,4 +63,18 @@ fn _test_compile_errors() { #[rustversion::before(1.57)] fn tests_rust_1_57(_t: &trybuild::TestCases) {} + + #[rustversion::since(1.58)] + fn tests_rust_1_58(t: &trybuild::TestCases) { + t.compile_fail("tests/ui/invalid_pyfunctions.rs"); + t.compile_fail("tests/ui/invalid_pymethod_receiver.rs"); + t.compile_fail("tests/ui/invalid_pymethods.rs"); + t.compile_fail("tests/ui/missing_clone.rs"); + t.compile_fail("tests/ui/not_send.rs"); + #[cfg(Py_LIMITED_API)] + t.compile_fail("tests/ui/abi3_nativetype_inheritance.rs"); + } + + #[rustversion::before(1.58)] + fn tests_rust_1_58(_t: &trybuild::TestCases) {} } diff --git a/tests/ui/abi3_nativetype_inheritance.stderr b/tests/ui/abi3_nativetype_inheritance.stderr index 4f9681d8e9f..762250a4c1f 100644 --- a/tests/ui/abi3_nativetype_inheritance.stderr +++ b/tests/ui/abi3_nativetype_inheritance.stderr @@ -1,21 +1,11 @@ error[E0277]: the trait bound `PyDict: PyClass` is not satisfied - --> tests/ui/abi3_nativetype_inheritance.rs:5:1 - | -5 | #[pyclass(extends=PyDict)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PyClass` is not implemented for `PyDict` - | - = note: required because of the requirements on the impl of `PyClassBaseType` for `PyDict` -note: required by a bound in `PyClassBaseType` - --> src/class/impl_.rs - | - | / pub trait PyClassBaseType: Sized { - | | type LayoutAsBase: PyCellLayout; - | | type BaseNativeType; - | | type ThreadChecker: PyClassThreadChecker; - | | type Initializer: PyObjectInit; - | | } - | |_^ required by this bound in `PyClassBaseType` - = note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info) + --> tests/ui/abi3_nativetype_inheritance.rs:5:1 + | +5 | #[pyclass(extends=PyDict)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PyClass` is not implemented for `PyDict` + | + = note: required because of the requirements on the impl of `PyClassBaseType` for `PyDict` + = note: this error originates in the attribute macro `pyclass` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `PyDict: PyClass` is not satisfied --> tests/ui/abi3_nativetype_inheritance.rs:5:1 diff --git a/tests/ui/invalid_pyfunctions.stderr b/tests/ui/invalid_pyfunctions.stderr index 00bf963faed..6587535ac55 100644 --- a/tests/ui/invalid_pyfunctions.stderr +++ b/tests/ui/invalid_pyfunctions.stderr @@ -12,7 +12,7 @@ error: Python functions cannot have `impl Trait` arguments error: `async fn` is not yet supported for Python functions. -Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and Python. For more information, see https://github.com/PyO3/pyo3/issues/1632 + Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and Python. For more information, see https://github.com/PyO3/pyo3/issues/1632 --> tests/ui/invalid_pyfunctions.rs:10:1 | 10 | async fn async_function() {} diff --git a/tests/ui/invalid_pymethod_receiver.stderr b/tests/ui/invalid_pymethod_receiver.stderr index 395c2acd68f..09057ae71b4 100644 --- a/tests/ui/invalid_pymethod_receiver.stderr +++ b/tests/ui/invalid_pymethod_receiver.stderr @@ -1,19 +1,14 @@ error[E0277]: the trait bound `i32: From<&PyCell>` is not satisfied - --> tests/ui/invalid_pymethod_receiver.rs:8:43 - | -8 | fn method_with_invalid_self_type(slf: i32, py: Python, index: u32) {} - | ^^^ 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 `Into` for `&PyCell` - = note: required because of the requirements on the impl of `TryFrom<&PyCell>` for `i32` -note: required by `std::convert::TryFrom::try_from` - --> $RUST/core/src/convert/mod.rs - | - | fn try_from(value: T) -> Result; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + --> tests/ui/invalid_pymethod_receiver.rs:8:43 + | +8 | fn method_with_invalid_self_type(slf: i32, py: Python, index: u32) {} + | ^^^ 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 `Into` for `&PyCell` + = note: required because of the requirements on the impl of `TryFrom<&PyCell>` for `i32` diff --git a/tests/ui/invalid_pymethods.stderr b/tests/ui/invalid_pymethods.stderr index 3556c2722eb..bc11faba722 100644 --- a/tests/ui/invalid_pymethods.stderr +++ b/tests/ui/invalid_pymethods.stderr @@ -90,7 +90,7 @@ error: Python functions cannot have `impl Trait` arguments error: `async fn` is not yet supported for Python functions. -Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and Python. For more information, see https://github.com/PyO3/pyo3/issues/1632 + Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and Python. For more information, see https://github.com/PyO3/pyo3/issues/1632 --> tests/ui/invalid_pymethods.rs:107:5 | 107 | async fn async_method(&self) {} diff --git a/tests/ui/missing_clone.stderr b/tests/ui/missing_clone.stderr index edb82e47b83..59c1f324ff2 100644 --- a/tests/ui/missing_clone.stderr +++ b/tests/ui/missing_clone.stderr @@ -1,7 +1,12 @@ error[E0277]: the trait bound `TestClass: Clone` is not satisfied - --> tests/ui/missing_clone.rs:15:32 - | -15 | let t: TestClass = pyvalue.extract(py).unwrap(); - | ^^^^^^^ the trait `Clone` is not implemented for `TestClass` - | - = note: required because of the requirements on the impl of `pyo3::FromPyObject<'_>` for `TestClass` + --> tests/ui/missing_clone.rs:15:32 + | +15 | let t: TestClass = pyvalue.extract(py).unwrap(); + | ^^^^^^^ the trait `Clone` is not implemented for `TestClass` + | + = note: required because of the requirements on the impl of `pyo3::FromPyObject<'_>` for `TestClass` +note: required by a bound in `pyo3::Py::::extract` + --> src/instance.rs + | + | D: FromPyObject<'p>, + | ^^^^^^^^^^^^^^^^ required by this bound in `pyo3::Py::::extract` diff --git a/tests/ui/not_send.stderr b/tests/ui/not_send.stderr index 31340cd7a19..166a3d6fd5f 100644 --- a/tests/ui/not_send.stderr +++ b/tests/ui/not_send.stderr @@ -1,14 +1,19 @@ error[E0277]: `*mut pyo3::Python<'static>` cannot be shared between threads safely - --> tests/ui/not_send.rs:4:8 - | -4 | py.allow_threads(|| { drop(py); }); - | ^^^^^^^^^^^^^ `*mut pyo3::Python<'static>` cannot be shared between threads safely - | - = help: within `pyo3::Python<'_>`, the trait `Sync` is not implemented for `*mut pyo3::Python<'static>` - = note: required because it appears within the type `PhantomData<*mut pyo3::Python<'static>>` - = note: required because it appears within the type `pyo3::impl_::not_send::NotSend` - = note: required because it appears within the type `(&GILGuard, pyo3::impl_::not_send::NotSend)` - = note: required because it appears within the type `PhantomData<(&GILGuard, pyo3::impl_::not_send::NotSend)>` - = note: required because it appears within the type `pyo3::Python<'_>` - = note: required because of the requirements on the impl of `Send` for `&pyo3::Python<'_>` - = note: required because it appears within the type `[closure@$DIR/tests/ui/not_send.rs:4:22: 4:38]` + --> tests/ui/not_send.rs:4:8 + | +4 | py.allow_threads(|| { drop(py); }); + | ^^^^^^^^^^^^^ `*mut pyo3::Python<'static>` cannot be shared between threads safely + | + = help: within `pyo3::Python<'_>`, the trait `Sync` is not implemented for `*mut pyo3::Python<'static>` + = note: required because it appears within the type `PhantomData<*mut pyo3::Python<'static>>` + = note: required because it appears within the type `pyo3::impl_::not_send::NotSend` + = note: required because it appears within the type `(&GILGuard, pyo3::impl_::not_send::NotSend)` + = note: required because it appears within the type `PhantomData<(&GILGuard, pyo3::impl_::not_send::NotSend)>` + = note: required because it appears within the type `pyo3::Python<'_>` + = note: required because of the requirements on the impl of `Send` for `&pyo3::Python<'_>` + = note: required because it appears within the type `[closure@$DIR/tests/ui/not_send.rs:4:22: 4:38]` +note: required by a bound in `pyo3::Python::<'py>::allow_threads` + --> src/python.rs + | + | F: Send + FnOnce() -> T, + | ^^^^ required by this bound in `pyo3::Python::<'py>::allow_threads`