Skip to content

Commit

Permalink
Resolve clippy warnings from nightly (#4601)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Oct 5, 2024
1 parent d03d102 commit 71012db
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 41 deletions.
3 changes: 1 addition & 2 deletions pyo3-ffi/src/cpython/tupleobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pyo3-macros-backend/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ fn find_and_remove_attribute(attrs: &mut Vec<syn::Attribute>, ident: &str) -> bo
found
}

impl<'a> PartialEq<syn::Ident> for IdentOrStr<'a> {
impl PartialEq<syn::Ident> for IdentOrStr<'_> {
fn eq(&self, other: &syn::Ident) -> bool {
match self {
IdentOrStr::Str(s) => other == s,
Expand Down
4 changes: 2 additions & 2 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub unsafe trait Element: Copy {
fn is_compatible_format(format: &CStr) -> bool;
}

impl<'py, T: Element> FromPyObject<'py> for PyBuffer<T> {
impl<T: Element> FromPyObject<'_> for PyBuffer<T> {
fn extract_bound(obj: &Bound<'_, PyAny>) -> PyResult<PyBuffer<T>> {
Self::get(obj)
}
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/std/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for Cell<T> {
}
}

impl<'a, 'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for &'a Cell<T> {
impl<'py, T: Copy + IntoPyObject<'py>> IntoPyObject<'py> for &Cell<T> {
type Target = T::Target;
type Output = T::Output;
type Error = T::Error;
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/std/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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()))
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/std/osstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'py> IntoPyObject<'py> for OsString {
}
}

impl<'a> IntoPy<PyObject> for &'a OsString {
impl IntoPy<PyObject> for &OsString {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
self.into_pyobject(py).unwrap().into_any().unbind()
Expand Down
8 changes: 4 additions & 4 deletions src/conversions/std/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl FromPyObject<'_> for PathBuf {
}
}

