Bump Rust edition to 2021 and make current Clippy happy.

This commit is contained in:
Adam Reichold 2023-06-07 20:49:27 +02:00
parent c1a0b8836d
commit 0d30bb7d3d
22 changed files with 24 additions and 45 deletions

View File

@ -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

View File

@ -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

View File

@ -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"] }

View File

@ -1,7 +1,7 @@
[package]
name = "decorator"
version = "0.1.0"
edition = "2018"
edition = "2021"
[lib]
name = "decorator"

View File

@ -1,7 +1,7 @@
[package]
name = "maturin-starter"
version = "0.1.0"
edition = "2018"
edition = "2021"
[lib]
name = "maturin_starter"

View File

@ -1,7 +1,7 @@
[package]
name = "setuptools-rust-starter"
version = "0.1.0"
edition = "2018"
edition = "2021"
[lib]
name = "setuptools_rust_starter"

View File

@ -1,7 +1,7 @@
[package]
name = "word-count"
version = "0.1.0"
edition = "2018"
edition = "2021"
[lib]
name = "word_count"

View File

@ -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::*;

View File

@ -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"

View File

@ -1,7 +1,7 @@
[package]
name = "pyo3-ffi-check"
version = "0.1.0"
edition = "2018"
edition = "2021"
publish = false
[dependencies]

View File

@ -1,7 +1,7 @@
[package]
name = "pyo3-ffi-check-macro"
version = "0.1.0"
edition = "2018"
edition = "2021"
publish = false
[lib]

View File

@ -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]

View File

@ -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::<Py_ssize_t>() 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(

View File

@ -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.

View File

@ -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);

View File

@ -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

View File

@ -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]

View File

@ -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<usize, &'static str> {

View File

@ -139,7 +139,7 @@
//! [package]
//! name = "string-sum"
//! version = "0.1.0"
//! edition = "2018"
//! edition = "2021"
//!
//! [lib]
//! name = "string_sum"

View File

@ -499,7 +499,6 @@ impl<T: PyClass> PyCell<T> {
/// 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<T>, contents) + offset_of!(PyCellContents<T>, dict);
@ -511,7 +510,6 @@ impl<T: PyClass> PyCell<T> {
/// 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<T>, contents) + offset_of!(PyCellContents<T>, weakref);

View File

@ -56,6 +56,6 @@ pub struct Foo4 {
field: i32,
#[pyo3(get, set)]
#[cfg(any(not(FALSE)))]
#[cfg(not(FALSE))]
field: u32,
}

View File

@ -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<()> {
| ++++