From 0d30bb7d3dd7b5bc3cd79cd349cefe9e6c31912a Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Wed, 7 Jun 2023 20:49:27 +0200 Subject: [PATCH] Bump Rust edition to 2021 and make current Clippy happy. --- Cargo.toml | 3 +-- README.md | 2 +- examples/Cargo.toml | 2 +- examples/decorator/Cargo.toml | 2 +- examples/maturin-starter/Cargo.toml | 2 +- examples/setuptools-rust-starter/Cargo.toml | 2 +- examples/word-count/Cargo.toml | 2 +- guide/src/class/numeric.md | 1 - pyo3-build-config/Cargo.toml | 2 +- pyo3-ffi-check/Cargo.toml | 2 +- pyo3-ffi-check/macro/Cargo.toml | 2 +- pyo3-ffi/Cargo.toml | 2 +- pyo3-ffi/src/cpython/abstract_.rs | 8 ++++---- pyo3-macros-backend/Cargo.toml | 2 +- pyo3-macros-backend/src/frompyobject.rs | 4 ++-- pyo3-macros/Cargo.toml | 2 +- pytests/Cargo.toml | 2 +- pytests/src/pyclasses.rs | 3 ++- src/lib.rs | 2 +- src/pycell.rs | 2 -- src/test_hygiene/pyclass.rs | 2 +- tests/ui/invalid_closure.stderr | 18 ------------------ 22 files changed, 24 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index afe29eac..c27639e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/crate/pyo3/" categories = ["api-bindings", "development-tools::ffi"] license = "Apache-2.0" exclude = ["/.gitignore", ".cargo/config", "/codecov.yml", "/Makefile", "/pyproject.toml", "/noxfile.py", "/.github", "/tests/test_compile_error.rs", "/tests/ui"] -edition = "2018" +edition = "2021" rust-version = "1.56" [dependencies] @@ -187,7 +187,6 @@ members = [ "pytests", "examples", ] -resolver = "2" [package.metadata.docs.rs] no-default-features = true diff --git a/README.md b/README.md index 1d72e3e4..7daccddf 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ The most important files generated by this command are `Cargo.toml` and `lib.rs` [package] name = "string_sum" version = "0.1.0" -edition = "2018" +edition = "2021" [lib] # The name of the native library. This is the name which will be used in Python to import the diff --git a/examples/Cargo.toml b/examples/Cargo.toml index e76132c4..6f25a226 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -2,7 +2,7 @@ name = "examples" version = "0.0.0" publish = false -edition = "2018" +edition = "2021" [dev-dependencies] pyo3 = { version = "0.19.0", path = "..", features = ["auto-initialize", "extension-module"] } diff --git a/examples/decorator/Cargo.toml b/examples/decorator/Cargo.toml index 702f6a1f..3456302a 100644 --- a/examples/decorator/Cargo.toml +++ b/examples/decorator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "decorator" version = "0.1.0" -edition = "2018" +edition = "2021" [lib] name = "decorator" diff --git a/examples/maturin-starter/Cargo.toml b/examples/maturin-starter/Cargo.toml index c7e3d233..257908a4 100644 --- a/examples/maturin-starter/Cargo.toml +++ b/examples/maturin-starter/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "maturin-starter" version = "0.1.0" -edition = "2018" +edition = "2021" [lib] name = "maturin_starter" diff --git a/examples/setuptools-rust-starter/Cargo.toml b/examples/setuptools-rust-starter/Cargo.toml index d07c29d7..5777cbbc 100644 --- a/examples/setuptools-rust-starter/Cargo.toml +++ b/examples/setuptools-rust-starter/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "setuptools-rust-starter" version = "0.1.0" -edition = "2018" +edition = "2021" [lib] name = "setuptools_rust_starter" diff --git a/examples/word-count/Cargo.toml b/examples/word-count/Cargo.toml index a351cf75..cfb3444d 100644 --- a/examples/word-count/Cargo.toml +++ b/examples/word-count/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "word-count" version = "0.1.0" -edition = "2018" +edition = "2021" [lib] name = "word_count" diff --git a/guide/src/class/numeric.md b/guide/src/class/numeric.md index 21327ae2..bd6a9a5c 100644 --- a/guide/src/class/numeric.md +++ b/guide/src/class/numeric.md @@ -71,7 +71,6 @@ impl Number { With that out of the way, let's implement some operators: ```rust -use std::convert::TryInto; use pyo3::exceptions::{PyZeroDivisionError, PyValueError}; # use pyo3::prelude::*; diff --git a/pyo3-build-config/Cargo.toml b/pyo3-build-config/Cargo.toml index ac8d451f..4fa56c59 100644 --- a/pyo3-build-config/Cargo.toml +++ b/pyo3-build-config/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://github.com/pyo3/pyo3" repository = "https://github.com/pyo3/pyo3" categories = ["api-bindings", "development-tools::ffi"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [dependencies] once_cell = "1" diff --git a/pyo3-ffi-check/Cargo.toml b/pyo3-ffi-check/Cargo.toml index e1663eb8..d807cf91 100644 --- a/pyo3-ffi-check/Cargo.toml +++ b/pyo3-ffi-check/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pyo3-ffi-check" version = "0.1.0" -edition = "2018" +edition = "2021" publish = false [dependencies] diff --git a/pyo3-ffi-check/macro/Cargo.toml b/pyo3-ffi-check/macro/Cargo.toml index a9f51f65..c2243f30 100644 --- a/pyo3-ffi-check/macro/Cargo.toml +++ b/pyo3-ffi-check/macro/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pyo3-ffi-check-macro" version = "0.1.0" -edition = "2018" +edition = "2021" publish = false [lib] diff --git a/pyo3-ffi/Cargo.toml b/pyo3-ffi/Cargo.toml index bda76ab6..30b00720 100644 --- a/pyo3-ffi/Cargo.toml +++ b/pyo3-ffi/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://github.com/pyo3/pyo3" repository = "https://github.com/pyo3/pyo3" categories = ["api-bindings", "development-tools::ffi"] license = "Apache-2.0" -edition = "2018" +edition = "2021" links = "python" [dependencies] diff --git a/pyo3-ffi/src/cpython/abstract_.rs b/pyo3-ffi/src/cpython/abstract_.rs index 7d97abc4..decfc8dc 100644 --- a/pyo3-ffi/src/cpython/abstract_.rs +++ b/pyo3-ffi/src/cpython/abstract_.rs @@ -41,11 +41,11 @@ extern "C" { ) -> *mut PyObject; } -#[cfg(all(Py_3_8))] +#[cfg(Py_3_8)] const PY_VECTORCALL_ARGUMENTS_OFFSET: Py_ssize_t = 1 << (8 * std::mem::size_of::() as Py_ssize_t - 1); -#[cfg(all(Py_3_8))] +#[cfg(Py_3_8)] #[inline(always)] pub unsafe fn PyVectorcall_NARGS(n: size_t) -> Py_ssize_t { assert!(n <= (PY_SSIZE_T_MAX as size_t)); @@ -113,7 +113,7 @@ extern "C" { kwnames: *mut PyObject, ) -> *mut PyObject; - #[cfg(all(Py_3_8))] + #[cfg(Py_3_8)] #[cfg_attr(all(not(PyPy), not(Py_3_9)), link_name = "_PyObject_VectorcallDict")] #[cfg_attr(all(PyPy, not(Py_3_9)), link_name = "_PyPyObject_VectorcallDict")] #[cfg_attr(all(PyPy, Py_3_9), link_name = "PyPyObject_VectorcallDict")] @@ -124,7 +124,7 @@ extern "C" { kwdict: *mut PyObject, ) -> *mut PyObject; - #[cfg(all(Py_3_8))] + #[cfg(Py_3_8)] #[cfg_attr(not(any(Py_3_9, PyPy)), link_name = "_PyVectorcall_Call")] #[cfg_attr(PyPy, link_name = "PyPyVectorcall_Call")] pub fn PyVectorcall_Call( diff --git a/pyo3-macros-backend/Cargo.toml b/pyo3-macros-backend/Cargo.toml index e08919cf..f2d81348 100644 --- a/pyo3-macros-backend/Cargo.toml +++ b/pyo3-macros-backend/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://github.com/pyo3/pyo3" repository = "https://github.com/pyo3/pyo3" categories = ["api-bindings", "development-tools::ffi"] license = "Apache-2.0" -edition = "2018" +edition = "2021" # Note: we use default-features = false for proc-macro related crates # not to depend on proc-macro itself. diff --git a/pyo3-macros-backend/src/frompyobject.rs b/pyo3-macros-backend/src/frompyobject.rs index bb8b4954..876a750f 100644 --- a/pyo3-macros-backend/src/frompyobject.rs +++ b/pyo3-macros-backend/src/frompyobject.rs @@ -416,7 +416,7 @@ impl ContainerOptions { } ContainerPyO3Attribute::ItemAll(kw) => { ensure_spanned!( - matches!(options.from_item_all, None), + options.from_item_all.is_none(), kw.span() => "`from_item_all` may only be provided once" ); options.from_item_all = Some(kw); @@ -608,7 +608,7 @@ pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result { use #krate as _pyo3; #[automatically_derived] - impl#trait_generics _pyo3::FromPyObject<#lt_param> for #ident#generics #where_clause { + impl #trait_generics _pyo3::FromPyObject<#lt_param> for #ident #generics #where_clause { fn extract(obj: &#lt_param _pyo3::PyAny) -> _pyo3::PyResult { #derives } diff --git a/pyo3-macros/Cargo.toml b/pyo3-macros/Cargo.toml index 6c531c0f..7ecc2b22 100644 --- a/pyo3-macros/Cargo.toml +++ b/pyo3-macros/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://github.com/pyo3/pyo3" repository = "https://github.com/pyo3/pyo3" categories = ["api-bindings", "development-tools::ffi"] license = "Apache-2.0" -edition = "2018" +edition = "2021" [lib] proc-macro = true diff --git a/pytests/Cargo.toml b/pytests/Cargo.toml index e697ac16..2b7e8ec8 100644 --- a/pytests/Cargo.toml +++ b/pytests/Cargo.toml @@ -3,7 +3,7 @@ authors = ["PyO3 Authors"] name = "pyo3-pytests" version = "0.1.0" description = "Python-based tests for PyO3" -edition = "2018" +edition = "2021" publish = false [dependencies] diff --git a/pytests/src/pyclasses.rs b/pytests/src/pyclasses.rs index 3ee61b34..48fa628b 100644 --- a/pytests/src/pyclasses.rs +++ b/pytests/src/pyclasses.rs @@ -16,6 +16,7 @@ impl EmptyClass { /// This is for demonstrating how to return a value from __next__ #[pyclass] +#[derive(Default)] struct PyClassIter { count: usize, } @@ -24,7 +25,7 @@ struct PyClassIter { impl PyClassIter { #[new] pub fn new() -> Self { - PyClassIter { count: 0 } + Default::default() } fn __next__(&mut self) -> IterNextOutput { diff --git a/src/lib.rs b/src/lib.rs index 656c5a71..1c3ab46e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,7 +139,7 @@ //! [package] //! name = "string-sum" //! version = "0.1.0" -//! edition = "2018" +//! edition = "2021" //! //! [lib] //! name = "string_sum" diff --git a/src/pycell.rs b/src/pycell.rs index 44ee822f..54a83676 100644 --- a/src/pycell.rs +++ b/src/pycell.rs @@ -499,7 +499,6 @@ impl PyCell { /// Gets the offset of the dictionary from the start of the struct in bytes. pub(crate) fn dict_offset() -> ffi::Py_ssize_t { use memoffset::offset_of; - use std::convert::TryInto; let offset = offset_of!(PyCell, contents) + offset_of!(PyCellContents, dict); @@ -511,7 +510,6 @@ impl PyCell { /// Gets the offset of the weakref list from the start of the struct in bytes. pub(crate) fn weaklist_offset() -> ffi::Py_ssize_t { use memoffset::offset_of; - use std::convert::TryInto; let offset = offset_of!(PyCell, contents) + offset_of!(PyCellContents, weakref); diff --git a/src/test_hygiene/pyclass.rs b/src/test_hygiene/pyclass.rs index 0b535abe..4d07009c 100644 --- a/src/test_hygiene/pyclass.rs +++ b/src/test_hygiene/pyclass.rs @@ -56,6 +56,6 @@ pub struct Foo4 { field: i32, #[pyo3(get, set)] - #[cfg(any(not(FALSE)))] + #[cfg(not(FALSE))] field: u32, } diff --git a/tests/ui/invalid_closure.stderr b/tests/ui/invalid_closure.stderr index 4844f766..e4e829d5 100644 --- a/tests/ui/invalid_closure.stderr +++ b/tests/ui/invalid_closure.stderr @@ -8,21 +8,3 @@ error[E0597]: `local_data` does not live long enough | ---------------------------------------------------- argument requires that `local_data` is borrowed for `'static` 14 | }); | - `local_data` dropped here while still borrowed - -error[E0373]: closure may outlive the current function, but it borrows `ref_`, which is owned by the current function - --> tests/ui/invalid_closure.rs:9:26 - | -9 | let closure_fn = |_args: &PyTuple, _kwargs: Option<&PyDict>| -> PyResult<()> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ may outlive borrowed value `ref_` -10 | println!("This is five: {:?}", ref_.len()); - | ---- `ref_` is borrowed here - | -note: function requires argument type to outlive `'static` - --> tests/ui/invalid_closure.rs:13:9 - | -13 | PyCFunction::new_closure(py, None, None, closure_fn).unwrap().into() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: to force the closure to take ownership of `ref_` (and any other referenced variables), use the `move` keyword - | -9 | let closure_fn = move |_args: &PyTuple, _kwargs: Option<&PyDict>| -> PyResult<()> { - | ++++