From caf80eca6607db6dfffa1f305c3118423320e9de Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 19 Mar 2024 21:41:27 +0000 Subject: [PATCH] handle clippy `new_without_default` warnings (#3971) * handle clippy `new_without_default` warnings * add newsfragment --- newsfragments/3971.added.md | 1 + pyo3-ffi/src/cpython/object.rs | 1 + pyo3-ffi/src/pybuffer.rs | 1 + src/impl_/pyclass/lazy_type_object.rs | 1 + src/sync.rs | 1 + 5 files changed, 5 insertions(+) create mode 100644 newsfragments/3971.added.md diff --git a/newsfragments/3971.added.md b/newsfragments/3971.added.md new file mode 100644 index 00000000..12c0d226 --- /dev/null +++ b/newsfragments/3971.added.md @@ -0,0 +1 @@ +Implement `Default` for `GILOnceCell`. diff --git a/pyo3-ffi/src/cpython/object.rs b/pyo3-ffi/src/cpython/object.rs index 161fb50c..d0c16340 100644 --- a/pyo3-ffi/src/cpython/object.rs +++ b/pyo3-ffi/src/cpython/object.rs @@ -46,6 +46,7 @@ mod bufferinfo { } impl Py_buffer { + #[allow(clippy::new_without_default)] pub const fn new() -> Self { Py_buffer { buf: ptr::null_mut(), diff --git a/pyo3-ffi/src/pybuffer.rs b/pyo3-ffi/src/pybuffer.rs index a414f333..50bf4e61 100644 --- a/pyo3-ffi/src/pybuffer.rs +++ b/pyo3-ffi/src/pybuffer.rs @@ -27,6 +27,7 @@ pub struct Py_buffer { } impl Py_buffer { + #[allow(clippy::new_without_default)] pub const fn new() -> Self { Py_buffer { buf: ptr::null_mut(), diff --git a/src/impl_/pyclass/lazy_type_object.rs b/src/impl_/pyclass/lazy_type_object.rs index 1318e1ab..efb6ecf3 100644 --- a/src/impl_/pyclass/lazy_type_object.rs +++ b/src/impl_/pyclass/lazy_type_object.rs @@ -32,6 +32,7 @@ struct LazyTypeObjectInner { impl LazyTypeObject { /// Creates an uninitialized `LazyTypeObject`. + #[allow(clippy::new_without_default)] pub const fn new() -> Self { LazyTypeObject( LazyTypeObjectInner { diff --git a/src/sync.rs b/src/sync.rs index 38471fb7..5af49404 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -90,6 +90,7 @@ unsafe impl Sync for GILProtected where T: Send {} /// } /// # Python::with_gil(|py| assert_eq!(get_shared_list(py).len(), 0)); /// ``` +#[derive(Default)] pub struct GILOnceCell(UnsafeCell>); // T: Send is needed for Sync because the thread which drops the GILOnceCell can be different