From 3725b3172421f1597078393fa10052fd00e43c9c Mon Sep 17 00:00:00 2001 From: mejrs Date: Tue, 12 Apr 2022 17:33:15 +0200 Subject: [PATCH] Make clippy happy --- examples/pyo3-pytests/src/buf_and_str.rs | 12 ++++++++---- pyo3-macros-backend/src/lib.rs | 1 - pyo3-macros-backend/src/method.rs | 11 ++++------- pyo3-macros-backend/src/params.rs | 4 ++-- pyo3-macros-backend/src/pyimpl.rs | 2 +- pyo3-macros-backend/src/pymethod.rs | 4 +--- pyo3-macros-backend/src/pyproto.rs | 2 +- src/conversion.rs | 2 -- src/ffi/pyhash.rs | 2 +- src/instance.rs | 4 ---- src/lib.rs | 1 - src/panic.rs | 2 +- tests/test_compile_error.rs | 1 - 13 files changed, 19 insertions(+), 29 deletions(-) diff --git a/examples/pyo3-pytests/src/buf_and_str.rs b/examples/pyo3-pytests/src/buf_and_str.rs index 76e530935a7..b5ce584dec1 100644 --- a/examples/pyo3-pytests/src/buf_and_str.rs +++ b/examples/pyo3-pytests/src/buf_and_str.rs @@ -14,22 +14,26 @@ impl BytesExtractor { BytesExtractor {} } - pub fn from_bytes(&mut self, bytes: &PyBytes) -> PyResult { + #[staticmethod] + pub fn from_bytes(bytes: &PyBytes) -> PyResult { let byte_vec: Vec = bytes.extract()?; Ok(byte_vec.len()) } - pub fn from_str(&mut self, string: &PyString) -> PyResult { + #[staticmethod] + pub fn from_str(string: &PyString) -> PyResult { let rust_string: String = string.extract()?; Ok(rust_string.len()) } - pub fn from_str_lossy(&mut self, string: &PyString) -> PyResult { + #[staticmethod] + pub fn from_str_lossy(string: &PyString) -> PyResult { let rust_string_lossy: String = string.to_string_lossy().to_string(); Ok(rust_string_lossy.len()) } - pub fn from_buffer(&mut self, buf: &PyAny) -> PyResult { + #[staticmethod] + pub fn from_buffer(buf: &PyAny) -> PyResult { let buf = PyBuffer::::get(buf)?; Ok(buf.item_count()) } diff --git a/pyo3-macros-backend/src/lib.rs b/pyo3-macros-backend/src/lib.rs index f42bd3b9a6f..14d1c2565b5 100644 --- a/pyo3-macros-backend/src/lib.rs +++ b/pyo3-macros-backend/src/lib.rs @@ -3,7 +3,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![recursion_limit = "1024"] - // Listed first so that macros in this module are available in the rest of the crate. #[macro_use] mod utils; diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index e57ef33780b..2858338fd00 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -29,9 +29,7 @@ impl<'a> FnArg<'a> { /// Transforms a rust fn arg parsed with syn into a method::FnArg pub fn parse(arg: &'a mut syn::FnArg) -> Result { match arg { - syn::FnArg::Receiver(recv) => { - bail_spanned!(recv.span() => "unexpected receiver") - } // checked in parse_fn_type + syn::FnArg::Receiver(recv) => bail_spanned!(recv.span() => "unexpected receiver"), // checked in parse_fn_type syn::FnArg::Typed(cap) => { if let syn::Type::ImplTrait(_) = &*cap.ty { bail_spanned!(cap.ty.span() => IMPL_TRAIT_ERR); @@ -101,9 +99,7 @@ impl FnType { cls.expect("no class given for Fn with a \"self\" receiver"), error_mode, ), - FnType::FnNew | FnType::FnStatic | FnType::ClassAttribute => { - quote!() - } + FnType::FnNew | FnType::FnStatic | FnType::ClassAttribute => quote!(), FnType::FnClass => { quote! { let _slf = ::pyo3::types::PyType::from_type_ptr(_py, _slf as *mut ::pyo3::ffi::PyTypeObject); @@ -352,7 +348,8 @@ impl<'a> FnSpec<'a> { parse_method_receiver(first_arg) }; - #[allow(clippy::manual_strip)] // for strip_prefix replacement supporting rust < 1.45 + #[allow(clippy::manual_strip)] + // for strip_prefix replacement supporting rust < 1.45 // strip get_ or set_ let strip_fn_name = |prefix: &'static str| { let ident = name.unraw().to_string(); diff --git a/pyo3-macros-backend/src/params.rs b/pyo3-macros-backend/src/params.rs index 1bbbb4727d8..c06c64e6de2 100644 --- a/pyo3-macros-backend/src/params.rs +++ b/pyo3-macros-backend/src/params.rs @@ -266,7 +266,7 @@ fn impl_arg_param( } }; - return if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(ty)) { + if let syn::Type::Reference(tref) = unwrap_ty_group(arg.optional.unwrap_or(ty)) { let mut tref = remove_lifetime(tref); if let Some(cls) = self_ { replace_self(&mut tref.elem, cls); @@ -298,5 +298,5 @@ fn impl_arg_param( Ok(quote_arg_span! { let #arg_name = #arg_value_or_default; }) - }; + } } diff --git a/pyo3-macros-backend/src/pyimpl.rs b/pyo3-macros-backend/src/pyimpl.rs index 54e248c9593..e0dcebd6e74 100644 --- a/pyo3-macros-backend/src/pyimpl.rs +++ b/pyo3-macros-backend/src/pyimpl.rs @@ -36,7 +36,7 @@ pub fn build_py_methods( pub fn impl_methods( ty: &syn::Type, - impls: &mut Vec, + impls: &mut [syn::ImplItem], methods_type: PyClassMethodsType, ) -> syn::Result { let mut trait_impls = Vec::new(); diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index 13a49f92734..8cdb2e06dc2 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -138,9 +138,7 @@ pub fn gen_py_method( cls, PropertyType::Function { self_type, spec }, )?), - (_, FnType::FnModule) => { - unreachable!("methods cannot be FnModule") - } + (_, FnType::FnModule) => unreachable!("methods cannot be FnModule"), }) } diff --git a/pyo3-macros-backend/src/pyproto.rs b/pyo3-macros-backend/src/pyproto.rs index 23e5d8a5d5d..6c02fb57367 100644 --- a/pyo3-macros-backend/src/pyproto.rs +++ b/pyo3-macros-backend/src/pyproto.rs @@ -45,7 +45,7 @@ pub fn build_py_proto(ast: &mut syn::ItemImpl) -> syn::Result { fn impl_proto_impl( ty: &syn::Type, - impls: &mut Vec, + impls: &mut [syn::ImplItem], proto: &defs::Proto, ) -> syn::Result { let mut trait_impls = TokenStream::new(); diff --git a/src/conversion.rs b/src/conversion.rs index ccd690bee15..e7cee002337 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -195,7 +195,6 @@ where /// } /// } /// } -/// # fn main() { /// # Python::with_gil(|py| { /// # let v = Value::Integer(73).into_py(py); /// # let v = v.extract::(py).unwrap(); @@ -206,7 +205,6 @@ where /// # let v = Value::None.into_py(py); /// # let v = v.extract::>>(py).unwrap(); /// # }); -/// # } /// ``` /// Python code will see this as any of the `int`, `string` or `None` objects. #[cfg_attr(docsrs, doc(alias = "IntoPyCallbackOutput"))] diff --git a/src/ffi/pyhash.rs b/src/ffi/pyhash.rs index 703f6245467..736f115ea54 100644 --- a/src/ffi/pyhash.rs +++ b/src/ffi/pyhash.rs @@ -14,7 +14,7 @@ extern "C" { pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t; } -pub const _PyHASH_MULTIPLIER: c_ulong = 1000003; +pub const _PyHASH_MULTIPLIER: c_ulong = 1_000_003; // skipped _PyHASH_BITS diff --git a/src/instance.rs b/src/instance.rs index 330e409967e..472f6bef7f8 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -172,7 +172,6 @@ pub unsafe trait PyNativeType: Sized { /// use pyo3::prelude::*; /// use pyo3::types::PyDict; /// -/// # fn main() { /// Python::with_gil(|py| { /// let first: Py = PyDict::new(py).into(); /// @@ -190,7 +189,6 @@ pub unsafe trait PyNativeType: Sized { /// assert_eq!(fourth.as_ptr(), fifth.as_ptr()); /// assert_eq!(second.as_ptr(), fourth.as_ptr()); /// }); -/// # } /// ``` /// /// # Preventing reference cycles @@ -479,7 +477,6 @@ impl Py { /// use pyo3::prelude::*; /// use pyo3::types::PyDict; /// - /// # fn main() { /// Python::with_gil(|py| { /// let first: Py = PyDict::new(py).into(); /// let second = Py::clone_ref(&first, py); @@ -487,7 +484,6 @@ impl Py { /// // Both point to the same object /// assert_eq!(first.as_ptr(), second.as_ptr()); /// }); - /// # } /// ``` #[inline] pub fn clone_ref(&self, py: Python) -> Py { diff --git a/src/lib.rs b/src/lib.rs index 14bc7466d3e..2c676ad9e32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,6 @@ // Deny some lints in doctests. // Use `#[allow(...)]` locally to override. #![doc(test(attr(deny(warnings), allow(unused_variables, unused_assignments))))] - //! Rust bindings to the Python interpreter. //! //! PyO3 can be used to write native Python modules or run Python code and modules from Rust. diff --git a/src/panic.rs b/src/panic.rs index cf1dd3701e3..da612e8ae9e 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -21,7 +21,7 @@ impl PanicException { if let Some(string) = payload.downcast_ref::() { Self::new_err((string.clone(),)) } else if let Some(s) = payload.downcast_ref::<&str>() { - Self::new_err((s.to_string(),)) + Self::new_err(((*s).to_string(),)) } else { Self::new_err(("panic from Rust code",)) } diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index 87492944b3f..bafaf065751 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -63,7 +63,6 @@ fn _test_compile_errors() { #[rustversion::before(1.56)] fn tests_rust_1_56(_t: &trybuild::TestCases) {} - #[rustversion::since(1.60)] fn tests_rust_1_60(t: &trybuild::TestCases) { t.compile_fail("tests/ui/invalid_pymethod_receiver.rs");