From 28d6c9986c80a564acc69a00e0c5057293db159d Mon Sep 17 00:00:00 2001 From: konstin Date: Tue, 3 Jul 2018 21:32:16 +0200 Subject: [PATCH] Fix clippy errors --- src/class/gc.rs | 2 +- src/conversion.rs | 1 - src/err.rs | 14 ++++++++------ src/freelist.rs | 4 ++-- src/objects/mod.rs | 6 +++--- src/objects/slice.rs | 18 +++++++++--------- src/pythonrun.rs | 2 +- src/typeob.rs | 12 ++++++------ 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/class/gc.rs b/src/class/gc.rs index 355d27e8..29e270e1 100644 --- a/src/class/gc.rs +++ b/src/class/gc.rs @@ -91,7 +91,7 @@ impl PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p> let py = Python::assume_gil_acquired(); let slf = py.mut_from_borrowed_ptr::(slf); - let visit = PyVisit { visit: visit, arg: arg, _py: py }; + let visit = PyVisit { visit, arg, _py: py }; match slf.__traverse__(visit) { Ok(()) => 0, Err(PyTraverseError(code)) => code diff --git a/src/conversion.rs b/src/conversion.rs index 86e3d0ed..4fde1b07 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -26,7 +26,6 @@ pub trait ToBorrowedObject: ToPyObject { /// /// May be more efficient than `to_object` because it does not need /// to touch any reference counts when the input object already is a Python object. - #[inline] fn with_borrowed_ptr(&self, py: Python, f: F) -> R where F: FnOnce(*mut ffi::PyObject) -> R; } diff --git a/src/err.rs b/src/err.rs index 4b77e243..96c5688d 100644 --- a/src/err.rs +++ b/src/err.rs @@ -286,13 +286,15 @@ impl PyErr { PyErrValue::None }; + let ptype = if ptype.is_null() { + ::type_object() + } else { + Py::from_owned_ptr(ptype) + }; + PyErr { - ptype: if ptype.is_null() { - ::type_object() - } else { - Py::from_owned_ptr(ptype) - }, - pvalue: pvalue, + ptype, + pvalue, ptraceback: PyObject::from_owned_ptr_or_opt(Python::assume_gil_acquired(), ptraceback), } } diff --git a/src/freelist.rs b/src/freelist.rs index e8c9cb65..a1aa34e3 100644 --- a/src/freelist.rs +++ b/src/freelist.rs @@ -35,9 +35,9 @@ impl FreeList { let entries = (0..capacity).map(|_| Slot::Empty).collect::>(); FreeList { - entries: entries, + entries, split: 0, - capacity: capacity, + capacity, } } diff --git a/src/objects/mod.rs b/src/objects/mod.rs index 9ffe3c55..3b5180dc 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -44,7 +44,7 @@ macro_rules! pyobject_downcast( { unsafe { if $crate::ffi::$checkfunction(ob.as_ptr()) != 0 { - Ok($crate::std::mem::transmute(ob)) + Ok(&*(ob as *const $crate::objects::PyObjectRef as *const $name)) } else { Err($crate::PyDowncastError.into()) } @@ -62,7 +62,7 @@ macro_rules! pyobject_native_type_named( impl $crate::std::convert::AsRef<$crate::PyObjectRef> for $name { #[cfg_attr(feature = "cargo-clippy", allow(useless_transmute))] fn as_ref(&self) -> &$crate::PyObjectRef { - unsafe{$crate::std::mem::transmute(self)} + unsafe{&*(self as *const $name as *const $crate::objects::PyObjectRef)} } } @@ -99,7 +99,7 @@ macro_rules! pyobject_native_type( impl<'a> $crate::std::convert::From<&'a $name> for &'a $crate::PyObjectRef { fn from(ob: &'a $name) -> Self { - unsafe{$crate::std::mem::transmute(ob)} + unsafe{&*(ob as *const $name as *const $crate::objects::PyObjectRef)} } } }; diff --git a/src/objects/slice.rs b/src/objects/slice.rs index 49da9431..e93ac9ea 100644 --- a/src/objects/slice.rs +++ b/src/objects/slice.rs @@ -28,9 +28,9 @@ pub struct PySliceIndices { impl PySliceIndices { pub fn new(start: isize, stop: isize, step: isize) -> PySliceIndices { PySliceIndices { - start: start, - stop: stop, - step: step, + start, + stop, + step, slicelength: 0, } } @@ -54,7 +54,7 @@ impl PySlice { pub fn indices(&self, length: c_long) -> PyResult { // non-negative Py_ssize_t should always fit into Rust usize unsafe { - let slicelen: isize = 0; + let slicelength: isize = 0; let start: isize = 0; let stop: isize = 0; let step: isize = 0; @@ -63,13 +63,13 @@ impl PySlice { &start as *const _ as *mut _, &stop as *const _ as *mut _, &step as *const _ as *mut _, - &slicelen as *const _ as *mut _); + &slicelength as *const _ as *mut _); if r == 0{ Ok(PySliceIndices { - start: start, - stop: stop, - step: step, - slicelength: slicelen, + start, + stop, + step, + slicelength, }) } else { Err(PyErr::fetch(self.py())) diff --git a/src/pythonrun.rs b/src/pythonrun.rs index 43b5f918..3459b521 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -261,7 +261,7 @@ impl GILGuard { let pool: &'static mut ReleasePool = &mut *POOL; GILGuard { owned: pool.owned.len(), borrowed: pool.borrowed.len(), - gstate: gstate, + gstate, no_send: marker::PhantomData } } } diff --git a/src/typeob.rs b/src/typeob.rs index 271e70b4..1e29c3f6 100644 --- a/src/typeob.rs +++ b/src/typeob.rs @@ -141,9 +141,9 @@ impl PyRawObject { if !ptr.is_null() { Ok(PyRawObject { - ptr: ptr, - tp_ptr: tp_ptr, - curr_ptr: curr_ptr, + ptr, + tp_ptr, + curr_ptr, // initialized: 0, }) } else { @@ -158,9 +158,9 @@ impl PyRawObject { curr_ptr: *mut ffi::PyTypeObject) -> PyResult { if !ptr.is_null() { Ok(PyRawObject { - ptr: ptr, - tp_ptr: tp_ptr, - curr_ptr: curr_ptr, + ptr, + tp_ptr, + curr_ptr, // initialized: 0, }) } else {