Make clippy happy

This commit is contained in:
konstin 2018-11-14 16:49:48 +01:00
parent 0890f24391
commit 5f175a41cf
11 changed files with 17 additions and 13 deletions

View File

@ -54,6 +54,7 @@ where
T: PyBufferProtocol<'p>, T: PyBufferProtocol<'p>,
{ {
#[inline] #[inline]
#[allow(clippy::needless_update)] // For python 2 it's not useless
fn tp_as_buffer() -> Option<ffi::PyBufferProcs> { fn tp_as_buffer() -> Option<ffi::PyBufferProcs> {
Some(ffi::PyBufferProcs { Some(ffi::PyBufferProcs {
bf_getbuffer: Self::cb_bf_getbuffer(), bf_getbuffer: Self::cb_bf_getbuffer(),

View File

@ -1,4 +1,4 @@
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::type_complexity))]
//! FFI bindings to the functions and structs defined in `datetime.h` //! FFI bindings to the functions and structs defined in `datetime.h`
//! //!

View File

@ -5,10 +5,10 @@ use std::os::raw::{
c_char, c_double, c_int, c_long, c_longlong, c_uchar, c_ulong, c_ulonglong, c_void, c_char, c_double, c_int, c_long, c_longlong, c_uchar, c_ulong, c_ulonglong, c_void,
}; };
/// In the python doc this opaque, but we know we can cast, so we make clippy happy by telling
/// it that it actually looks like a PyObject
#[repr(C)] #[repr(C)]
pub struct PyLongObject { pub struct PyLongObject(PyObject);
_private: [u8; 0],
}
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" { extern "C" {

View File

@ -1,7 +1,7 @@
//! Rust FFI declarations for Python 3 //! Rust FFI declarations for Python 3
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
#![cfg_attr(Py_LIMITED_API, allow(unused_imports))] #![cfg_attr(Py_LIMITED_API, allow(unused_imports))]
#![cfg_attr(feature="cargo-clippy", allow(inline_always))] #![cfg_attr(feature="cargo-clippy", allow(clippy::inline_always))]
pub use self::pymem::*; pub use self::pymem::*;
pub use self::pyport::*; pub use self::pyport::*;

View File

@ -176,7 +176,7 @@ impl PyObject {
/// Calls the object. /// Calls the object.
/// This is equivalent to the Python expression: 'self(*args, **kwargs)' /// This is equivalent to the Python expression: 'self(*args, **kwargs)'
pub fn call<A>(&self, py: Python, args: A, kwargs: Option<PyDict>) -> PyResult<PyObject> pub fn call<A>(&self, py: Python, args: A, kwargs: Option<&PyDict>) -> PyResult<PyObject>
where where
A: IntoPyTuple, A: IntoPyTuple,
{ {

View File

@ -85,7 +85,7 @@ pub const PY_TYPE_FLAG_DICT: usize = 1 << 3;
/// impl MyClass { /// impl MyClass {
/// #[new] /// #[new]
/// fn __new__(obj: &PyRawObject) -> PyResult<()> { /// fn __new__(obj: &PyRawObject) -> PyResult<()> {
/// obj.init(|| MyClass { }) /// obj.init(|| MyClass { })
/// } /// }
/// } /// }
/// ``` /// ```
@ -149,7 +149,7 @@ impl PyRawObject {
let value = f(); let value = f();
unsafe { unsafe {
let ptr = (self.ptr as *mut u8).offset(T::OFFSET) as *mut T; let ptr = self.ptr.offset(T::OFFSET) as *mut T;
std::ptr::write(ptr, value); std::ptr::write(ptr, value);
} }
Ok(()) Ok(())

View File

@ -14,7 +14,7 @@ pyobject_native_type!(PyComplex, ffi::PyComplex_Type, ffi::PyComplex_Check);
impl PyComplex { impl PyComplex {
/// Creates a new Python `PyComplex` object, from its real and imaginary values. /// Creates a new Python `PyComplex` object, from its real and imaginary values.
pub fn from_doubles<'p>(py: Python<'p>, real: c_double, imag: c_double) -> &'p PyComplex { pub fn from_doubles(py: Python, real: c_double, imag: c_double) -> &PyComplex {
unsafe { unsafe {
let ptr = ffi::PyComplex_FromDoubles(real, imag); let ptr = ffi::PyComplex_FromDoubles(real, imag);
py.from_owned_ptr(ptr) py.from_owned_ptr(ptr)

View File

@ -2,6 +2,9 @@
//! //!
//! For more details about these types, see the [Python //! For more details about these types, see the [Python
//! documentation](https://docs.python.org/3/library/datetime.html) //! documentation](https://docs.python.org/3/library/datetime.html)
#![allow(clippy::too_many_arguments)]
use crate::conversion::ToPyObject; use crate::conversion::ToPyObject;
use crate::err::PyResult; use crate::err::PyResult;
use crate::ffi; use crate::ffi;

View File

@ -51,7 +51,7 @@ impl IntoPyObject for f64 {
impl<'source> FromPyObject<'source> for f64 { impl<'source> FromPyObject<'source> for f64 {
// PyFloat_AsDouble returns -1.0 upon failure // PyFloat_AsDouble returns -1.0 upon failure
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self> { fn extract(obj: &'source PyObjectRef) -> PyResult<Self> {
let v = unsafe { ffi::PyFloat_AsDouble(obj.as_ptr()) }; let v = unsafe { ffi::PyFloat_AsDouble(obj.as_ptr()) };

View File

@ -30,7 +30,7 @@ pyobject_native_type!(PyLong, ffi::PyLong_Type, ffi::PyLong_Check);
macro_rules! int_fits_c_long ( macro_rules! int_fits_c_long (
($rust_type:ty) => ( ($rust_type:ty) => (
impl ToPyObject for $rust_type { impl ToPyObject for $rust_type {
#![cfg_attr(feature="cargo-clippy", allow(cast_lossless))] #![cfg_attr(feature="cargo-clippy", allow(clippy::cast_lossless))]
fn to_object(&self, py: Python) -> PyObject { fn to_object(&self, py: Python) -> PyObject {
unsafe { unsafe {
PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(*self as c_long)) PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(*self as c_long))
@ -38,7 +38,7 @@ macro_rules! int_fits_c_long (
} }
} }
impl IntoPyObject for $rust_type { impl IntoPyObject for $rust_type {
#![cfg_attr(feature="cargo-clippy", allow(cast_lossless))] #![cfg_attr(feature="cargo-clippy", allow(clippy::cast_lossless))]
fn into_object(self, py: Python) -> PyObject { fn into_object(self, py: Python) -> PyObject {
unsafe { unsafe {
PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(self as c_long)) PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(self as c_long))

View File

@ -5,7 +5,7 @@ use std::os::raw::c_int;
use crate::err::{PyErr, PyResult}; use crate::err::{PyErr, PyResult};
use crate::python::Python; use crate::python::Python;
pub(super) fn err_if_invalid_value<T: PartialEq>( pub(super) fn err_if_invalid_value<T: PartialEq + Copy>(
py: Python, py: Python,
invalid_value: T, invalid_value: T,
actual_value: T, actual_value: T,