Skip to content
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

CI fixes for Rust 1.48 #1284

Merged
merged 2 commits into from
Nov 19, 2020
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
2 changes: 1 addition & 1 deletion pyo3-derive-backend/src/from_pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions pyo3-derive-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 21 additions & 19 deletions src/ffi/methodobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
14 changes: 11 additions & 3 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
12 changes: 6 additions & 6 deletions tests/ui/abi3_nativetype_inheritance.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0277]: the trait bound `pyo3::ffi::PyDictObject: pyo3::type_object::PySizedLayout<pyo3::types::PyDict>` is not satisfied
error[E0277]: the trait bound `PyDictObject: PySizedLayout<PyDict>` is not satisfied
--> $DIR/abi3_nativetype_inheritance.rs:5:1
|
5 | #[pyclass(extends=PyDict)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `pyo3::type_object::PySizedLayout<pyo3::types::PyDict>` is not implemented for `pyo3::ffi::PyDictObject`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PySizedLayout<PyDict>` is not implemented for `PyDictObject`
|
::: $WORKSPACE/src/type_object.rs:96:22
::: $WORKSPACE/src/type_object.rs
|
96 | type BaseLayout: PySizedLayout<Self::BaseType>;
| ----------------------------- required by this bound in `pyo3::PyTypeInfo`
| type BaseLayout: PySizedLayout<Self::BaseType>;
| ----------------------------- required by this bound in `PyTypeInfo`
|
= note: required because of the requirements on the impl of `pyo3::type_object::PySizedLayout<pyo3::types::PyDict>` for `pyo3::pycell::PyCellBase<pyo3::types::PyDict>`
= note: required because of the requirements on the impl of `PySizedLayout<PyDict>` for `PyCellBase<PyDict>`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
16 changes: 8 additions & 8 deletions tests/ui/invalid_pymethod_receiver.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0277]: the trait bound `i32: std::convert::From<&pyo3::PyCell<MyClass>>` is not satisfied
error[E0277]: the trait bound `i32: From<&PyCell<MyClass>>` 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<MyClass>>` is not implemented for `i32`
| ^^^ the trait `From<&PyCell<MyClass>>` is not implemented for `i32`
|
= help: the following implementations were found:
<i32 as std::convert::From<bool>>
<i32 as std::convert::From<i16>>
<i32 as std::convert::From<i8>>
<i32 as std::convert::From<std::num::NonZeroI32>>
<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 `std::convert::Into<i32>` for `&pyo3::PyCell<MyClass>`
= note: required because of the requirements on the impl of `std::convert::TryFrom<&pyo3::PyCell<MyClass>>` for `i32`
= 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`
10 changes: 5 additions & 5 deletions tests/ui/invalid_result_conversion.stderr
Original file line number Diff line number Diff line change
@@ -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<U>,
| T: IntoPyCallbackOutput<U>,
| ----------------------- required by this bound in `pyo3::callback::convert`
|
= help: the following implementations were found:
<std::result::Result<T, E> as pyo3::callback::IntoPyCallbackOutput<U>>
<std::result::Result<T, E> as IntoPyCallbackOutput<U>>
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
4 changes: 2 additions & 2 deletions tests/ui/missing_clone.stderr
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion tests/ui/wrong_aspyref_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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