From 90c5ffbd043309eb73a3363602c1c038b6b18de7 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 26 Mar 2021 13:21:38 +0800 Subject: [PATCH] Fix clippy warnings in Rust 1.51.0 --- src/class/gc.rs | 4 ++++ src/class/impl_.rs | 1 + src/class/macros.rs | 1 + src/class/number.rs | 5 +++++ src/exceptions.rs | 1 + src/gil.rs | 3 +++ src/lib.rs | 2 +- src/once_cell.rs | 1 + tests/test_gc.rs | 12 ++++++------ 9 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/class/gc.rs b/src/class/gc.rs index 667d97ae..e4112afa 100644 --- a/src/class/gc.rs +++ b/src/class/gc.rs @@ -10,12 +10,16 @@ use std::os::raw::{c_int, c_void}; pub struct PyTraverseError(c_int); /// GC support +#[allow(clippy::upper_case_acronyms)] pub trait PyGCProtocol<'p>: PyClass { fn __traverse__(&'p self, visit: PyVisit) -> Result<(), PyTraverseError>; fn __clear__(&'p mut self); } +#[allow(clippy::upper_case_acronyms)] pub trait PyGCTraverseProtocol<'p>: PyGCProtocol<'p> {} + +#[allow(clippy::upper_case_acronyms)] pub trait PyGCClearProtocol<'p>: PyGCProtocol<'p> {} #[doc(hidden)] diff --git a/src/class/impl_.rs b/src/class/impl_.rs index a5763453..4e87df97 100644 --- a/src/class/impl_.rs +++ b/src/class/impl_.rs @@ -140,6 +140,7 @@ methods_trait!(PyMethods, py_methods); macro_rules! slots_trait { ($name:ident, $function_name: ident) => { + #[allow(clippy::upper_case_acronyms)] pub trait $name { fn $function_name(self) -> &'static [ffi::PyType_Slot]; } diff --git a/src/class/macros.rs b/src/class/macros.rs index 719f9d4d..859501e7 100644 --- a/src/class/macros.rs +++ b/src/class/macros.rs @@ -162,6 +162,7 @@ macro_rules! py_binary_self_func { $crate::callback_body!(py, { let slf_ = py.from_borrowed_ptr::<$crate::PyCell>(slf); let arg = py.from_borrowed_ptr::<$crate::PyAny>(arg); + #[allow(clippy::needless_question_mark)] call_operator_mut!(py, slf_, $f, arg).convert(py)?; ffi::Py_INCREF(slf); Ok::<_, $crate::err::PyErr>(slf) diff --git a/src/class/number.rs b/src/class/number.rs index 36eae307..a093df12 100644 --- a/src/class/number.rs +++ b/src/class/number.rs @@ -446,11 +446,13 @@ pub trait PyNumberRPowProtocol<'p>: PyNumberProtocol<'p> { type Result: IntoPyCallbackOutput; } +#[allow(clippy::upper_case_acronyms)] pub trait PyNumberRLShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: IntoPyCallbackOutput; } +#[allow(clippy::upper_case_acronyms)] pub trait PyNumberRRShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: IntoPyCallbackOutput; @@ -516,11 +518,13 @@ pub trait PyNumberIPowProtocol<'p>: PyNumberProtocol<'p> { type Result: IntoPyCallbackOutput<()>; } +#[allow(clippy::upper_case_acronyms)] pub trait PyNumberILShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: IntoPyCallbackOutput<()>; } +#[allow(clippy::upper_case_acronyms)] pub trait PyNumberIRShiftProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Result: IntoPyCallbackOutput<()>; @@ -738,6 +742,7 @@ where crate::callback_body!(py, { let slf_cell = py.from_borrowed_ptr::>(slf); let other = py.from_borrowed_ptr::(other); + #[allow(clippy::needless_question_mark)] call_operator_mut!(py, slf_cell, __ipow__, other).convert(py)?; ffi::Py_INCREF(slf); Ok::<_, PyErr>(slf) diff --git a/src/exceptions.rs b/src/exceptions.rs index 16969f8a..b2efa8a7 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -197,6 +197,7 @@ macro_rules! create_exception_type_object { macro_rules! impl_native_exception ( ($name:ident, $exc_name:ident, $layout:path) => ( + #[allow(clippy::upper_case_acronyms)] pub struct $name($crate::PyAny); $crate::impl_exception_boilerplate!($name); diff --git a/src/gil.rs b/src/gil.rs index ac22a626..d2ad8220 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -193,6 +193,7 @@ where /// let py = gil_guard.python(); /// } // GIL is released when gil_guard is dropped /// ``` +#[allow(clippy::upper_case_acronyms)] #[must_use] pub struct GILGuard { gstate: ffi::PyGILState_STATE, @@ -367,6 +368,7 @@ unsafe impl Sync for ReferencePool {} static POOL: ReferencePool = ReferencePool::new(); /// A RAII pool which PyO3 uses to store owned Python references. +#[allow(clippy::upper_case_acronyms)] pub struct GILPool { /// Initial length of owned objects and anys. /// `Option` is used since TSL can be broken when `new` is called from `atexit`. @@ -495,6 +497,7 @@ pub(crate) fn ensure_gil() -> EnsureGIL { } /// Struct used internally which avoids acquiring the GIL where it's not necessary. +#[allow(clippy::upper_case_acronyms)] pub(crate) struct EnsureGIL(Option); impl EnsureGIL { diff --git a/src/lib.rs b/src/lib.rs index 5518548b..5124ebf3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,7 +191,7 @@ pub mod derive_utils; mod err; pub mod exceptions; /// Raw ffi declarations for the c interface of python -#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::upper_case_acronyms)] #[allow(clippy::missing_safety_doc)] pub mod ffi; pub mod freelist; diff --git a/src/once_cell.rs b/src/once_cell.rs index fbd90f82..0aaee72c 100644 --- a/src/once_cell.rs +++ b/src/once_cell.rs @@ -27,6 +27,7 @@ use std::cell::UnsafeCell; /// } /// # Python::with_gil(|py| assert_eq!(get_shared_list(py).len(), 0)); /// ``` +#[allow(clippy::upper_case_acronyms)] pub struct GILOnceCell(UnsafeCell>); // T: Send is needed for Sync because the thread which drops the GILOnceCell can be different diff --git a/tests/test_gc.rs b/tests/test_gc.rs index 9aa5252e..3d8f64bc 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -82,13 +82,13 @@ fn data_is_dropped() { #[allow(dead_code)] #[pyclass] -struct GCIntegration { +struct GcIntegration { self_ref: PyObject, dropped: TestDropCall, } #[pyproto] -impl PyGCProtocol for GCIntegration { +impl PyGCProtocol for GcIntegration { fn __traverse__(&self, visit: PyVisit) -> Result<(), PyTraverseError> { visit.call(&self.self_ref) } @@ -108,7 +108,7 @@ fn gc_integration() { let py = gil.python(); let inst = PyCell::new( py, - GCIntegration { + GcIntegration { self_ref: py.None(), dropped: TestDropCall { drop_called: Arc::clone(&drop_called), @@ -128,10 +128,10 @@ fn gc_integration() { } #[pyclass(gc)] -struct GCIntegration2 {} +struct GcIntegration2 {} #[pyproto] -impl PyGCProtocol for GCIntegration2 { +impl PyGCProtocol for GcIntegration2 { fn __traverse__(&self, _visit: PyVisit) -> Result<(), PyTraverseError> { Ok(()) } @@ -142,7 +142,7 @@ impl PyGCProtocol for GCIntegration2 { fn gc_integration2() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = PyCell::new(py, GCIntegration2 {}).unwrap(); + let inst = PyCell::new(py, GcIntegration2 {}).unwrap(); py_run!(py, inst, "import gc; assert inst in gc.get_objects()"); }