Skip to content

Commit d3f993a

Browse files
authored
Merge pull request #1284 from davidhewitt/fix-rust-1_48
CI fixes for Rust 1.48
2 parents dcca3f8 + 8a8c098 commit d3f993a

9 files changed

Lines changed: 59 additions & 51 deletions

pyo3-derive-backend/src/from_pyobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a> Container<'a> {
161161
.as_ref()
162162
.expect("Named fields should have identifiers");
163163
let attr = FieldAttribute::parse_attrs(&field.attrs)?
164-
.unwrap_or_else(|| FieldAttribute::GetAttr(None));
164+
.unwrap_or(FieldAttribute::GetAttr(None));
165165
fields.push((ident, attr))
166166
}
167167
ContainerType::Struct(fields)

pyo3-derive-backend/src/method.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,10 @@ impl<'a> FnSpec<'a> {
139139

140140
// strip get_ or set_
141141
let strip_fn_name = |prefix: &'static str| {
142-
let ident = sig.ident.unraw().to_string();
143-
if ident.starts_with(prefix) {
144-
Some(syn::Ident::new(&ident[prefix.len()..], ident.span()))
145-
} else {
146-
None
147-
}
142+
name.unraw()
143+
.to_string()
144+
.strip_prefix(prefix)
145+
.map(|rest| syn::Ident::new(rest, name.span()))
148146
};
149147

150148
// Parse receiver & function type for various method types