impl<'a> IntoPy<PyObject> for &'a Path {
impl IntoPy<PyObject> for &Path {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
self.into_pyobject(py).unwrap().into_any().unbind()
Expand Down Expand Up @@ -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<PyObject> for Cow<'a, Path> {
impl IntoPy<PyObject> for Cow<'_, Path> {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
self.into_pyobject(py).unwrap().into_any().unbind()
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<'py> IntoPyObject<'py> for PathBuf {
}
}

impl<'a> IntoPy<PyObject> for &'a PathBuf {
impl IntoPy<PyObject> for &PathBuf {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
self.into_pyobject(py).unwrap().into_any().unbind()
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/std/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
Bound, IntoPy, Py, PyAny, PyErr, PyObject, PyResult, Python, ToPyObject,
};

impl<'a> IntoPy<PyObject> for &'a [u8] {
impl IntoPy<PyObject> for &[u8] {
fn into_py(self, py: Python<'_>) -> PyObject {
PyBytes::new(py, self).unbind().into()
}
Expand Down
6 changes: 3 additions & 3 deletions src/conversions/std/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl ToPyObject for str {
}
}

impl<'a> IntoPy<PyObject> for &'a str {
impl IntoPy<PyObject> for &str {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
self.into_pyobject(py).unwrap().into_any().unbind()
Expand All @@ -30,7 +30,7 @@ impl<'a> IntoPy<PyObject> for &'a str {
}
}

impl<'a> IntoPy<Py<PyString>> for &'a str {
impl IntoPy<Py<PyString>> for &str {
#[inline]
fn into_py(self, py: Python<'_>) -> Py<PyString> {
self.into_pyobject(py).unwrap().unbind()
Expand Down Expand Up @@ -179,7 +179,7 @@ impl<'py> IntoPyObject<'py> for String {
}
}

impl<'a> IntoPy<PyObject> for &'a String {
impl IntoPy<PyObject> for &String {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
self.into_pyobject(py).unwrap().into_any().unbind()
Expand Down
2 changes: 1 addition & 1 deletion src/err/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ impl ToPyObject for PyErr {
}
}

impl<'a> IntoPy<PyObject> for &'a PyErr {
impl IntoPy<PyObject> for &PyErr {
#[inline]
fn into_py(self, py: Python<'_>) -> PyObject {
self.into_pyobject(py).unwrap().into_any().unbind()
Expand Down
2 changes: 1 addition & 1 deletion src/impl_/pymethods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>);
impl<'a, T: PyClass> Drop for TraverseGuard<'a, T> {
impl<T: PyClass> Drop for TraverseGuard<'_, T> {
fn drop(&mut self) {
self.0.borrow_checker().release_borrow()
}
Expand Down
8 changes: 4 additions & 4 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> 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<T> Sealed for super::Borrowed<'_, '_, T> {}
}

/// A GIL-attached equivalent to [`Py<T>`].
Expand Down Expand Up @@ -465,14 +465,14 @@ where
}
}

impl<'py, T> std::fmt::Debug for Bound<'py, T> {
impl<T> 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<T> 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)
Expand Down
18 changes: 9 additions & 9 deletions src/pycell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<'p, T: PyClass> PyRef<'p, T> {
}
}

impl<'p, T, U> AsRef<U> for PyRef<'p, T>
impl<T, U> AsRef<U> for PyRef<'_, T>
where
T: PyClass<BaseType = U>,
U: PyClass,
Expand Down Expand Up @@ -429,7 +429,7 @@ where
}
}

impl<'p, T: PyClass> Deref for PyRef<'p, T> {
impl<T: PyClass> Deref for PyRef<'_, T> {
type Target = T;

#[inline]
Expand All @@ -438,7 +438,7 @@ impl<'p, T: PyClass> Deref for PyRef<'p, T> {
}
}

impl<'p, T: PyClass> Drop for PyRef<'p, T> {
impl<T: PyClass> Drop for PyRef<'_, T> {
fn drop(&mut self) {
self.inner
.get_class_object()
Expand Down Expand Up @@ -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<T: PyClass> AsPyPointer for PyRef<'_, T> {
fn as_ptr(&self) -> *mut ffi::PyObject {
self.inner.as_ptr()
}
Expand Down Expand Up @@ -508,7 +508,7 @@ impl<'p, T: PyClass<Frozen = False>> PyRefMut<'p, T> {
}
}

impl<'p, T, U> AsRef<U> for PyRefMut<'p, T>
impl<T, U> AsRef<U> for PyRefMut<'_, T>
where
T: PyClass<BaseType = U, Frozen = False>,
U: PyClass<Frozen = False>,
Expand All @@ -518,7 +518,7 @@ where
}
}

impl<'p, T, U> AsMut<U> for PyRefMut<'p, T>
impl<T, U> AsMut<U> for PyRefMut<'_, T>
where
T: PyClass<BaseType = U, Frozen = False>,
U: PyClass<Frozen = False>,
Expand Down Expand Up @@ -611,7 +611,7 @@ where
}
}

impl<'p, T: PyClass<Frozen = False>> Deref for PyRefMut<'p, T> {
impl<T: PyClass<Frozen = False>> Deref for PyRefMut<'_, T> {
type Target = T;

#[inline]
Expand All @@ -620,14 +620,14 @@ impl<'p, T: PyClass<Frozen = False>> Deref for PyRefMut<'p, T> {
}
}

impl<'p, T: PyClass<Frozen = False>> DerefMut for PyRefMut<'p, T> {
impl<T: PyClass<Frozen = False>> 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<Frozen = False>> Drop for PyRefMut<'p, T> {
impl<T: PyClass<Frozen = False>> Drop for PyRefMut<'_, T> {
fn drop(&mut self) {
self.inner
.get_class_object()
Expand Down
2 changes: 1 addition & 1 deletion src/pyclass/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct PyVisit<'a> {
pub(crate) _guard: PhantomData<&'a ()>,
}

impl<'a> PyVisit<'a> {
impl PyVisit<'_> {
/// Visit `obj`.
pub fn call<T>(&self, obj: &T) -> Result<(), PyTraverseError>
where
Expand Down
2 changes: 1 addition & 1 deletion src/types/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/frozenset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions src/types/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Item> {
if self.index < self.length {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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<Self::Item> {
if self.index < self.length {
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down

0 comments on commit 71012db

Please sign in to comment.