Skip to content

chore: Fix 1.58 release #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct PyBuffer<T>(Pin<Box<ffi::Py_buffer>>, PhantomData<T>);

// 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)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See rust-lang/rust-clippy#8045

We could also just make the fields Send, because right now the only types that implement Element are threadsafe already. However that would be a breaking change for anyone who has implemented Element on their own types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Should we mark this with a FIXME or TODO to decide later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that's not going to silence the lint, because it's triggering on ffi::Py_buffer, and we can't make that Send. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. This is just one of the many cases where Python ffi makes clippy uneasy, we'll just have to live with it.

unsafe impl<T> Send for PyBuffer<T> {}
unsafe impl<T> Sync for PyBuffer<T> {}

Expand Down
5 changes: 2 additions & 3 deletions src/ffi/unicodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +80 to +81
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's up with this..it seems that all functions using the va_list are commented out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's because support in std is not stable? We could enable it behind an optional flag.

https://doc.rust-lang.org/std/ffi/struct.VaList.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I had no idea that existed. Given that it's been on nightly for 3 years now and it doesn't look like it's close to stabilization, I think I prefer just not having these.

#[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);
Expand Down
31 changes: 15 additions & 16 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)]
Expand All @@ -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) {}
}
24 changes: 7 additions & 17 deletions tests/ui/abi3_nativetype_inheritance.stderr
Original file line number Diff line number Diff line change
@@ -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<Self>;
| | type BaseNativeType;
| | type ThreadChecker: PyClassThreadChecker<Self>;
| | type Initializer: PyObjectInit<Self>;
| | }
| |_^ 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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/invalid_pyfunctions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
31 changes: 13 additions & 18 deletions tests/ui/invalid_pymethod_receiver.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
error[E0277]: the trait bound `i32: From<&PyCell<MyClass>>` 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<MyClass>>` is not implemented for `i32`
|
= help: the following implementations were found:
<i32 as From<NonZeroI32>>
<i32 as From<bool>>
<i32 as From<i16>>
<i32 as From<i8>>
and 2 others
= note: required because of the requirements on the impl of `Into<i32>` for `&PyCell<MyClass>`
= note: required because of the requirements on the impl of `TryFrom<&PyCell<MyClass>>` for `i32`
note: required by `std::convert::TryFrom::try_from`
--> $RUST/core/src/convert/mod.rs
|
| fn try_from(value: T) -> Result<Self, Self::Error>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--> 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<MyClass>>` is not implemented for `i32`
|
= help: the following implementations were found:
<i32 as From<NonZeroI32>>
<i32 as From<bool>>
<i32 as From<i16>>
<i32 as From<i8>>
and 2 others
= note: required because of the requirements on the impl of `Into<i32>` for `&PyCell<MyClass>`
= note: required because of the requirements on the impl of `TryFrom<&PyCell<MyClass>>` for `i32`
2 changes: 1 addition & 1 deletion tests/ui/invalid_pymethods.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
17 changes: 11 additions & 6 deletions tests/ui/missing_clone.stderr
Original file line number Diff line number Diff line change
@@ -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::<T>::extract`
--> src/instance.rs
|
| D: FromPyObject<'p>,
| ^^^^^^^^^^^^^^^^ required by this bound in `pyo3::Py::<T>::extract`
31 changes: 18 additions & 13 deletions tests/ui/not_send.stderr
Original file line number Diff line number Diff line change
@@ -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`