From 71012db0e757c4f5461f202b329cf8dc73d38202 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 5 Oct 2024 02:12:23 -0500 Subject: [PATCH] Resolve clippy warnings from nightly (#4601) --- pyo3-ffi/src/cpython/tupleobject.rs | 3 +-- pyo3-macros-backend/src/module.rs | 2 +- pyo3-macros-backend/src/pyclass.rs | 4 ++-- src/buffer.rs | 2 +- src/conversions/std/cell.rs | 2 +- src/conversions/std/num.rs | 2 +- src/conversions/std/osstr.rs | 2 +- src/conversions/std/path.rs | 8 ++++---- src/conversions/std/slice.rs | 2 +- src/conversions/std/string.rs | 6 +++--- src/err/mod.rs | 2 +- src/impl_/pymethods.rs | 2 +- src/instance.rs | 8 ++++---- src/pycell.rs | 18 +++++++++--------- src/pyclass/gc.rs | 2 +- src/types/dict.rs | 2 +- src/types/frozenset.rs | 2 +- src/types/set.rs | 2 +- src/types/tuple.rs | 8 ++++---- tests/test_gc.rs | 2 +- 20 files changed, 40 insertions(+), 41 deletions(-) diff --git a/pyo3-ffi/src/cpython/tupleobject.rs b/pyo3-ffi/src/cpython/tupleobject.rs index 4ed8520daf3..1d988d2bef0 100644 --- a/pyo3-ffi/src/cpython/tupleobject.rs +++ b/pyo3-ffi/src/cpython/tupleobject.rs @@ -12,10 +12,9 @@ pub struct PyTupleObject { // skipped _PyTuple_Resize // skipped _PyTuple_MaybeUntrack -/// Macro, trading safety for speed - // skipped _PyTuple_CAST +/// Macro, trading safety for speed #[inline] #[cfg(not(PyPy))] pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { diff --git a/pyo3-macros-backend/src/module.rs b/pyo3-macros-backend/src/module.rs index e0025fda6dd..7d2c72dbdfb 100644 --- a/pyo3-macros-backend/src/module.rs +++ b/pyo3-macros-backend/src/module.rs @@ -559,7 +559,7 @@ fn find_and_remove_attribute(attrs: &mut Vec, ident: &str) -> bo found } -impl<'a> PartialEq for IdentOrStr<'a> { +impl PartialEq for IdentOrStr<'_> { fn eq(&self, other: &syn::Ident) -> bool { match self { IdentOrStr::Str(s) => other == s, diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index c9fe1956f66..d7edeb0bf24 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -678,7 +678,7 @@ trait EnumVariant { } } -impl<'a> EnumVariant for PyClassEnumVariant<'a> { +impl EnumVariant for PyClassEnumVariant<'_> { fn get_ident(&self) -> &syn::Ident { match self { PyClassEnumVariant::Struct(struct_variant) => struct_variant.ident, @@ -701,7 +701,7 @@ struct PyClassEnumUnitVariant<'a> { cfg_attrs: Vec<&'a syn::Attribute>, } -impl<'a> EnumVariant for PyClassEnumUnitVariant<'a> { +impl EnumVariant for PyClassEnumUnitVariant<'_> { fn get_ident(&self) -> &syn::Ident { self.ident } diff --git a/src/buffer.rs b/src/buffer.rs index ad070e13e05..85144f6ff99 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -182,7 +182,7 @@ pub unsafe trait Element: Copy { fn is_compatible_format(format: &CStr) -> bool; } -impl<'py, T: Element> FromPyObject<'py> for PyBuffer { +impl FromPyObject<'_> for PyBuffer { fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult> { Self::get(obj) } diff --git a/src/conversions/std/cell.rs b/src/conversions/std/cell.rs index 75a8a13a787..3c1ab55c4a7 100644 --- a/src/conversions/std/cell.rs +++ b/src/conversions/std/cell.rs @@ -28,7 +28,7 @@ impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for Cell { } } -impl<'a, 'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for &'a Cell { +impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for &Cell { type Target = T::Target; type Output = T::Output; type Error = T::Error; diff --git a/src/conversions/std/num.rs b/src/conversions/std/num.rs index 80bc678fddf..d1faa905abd 100644 --- a/src/conversions/std/num.rs +++ b/src/conversions/std/num.rs @@ -276,7 +276,7 @@ impl<'py> IntoPyObject<'py> for &'_ u8 { } } -impl<'py> FromPyObject<'py> for u8 { +impl FromPyObject<'_> for u8 { fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult { let val: c_long = extract_int!(obj, -1, ffi::PyLong_AsLong)?; u8::try_from(val).map_err(|e| exceptions::PyOverflowError::new_err(e.to_string())) diff --git a/src/conversions/std/osstr.rs b/src/conversions/std/osstr.rs index 4f956c64ce8..57387b1e600 100644 --- a/src/conversions/std/osstr.rs +++ b/src/conversions/std/osstr.rs @@ -199,7 +199,7 @@ impl<'py> IntoPyObject<'py> for OsString { } } -impl<'a> IntoPy for &'a OsString { +impl IntoPy for &OsString { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() diff --git a/src/conversions/std/path.rs b/src/conversions/std/path.rs index f012cc81a27..615d98e3cd8 100644 --- a/src/conversions/std/path.rs +++ b/src/conversions/std/path.rs @@ -26,7 +26,7 @@ impl FromPyObject<'_> for PathBuf { } } -impl<'a> IntoPy for &'a Path { +impl IntoPy for &Path { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() @@ -55,14 +55,14 @@ impl<'py> IntoPyObject<'py> for &&Path { } } -impl<'a> ToPyObject for Cow<'a, Path> { +impl ToPyObject for Cow<'_, Path> { #[inline] fn to_object(&self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() } } -impl<'a> IntoPy for Cow<'a, Path> { +impl IntoPy for Cow<'_, Path> { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() @@ -116,7 +116,7 @@ impl<'py> IntoPyObject<'py> for PathBuf { } } -impl<'a> IntoPy for &'a PathBuf { +impl IntoPy for &PathBuf { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() diff --git a/src/conversions/std/slice.rs b/src/conversions/std/slice.rs index a90d70a49f7..241c520e847 100644 --- a/src/conversions/std/slice.rs +++ b/src/conversions/std/slice.rs @@ -8,7 +8,7 @@ use crate::{ Bound, IntoPy, Py, PyAny, PyErr, PyObject, PyResult, Python, ToPyObject, }; -impl<'a> IntoPy for &'a [u8] { +impl IntoPy for &[u8] { fn into_py(self, py: Python<'_>) -> PyObject { PyBytes::new(py, self).unbind().into() } diff --git a/src/conversions/std/string.rs b/src/conversions/std/string.rs index 02688641e78..5c634a621bd 100644 --- a/src/conversions/std/string.rs +++ b/src/conversions/std/string.rs @@ -18,7 +18,7 @@ impl ToPyObject for str { } } -impl<'a> IntoPy for &'a str { +impl IntoPy for &str { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() @@ -30,7 +30,7 @@ impl<'a> IntoPy for &'a str { } } -impl<'a> IntoPy> for &'a str { +impl IntoPy> for &str { #[inline] fn into_py(self, py: Python<'_>) -> Py { self.into_pyobject(py).unwrap().unbind() @@ -179,7 +179,7 @@ impl<'py> IntoPyObject<'py> for String { } } -impl<'a> IntoPy for &'a String { +impl IntoPy for &String { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() diff --git a/src/err/mod.rs b/src/err/mod.rs index 2ef9e531768..ac03c2e573e 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -891,7 +891,7 @@ impl ToPyObject for PyErr { } } -impl<'a> IntoPy for &'a PyErr { +impl IntoPy for &PyErr { #[inline] fn into_py(self, py: Python<'_>) -> PyObject { self.into_pyobject(py).unwrap().into_any().unbind() diff --git a/src/impl_/pymethods.rs b/src/impl_/pymethods.rs index 300af22db3a..617bad52ea4 100644 --- a/src/impl_/pymethods.rs +++ b/src/impl_/pymethods.rs @@ -300,7 +300,7 @@ where // ... and we cannot traverse a type which might be being mutated by a Rust thread && class_object.borrow_checker().try_borrow().is_ok() { struct TraverseGuard<'a, T: PyClass>(&'a PyClassObject); - impl<'a, T: PyClass> Drop for TraverseGuard<'a, T> { + impl Drop for TraverseGuard<'_, T> { fn drop(&mut self) { self.0.borrow_checker().release_borrow() } diff --git a/src/instance.rs b/src/instance.rs index 4d5608a9dc0..d476c7cef31 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -43,9 +43,9 @@ mod bound_object_sealed { pub unsafe trait Sealed {} // SAFETY: `Bound` is layout-compatible with `*mut ffi::PyObject`. - unsafe impl<'py, T> Sealed for super::Bound<'py, T> {} + unsafe impl Sealed for super::Bound<'_, T> {} // SAFETY: `Borrowed` is layout-compatible with `*mut ffi::PyObject`. - unsafe impl<'a, 'py, T> Sealed for super::Borrowed<'a, 'py, T> {} + unsafe impl Sealed for super::Borrowed<'_, '_, T> {} } /// A GIL-attached equivalent to [`Py`]. @@ -465,14 +465,14 @@ where } } -impl<'py, T> std::fmt::Debug for Bound<'py, T> { +impl std::fmt::Debug for Bound<'_, T> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { let any = self.as_any(); python_format(any, any.repr(), f) } } -impl<'py, T> std::fmt::Display for Bound<'py, T> { +impl std::fmt::Display for Bound<'_, T> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { let any = self.as_any(); python_format(any, any.str(), f) diff --git a/src/pycell.rs b/src/pycell.rs index 38f82eb27fd..a330e4962dc 100644 --- a/src/pycell.rs +++ b/src/pycell.rs @@ -265,7 +265,7 @@ impl<'p, T: PyClass> PyRef<'p, T> { } } -impl<'p, T, U> AsRef for PyRef<'p, T> +impl AsRef for PyRef<'_, T> where T: PyClass, U: PyClass, @@ -429,7 +429,7 @@ where } } -impl<'p, T: PyClass> Deref for PyRef<'p, T> { +impl Deref for PyRef<'_, T> { type Target = T; #[inline] @@ -438,7 +438,7 @@ impl<'p, T: PyClass> Deref for PyRef<'p, T> { } } -impl<'p, T: PyClass> Drop for PyRef<'p, T> { +impl Drop for PyRef<'_, T> { fn drop(&mut self) { self.inner .get_class_object() @@ -479,7 +479,7 @@ impl<'a, 'py, T: PyClass> IntoPyObject<'py> for &'a PyRef<'py, T> { } } -unsafe impl<'a, T: PyClass> AsPyPointer for PyRef<'a, T> { +unsafe impl AsPyPointer for PyRef<'_, T> { fn as_ptr(&self) -> *mut ffi::PyObject { self.inner.as_ptr() } @@ -508,7 +508,7 @@ impl<'p, T: PyClass> PyRefMut<'p, T> { } } -impl<'p, T, U> AsRef for PyRefMut<'p, T> +impl AsRef for PyRefMut<'_, T> where T: PyClass, U: PyClass, @@ -518,7 +518,7 @@ where } } -impl<'p, T, U> AsMut for PyRefMut<'p, T> +impl AsMut for PyRefMut<'_, T> where T: PyClass, U: PyClass, @@ -611,7 +611,7 @@ where } } -impl<'p, T: PyClass> Deref for PyRefMut<'p, T> { +impl> Deref for PyRefMut<'_, T> { type Target = T; #[inline] @@ -620,14 +620,14 @@ impl<'p, T: PyClass> Deref for PyRefMut<'p, T> { } } -impl<'p, T: PyClass> DerefMut for PyRefMut<'p, T> { +impl> DerefMut for PyRefMut<'_, T> { #[inline] fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.inner.get_class_object().get_ptr() } } } -impl<'p, T: PyClass> Drop for PyRefMut<'p, T> { +impl> Drop for PyRefMut<'_, T> { fn drop(&mut self) { self.inner .get_class_object() diff --git a/src/pyclass/gc.rs b/src/pyclass/gc.rs index b6747a63f89..b95bfa3804f 100644 --- a/src/pyclass/gc.rs +++ b/src/pyclass/gc.rs @@ -25,7 +25,7 @@ pub struct PyVisit<'a> { pub(crate) _guard: PhantomData<&'a ()>, } -impl<'a> PyVisit<'a> { +impl PyVisit<'_> { /// Visit `obj`. pub fn call(&self, obj: &T) -> Result<(), PyTraverseError> where diff --git a/src/types/dict.rs b/src/types/dict.rs index 61767f245cc..ff7595afceb 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -466,7 +466,7 @@ impl<'py> Iterator for BoundDictIterator<'py> { } } -impl<'py> ExactSizeIterator for BoundDictIterator<'py> { +impl ExactSizeIterator for BoundDictIterator<'_> { fn len(&self) -> usize { self.len as usize } diff --git a/src/types/frozenset.rs b/src/types/frozenset.rs index 88d726b136d..524baaa2f08 100644 --- a/src/types/frozenset.rs +++ b/src/types/frozenset.rs @@ -242,7 +242,7 @@ impl<'py> Iterator for BoundFrozenSetIterator<'py> { } } -impl<'py> ExactSizeIterator for BoundFrozenSetIterator<'py> { +impl ExactSizeIterator for BoundFrozenSetIterator<'_> { fn len(&self) -> usize { self.remaining } diff --git a/src/types/set.rs b/src/types/set.rs index eddc2eb8885..3e28b2c20e0 100644 --- a/src/types/set.rs +++ b/src/types/set.rs @@ -279,7 +279,7 @@ impl<'py> Iterator for BoundSetIterator<'py> { } } -impl<'py> ExactSizeIterator for BoundSetIterator<'py> { +impl ExactSizeIterator for BoundSetIterator<'_> { fn len(&self) -> usize { self.remaining } diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 8f26e4d89e6..7c8abfcae91 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -383,7 +383,7 @@ impl<'py> Iterator for BoundTupleIterator<'py> { } } -impl<'py> DoubleEndedIterator for BoundTupleIterator<'py> { +impl DoubleEndedIterator for BoundTupleIterator<'_> { #[inline] fn next_back(&mut self) -> Option { if self.index < self.length { @@ -399,7 +399,7 @@ impl<'py> DoubleEndedIterator for BoundTupleIterator<'py> { } } -impl<'py> ExactSizeIterator for BoundTupleIterator<'py> { +impl ExactSizeIterator for BoundTupleIterator<'_> { fn len(&self) -> usize { self.length.saturating_sub(self.index) } @@ -475,7 +475,7 @@ impl<'a, 'py> Iterator for BorrowedTupleIterator<'a, 'py> { } } -impl<'a, 'py> DoubleEndedIterator for BorrowedTupleIterator<'a, 'py> { +impl DoubleEndedIterator for BorrowedTupleIterator<'_, '_> { #[inline] fn next_back(&mut self) -> Option { if self.index < self.length { @@ -488,7 +488,7 @@ impl<'a, 'py> DoubleEndedIterator for BorrowedTupleIterator<'a, 'py> { } } -impl<'a, 'py> ExactSizeIterator for BorrowedTupleIterator<'a, 'py> { +impl ExactSizeIterator for BorrowedTupleIterator<'_, '_> { fn len(&self) -> usize { self.length.saturating_sub(self.index) } diff --git a/tests/test_gc.rs b/tests/test_gc.rs index 1f55d91d496..ab1302a9d88 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -416,7 +416,7 @@ trait Traversable { fn __traverse__(&self, visit: PyVisit<'_>) -> Result<(), PyTraverseError>; } -impl<'a> Traversable for PyRef<'a, HijackedTraverse> { +impl Traversable for PyRef<'_, HijackedTraverse> { fn __traverse__(&self, _visit: PyVisit<'_>) -> Result<(), PyTraverseError> { self.hijacked.set(true); Ok(())