src/ffi/methodobject.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int {
1616
pub type PyCFunction =
1717
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
1818

19-
#[cfg(all(Py_3_8, not(Py_LIMITED_API)))]
20-
#[cfg_attr(Py_3_8, link_name = "_PyObject_Vectorcall")]
21-
pub type PyObject_Vectorcall = unsafe extern "C" fn(
22-
slf: *mut PyObject,
23-
// positional and keyword arguments
24-
args: *const *mut PyObject,
25-
// number of position arguments in args, after which values are kwargs
26-
nargs: crate::ffi::pyport::Py_ssize_t,
27-
// tuple of kwargs, if given, or null
28-
kwnames: *mut PyObject,
29-
) -> *mut PyObject;
30-
31-
#[cfg(all(Py_3_8, not(Py_LIMITED_API)))]
32-
#[cfg_attr(Py_3_8, link_name = "PyVectorcall_Call")]
33-
pub type PyVectorcall_Call = unsafe extern "C" fn(
34-
obj: *mut PyObject,
35-
tuple: *mut PyObject,
36-
dict: *mut PyObject,
37-
) -> *mut PyObject;
19+
// TODO(davidhewitt)[1283] - Fix this definition
20+
// #[cfg(all(Py_3_8, not(Py_LIMITED_API)))]
21+
// #[cfg_attr(Py_3_8, link_name = "_PyObject_Vectorcall")]
22+
// pub type PyObject_Vectorcall = unsafe extern "C" fn(
23+
// slf: *mut PyObject,
24+
// // positional and keyword arguments
25+
// args: *const *mut PyObject,
26+
// // number of position arguments in args, after which values are kwargs
27+
// nargs: crate::ffi::pyport::Py_ssize_t,
28+
// // tuple of kwargs, if given, or null
29+
// kwnames: *mut PyObject,
30+
// ) -> *mut PyObject;
31+
32+
// TODO(davidhewitt)[1283] - Fix this definition
33+
// #[cfg(all(Py_3_8, not(Py_LIMITED_API)))]
34+
// #[cfg_attr(Py_3_8, link_name = "PyVectorcall_Call")]
35+
// pub type PyVectorcall_Call = unsafe extern "C" fn(
36+
// obj: *mut PyObject,
37+
// tuple: *mut PyObject,
38+
// dict: *mut PyObject,
39+
// ) -> *mut PyObject;
3840

3941
#[cfg(all(Py_3_7, not(Py_LIMITED_API)))]
4042
const PY_VECTORCALL_ARGUMENTS_OFFSET: crate::ffi::pyport::Py_ssize_t =

tests/test_compile_error.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@ fn test_compile_errors() {
99
t.compile_fail("tests/ui/invalid_pymethod_names.rs");
1010
t.compile_fail("tests/ui/reject_generics.rs");
1111
t.compile_fail("tests/ui/static_ref.rs");
12-
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
1312

1413
tests_rust_1_46(&t);
14+
tests_rust_1_48(&t);
1515

1616
#[rustversion::since(1.46)]
1717
fn tests_rust_1_46(t: &trybuild::TestCases) {
1818
t.compile_fail("tests/ui/invalid_frompy_derive.rs");
19+
}
20+
#[rustversion::before(1.46)]
21+
fn tests_rust_1_46(_t: &trybuild::TestCases) {}
22+
23+
#[rustversion::since(1.48)]
24+
fn tests_rust_1_48(t: &trybuild::TestCases) {
1925
t.compile_fail("tests/ui/invalid_pymethod_receiver.rs");
2026
t.compile_fail("tests/ui/invalid_result_conversion.rs");
2127
t.compile_fail("tests/ui/missing_clone.rs");
28+
t.compile_fail("tests/ui/wrong_aspyref_lifetimes.rs");
29+
2230
#[cfg(Py_LIMITED_API)]
2331
t.compile_fail("tests/ui/abi3_nativetype_inheritance.rs");
2432
}
25-
#[rustversion::before(1.46)]
26-
fn tests_rust_1_46(_t: &trybuild::TestCases) {}
33+
#[rustversion::before(1.48)]
34+
fn tests_rust_1_48(_t: &trybuild::TestCases) {}
2735
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0277]: the trait bound `pyo3::ffi::PyDictObject: pyo3::type_object::PySizedLayout<pyo3::types::PyDict>` is not satisfied
1+
error[E0277]: the trait bound `PyDictObject: PySizedLayout<PyDict>` is not satisfied
22
--> $DIR/abi3_nativetype_inheritance.rs:5:1
33
|
44
5 | #[pyclass(extends=PyDict)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `pyo3::type_object::PySizedLayout<pyo3::types::PyDict>` is not implemented for `pyo3::ffi::PyDictObject`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PySizedLayout<PyDict>` is not implemented for `PyDictObject`
66
|
7-
::: $WORKSPACE/src/type_object.rs:96:22
7+
::: $WORKSPACE/src/type_object.rs
88
|
9-
96 | type BaseLayout: PySizedLayout<Self::BaseType>;
10-
| ----------------------------- required by this bound in `pyo3::PyTypeInfo`
9+
| type BaseLayout: PySizedLayout<Self::BaseType>;
10+
| ----------------------------- required by this bound in `PyTypeInfo`
1111
|
12-
= note: required because of the requirements on the impl of `pyo3::type_object::PySizedLayout<pyo3::types::PyDict>` for `pyo3::pycell::PyCellBase<pyo3::types::PyDict>`
12+
= note: required because of the requirements on the impl of `PySizedLayout<PyDict>` for `PyCellBase<PyDict>`
1313
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0277]: the trait bound `i32: std::convert::From<&pyo3::PyCell<MyClass>>` is not satisfied
1+
error[E0277]: the trait bound `i32: From<&PyCell<MyClass>>` is not satisfied
22
--> $DIR/invalid_pymethod_receiver.rs:8:43
33
|
44
8 | fn method_with_invalid_self_type(slf: i32, py: Python, index: u32) {}
5-
| ^^^ the trait `std::convert::From<&pyo3::PyCell<MyClass>>` is not implemented for `i32`
5+
| ^^^ the trait `From<&PyCell<MyClass>>` is not implemented for `i32`
66
|
77
= help: the following implementations were found:
8-
<i32 as std::convert::From<bool>>
9-
<i32 as std::convert::From<i16>>
10-
<i32 as std::convert::From<i8>>
11-
<i32 as std::convert::From<std::num::NonZeroI32>>
8+
<i32 as From<NonZeroI32>>
9+
<i32 as From<bool>>
10+
<i32 as From<i16>>
11+
<i32 as From<i8>>
1212
and 2 others
13-
= note: required because of the requirements on the impl of `std::convert::Into<i32>` for `&pyo3::PyCell<MyClass>`
14-
= note: required because of the requirements on the impl of `std::convert::TryFrom<&pyo3::PyCell<MyClass>>` for `i32`
13+
= note: required because of the requirements on the impl of `Into<i32>` for `&PyCell<MyClass>`
14+
= note: required because of the requirements on the impl of `TryFrom<&PyCell<MyClass>>` for `i32`
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0277]: the trait bound `std::result::Result<(), MyError>: pyo3::callback::IntoPyCallbackOutput<_>` is not satisfied
1+
error[E0277]: the trait bound `std::result::Result<(), MyError>: IntoPyCallbackOutput<_>` is not satisfied
22
--> $DIR/invalid_result_conversion.rs:22:1
33
|
44
22 | #[pyfunction]
5-
| ^^^^^^^^^^^^^ the trait `pyo3::callback::IntoPyCallbackOutput<_>` is not implemented for `std::result::Result<(), MyError>`
5+
| ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `std::result::Result<(), MyError>`
66
|
7-
::: $WORKSPACE/src/callback.rs:170:8
7+
::: $WORKSPACE/src/callback.rs
88
|
9-
170 | T: IntoPyCallbackOutput<U>,
9+
| T: IntoPyCallbackOutput<U>,
1010
| ----------------------- required by this bound in `pyo3::callback::convert`
1111
|
1212
= help: the following implementations were found:
13-
<std::result::Result<T, E> as pyo3::callback::IntoPyCallbackOutput<U>>
13+
<std::result::Result<T, E> as IntoPyCallbackOutput<U>>
1414
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/missing_clone.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error[E0277]: the trait bound `TestClass: std::clone::Clone` is not satisfied
1+
error[E0277]: the trait bound `TestClass: Clone` is not satisfied
22
--> $DIR/missing_clone.rs:15:32
33
|
44
15 | let t: TestClass = pyvalue.extract(py).unwrap();
5-
| ^^^^^^^ the trait `std::clone::Clone` is not implemented for `TestClass`
5+
| ^^^^^^^ the trait `Clone` is not implemented for `TestClass`
66
|
77
= note: required because of the requirements on the impl of `pyo3::FromPyObject<'_>` for `TestClass`

tests/ui/wrong_aspyref_lifetimes.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ error[E0505]: cannot move out of `gil` because it is borrowed
55
| --- borrow of `gil` occurs here
66
7 | drop(gil);
77
| ^^^ move out of `gil` occurs here
8-
8 |
8+
8 |
99
9 | let _py: Python = dict.py(); // Obtain a Python<'p> without GIL.
1010
| ---- borrow later used here

0 commit comments

Comments
 (0)