From b1012ebb68431c69a8fa39171f9b1538d956d0d3 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 31 Dec 2020 15:46:54 +0000 Subject: [PATCH] build: update for Rust 1.49 --- .github/workflows/ci.yml | 8 ++++---- CHANGELOG.md | 1 + pyo3-macros-backend/src/module.rs | 2 +- pyo3-macros-backend/src/pyclass.rs | 2 +- src/gil.rs | 2 +- src/types/complex.rs | 5 +---- src/types/datetime.rs | 10 +++++----- src/types/set.rs | 21 +++++--------------- tests/test_compile_error.rs | 22 ++++++++++----------- tests/test_exceptions.rs | 2 +- tests/ui/abi3_nativetype_inheritance.stderr | 2 +- tests/ui/invalid_frompy_derive.stderr | 2 +- tests/ui/invalid_pymethod_receiver.stderr | 1 + 13 files changed, 34 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5905894ae2a..9339677f6b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,18 +85,18 @@ jobs: run: echo LD_LIBRARY_PATH=${pythonLocation}/lib >> $GITHUB_ENV - name: Build docs - run: cargo doc --features "num-bigint num-complex" --verbose --target ${{ matrix.platform.rust-target }} + run: cargo doc --features "num-bigint num-complex hashbrown" --verbose --target ${{ matrix.platform.rust-target }} - name: Build without default features run: cargo build --no-default-features --verbose --target ${{ matrix.platform.rust-target }} - name: Build with default features - run: cargo build --features "num-bigint num-complex" --verbose --target ${{ matrix.platform.rust-target }} + run: cargo build --features "num-bigint num-complex hashbrown" --verbose --target ${{ matrix.platform.rust-target }} # Run tests (except on PyPy, because no embedding API). - if: matrix.python-version != 'pypy-3.6' name: Test - run: cargo test --features "num-bigint num-complex" --target ${{ matrix.platform.rust-target }} + run: cargo test --features "num-bigint num-complex hashbrown" --target ${{ matrix.platform.rust-target }} # Run tests again, but in abi3 mode - if: matrix.python-version != 'pypy-3.6' name: Test (abi3) @@ -139,7 +139,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test - args: --features "num-bigint num-complex" --no-fail-fast + args: --features "num-bigint num-complex hashbrown" --no-fail-fast env: CARGO_INCREMENTAL: 0 RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests" diff --git a/CHANGELOG.md b/CHANGELOG.md index a6ab595bb80..7c8254929a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Stop including `Py_TRACE_REFS` config setting automatically if `Py_DEBUG` is set on Python 3.8 and up. [#1334](https://github.com/PyO3/pyo3/pull/1334) - Remove `#[deny(warnings)]` attribute (and instead refuse warnings only in CI). [#1340](https://github.com/PyO3/pyo3/pull/1340) - Fix deprecation warning for missing `__module__` with `#[pyclass]`. [#1343](https://github.com/PyO3/pyo3/pull/1343) +- Correct return type of `PyFrozenSet::empty` to `&PyFrozenSet` (was incorrectly `&PySet`). [#1351](https://github.com/PyO3/pyo3/pull/1351) ## [0.13.0] - 2020-12-22 ### Packaging diff --git a/pyo3-macros-backend/src/module.rs b/pyo3-macros-backend/src/module.rs index a09a2ccbd13..12463dd1993 100644 --- a/pyo3-macros-backend/src/module.rs +++ b/pyo3-macros-backend/src/module.rs @@ -58,7 +58,7 @@ pub fn process_functions_in_module(func: &mut syn::ItemFn) -> syn::Result<()> { } /// Transforms a rust fn arg parsed with syn into a method::FnArg -fn wrap_fn_argument<'a>(cap: &'a syn::PatType) -> syn::Result> { +fn wrap_fn_argument(cap: &syn::PatType) -> syn::Result { let (mutability, by_ref, ident) = match &*cap.pat { syn::Pat::Ident(patid) => (&patid.mutability, &patid.by_ref, &patid.ident), _ => return Err(syn::Error::new_spanned(&cap.pat, "Unsupported argument")), diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 77f76eb46fc..28a27e703e6 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -229,7 +229,7 @@ fn parse_descriptors(item: &mut syn::Field) -> syn::Result> { /// To allow multiple #[pymethods]/#[pyproto] block, we define inventory types. fn impl_methods_inventory(cls: &syn::Ident) -> TokenStream { // Try to build a unique type for better error messages - let name = format!("Pyo3MethodsInventoryFor{}", cls); + let name = format!("Pyo3MethodsInventoryFor{}", cls.unraw()); let inventory_cls = syn::Ident::new(&name, Span::call_site()); quote! { diff --git a/src/gil.rs b/src/gil.rs index 135881b3ef5..183af48ec0b 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -224,7 +224,7 @@ impl ReferencePool { drop(locked); out }}; - }; + } // Always increase reference counts first - as otherwise objects which have a // nonzero total reference count might be incorrectly dropped by Python during diff --git a/src/types/complex.rs b/src/types/complex.rs index 69d92c17c72..19ad2771159 100644 --- a/src/types/complex.rs +++ b/src/types/complex.rs @@ -126,10 +126,7 @@ mod complex_conversion { impl PyComplex { /// Creates a new Python `PyComplex` object from num_complex::Complex. - pub fn from_complex<'py, F: Into>( - py: Python<'py>, - complex: Complex, - ) -> &'py PyComplex { + pub fn from_complex>(py: Python, complex: Complex) -> &PyComplex { unsafe { let ptr = ffi::PyComplex_FromDoubles(complex.re.into(), complex.im.into()); py.from_owned_ptr(ptr) diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 89dbeb201ae..97d8aa0c1a0 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -73,7 +73,7 @@ pyobject_native_type!( ); impl PyDate { - pub fn new<'p>(py: Python<'p>, year: i32, month: u8, day: u8) -> PyResult<&'p PyDate> { + pub fn new(py: Python, year: i32, month: u8, day: u8) -> PyResult<&PyDate> { unsafe { let ptr = (PyDateTimeAPI.Date_FromDate)( year, @@ -88,7 +88,7 @@ impl PyDate { /// Construct a `datetime.date` from a POSIX timestamp /// /// This is equivalent to `datetime.date.fromtimestamp` - pub fn from_timestamp<'p>(py: Python<'p>, timestamp: i64) -> PyResult<&'p PyDate> { + pub fn from_timestamp(py: Python, timestamp: i64) -> PyResult<&PyDate> { let time_tuple = PyTuple::new(py, &[timestamp]); unsafe { @@ -336,13 +336,13 @@ pyobject_native_type!( ); impl PyDelta { - pub fn new<'p>( - py: Python<'p>, + pub fn new( + py: Python, days: i32, seconds: i32, microseconds: i32, normalize: bool, - ) -> PyResult<&'p PyDelta> { + ) -> PyResult<&PyDelta> { unsafe { let ptr = (PyDateTimeAPI.Delta_FromDelta)( days as c_int, diff --git a/src/types/set.rs b/src/types/set.rs index 5593490afd8..3989edfb59e 100644 --- a/src/types/set.rs +++ b/src/types/set.rs @@ -38,7 +38,7 @@ impl PySet { } /// Creates a new empty set. - pub fn empty<'p>(py: Python<'p>) -> PyResult<&'p PySet> { + pub fn empty(py: Python) -> PyResult<&PySet> { unsafe { py.from_owned_ptr_or_err(ffi::PySet_New(ptr::null_mut())) } } @@ -275,7 +275,7 @@ impl PyFrozenSet { } /// Creates a new empty frozen set - pub fn empty<'p>(py: Python<'p>) -> PyResult<&'p PySet> { + pub fn empty(py: Python) -> PyResult<&PyFrozenSet> { unsafe { py.from_owned_ptr_or_err(ffi::PyFrozenSet_New(ptr::null_mut())) } } @@ -372,16 +372,12 @@ mod hashbrown_hashset_conversion { #[test] fn test_extract_hashbrown_hashset() { - use std::iter::FromIterator; let gil = Python::acquire_gil(); let py = gil.python(); let set = PySet::new(py, &[1, 2, 3, 4, 5]).unwrap(); let hash_set: hashbrown::HashSet = set.extract().unwrap(); - assert_eq!( - hash_set, - hashbrown::HashSet::from_iter([1, 2, 3, 4, 5].iter().copied()) - ); + assert_eq!(hash_set, [1, 2, 3, 4, 5].iter().copied().collect()); } #[test] @@ -402,7 +398,6 @@ mod test { use super::{PyFrozenSet, PySet}; use crate::{IntoPy, PyObject, PyTryFrom, Python, ToPyObject}; use std::collections::{BTreeSet, HashSet}; - use std::iter::FromIterator; #[test] fn test_set_new() { @@ -562,10 +557,7 @@ mod test { let set = PySet::new(py, &[1, 2, 3, 4, 5]).unwrap(); let hash_set: HashSet = set.extract().unwrap(); - assert_eq!( - hash_set, - HashSet::from_iter([1, 2, 3, 4, 5].iter().copied()) - ); + assert_eq!(hash_set, [1, 2, 3, 4, 5].iter().copied().collect()); } #[test] @@ -575,10 +567,7 @@ mod test { let set = PySet::new(py, &[1, 2, 3, 4, 5]).unwrap(); let hash_set: BTreeSet = set.extract().unwrap(); - assert_eq!( - hash_set, - BTreeSet::from_iter([1, 2, 3, 4, 5].iter().copied()) - ); + assert_eq!(hash_set, [1, 2, 3, 4, 5].iter().copied().collect()); } #[test] diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 59f4a03f89c..99f52e7181b 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -10,26 +10,26 @@ fn test_compile_errors() { t.compile_fail("tests/ui/reject_generics.rs"); t.compile_fail("tests/ui/static_ref.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) {} + tests_rust_1_49(&t); #[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"); + } + #[rustversion::before(1.48)] + fn tests_rust_1_48(_t: &trybuild::TestCases) {} + + #[rustversion::since(1.49)] + fn tests_rust_1_49(t: &trybuild::TestCases) { + t.compile_fail("tests/ui/invalid_frompy_derive.rs"); + t.compile_fail("tests/ui/invalid_pymethod_receiver.rs"); #[cfg(Py_LIMITED_API)] t.compile_fail("tests/ui/abi3_nativetype_inheritance.rs"); } - #[rustversion::before(1.48)] - fn tests_rust_1_48(_t: &trybuild::TestCases) {} + #[rustversion::before(1.49)] + fn tests_rust_1_49(_t: &trybuild::TestCases) {} } diff --git a/tests/test_exceptions.rs b/tests/test_exceptions.rs index 5d4a9a6505d..710b170584b 100644 --- a/tests/test_exceptions.rs +++ b/tests/test_exceptions.rs @@ -80,7 +80,7 @@ fn test_custom_error() { #[test] fn test_exception_nosegfault() { - use std::{net::TcpListener, panic}; + use std::net::TcpListener; fn io_err() -> PyResult<()> { TcpListener::bind("no:address")?; Ok(()) diff --git a/tests/ui/abi3_nativetype_inheritance.stderr b/tests/ui/abi3_nativetype_inheritance.stderr index 54cacd505d9..cf825281016 100644 --- a/tests/ui/abi3_nativetype_inheritance.stderr +++ b/tests/ui/abi3_nativetype_inheritance.stderr @@ -7,7 +7,7 @@ error[E0277]: the trait bound `PyDictObject: PySizedLayout` is not satis ::: $WORKSPACE/src/type_object.rs | | type BaseLayout: PySizedLayout; - | ----------------------------- required by this bound in `PyTypeInfo` + | ----------------------------- required by this bound in `pyo3::PyTypeInfo::BaseLayout` | = 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_frompy_derive.stderr b/tests/ui/invalid_frompy_derive.stderr index 4eaf1218586..cb5424466af 100644 --- a/tests/ui/invalid_frompy_derive.stderr +++ b/tests/ui/invalid_frompy_derive.stderr @@ -142,7 +142,7 @@ error: Annotating error messages for structs is not supported. Remove the annota --> $DIR/invalid_frompy_derive.rs:129:1 | 129 | #[pyo3(annotation = "should not work")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error: Expected string literal. --> $DIR/invalid_frompy_derive.rs:136:25 diff --git a/tests/ui/invalid_pymethod_receiver.stderr b/tests/ui/invalid_pymethod_receiver.stderr index e43a08ed209..d6dc0ac6254 100644 --- a/tests/ui/invalid_pymethod_receiver.stderr +++ b/tests/ui/invalid_pymethod_receiver.stderr @@ -12,3 +12,4 @@ error[E0277]: the trait bound `i32: From<&PyCell>` is not satisfied 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`