diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 13d77152..d25765cc 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -19,6 +19,8 @@ _latest() { curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$TRAVIS_RUST_VERSION export PATH=$PATH:$HOME/.cargo/bin +rustup component add clippy-preview + ### Setup kcov ################################################################# @@ -41,4 +43,4 @@ PYTHON_LIB=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PYTHON_LIB:$HOME/rust/lib" -echo ${LD_LIBRARY_PATH} \ No newline at end of file +echo ${LD_LIBRARY_PATH} diff --git a/ci/travis/test.sh b/ci/travis/test.sh index cd4b9c5f..acd602a2 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -3,6 +3,7 @@ set -ex cargo build --features $FEATURES +cargo clippy --features $FEATURES cargo test --features $FEATURES for example in examples/*; do diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 9b1bc4ca..4a6bc41d 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -545,6 +545,7 @@ impl Clone for PyHeapTypeObject { // access macro to the members which are floating "behind" the object #[inline] +#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))] pub unsafe fn PyHeapType_GET_MEMBERS( etype: *mut PyHeapTypeObject, ) -> *mut ffi2::structmember::PyMemberDef { @@ -671,6 +672,8 @@ extern "C" { // Flag bits for printing: pub const Py_PRINT_RAW: c_int = 1; // No string quotes etc. +// https://github.com/rust-lang-nursery/rust-clippy/issues/3430 +#[cfg_attr(feature = "cargo-clippy", allow(clippy::identity_op))] // PyBufferProcs contains bf_getcharbuffer pub const Py_TPFLAGS_HAVE_GETCHARBUFFER: c_long = (1 << 0); @@ -745,8 +748,7 @@ pub const Py_TPFLAGS_DEFAULT: c_long = (Py_TPFLAGS_HAVE_GETCHARBUFFER | Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_CLASS | Py_TPFLAGS_HAVE_STACKLESS_EXTENSION - | Py_TPFLAGS_HAVE_INDEX - | 0); + | Py_TPFLAGS_HAVE_INDEX); #[inline] pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_long) -> c_int { diff --git a/src/ffi2/objimpl.rs b/src/ffi2/objimpl.rs index 4986fec6..4a9b06f9 100644 --- a/src/ffi2/objimpl.rs +++ b/src/ffi2/objimpl.rs @@ -54,6 +54,7 @@ pub unsafe fn PyType_SUPPORTS_WEAKREFS(t: *mut PyTypeObject) -> c_int { } #[inline] +#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))] pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o: *mut PyObject) -> *mut *mut PyObject { let weaklistoffset = (*Py_TYPE(o)).tp_weaklistoffset as isize; (o as *mut c_char).offset(weaklistoffset) as *mut *mut PyObject diff --git a/src/typeob.rs b/src/typeob.rs index 24fee290..1af18a47 100644 --- a/src/typeob.rs +++ b/src/typeob.rs @@ -491,7 +491,7 @@ fn py_class_flags(type_object: &mut ffi::PyTypeObject) { type_object.tp_flags = ffi::Py_TPFLAGS_DEFAULT | ffi::Py_TPFLAGS_CHECKTYPES; } if !type_object.tp_as_buffer.is_null() { - type_object.tp_flags = type_object.tp_flags | ffi::Py_TPFLAGS_HAVE_NEWBUFFER; + type_object.tp_flags |= ffi::Py_TPFLAGS_HAVE_NEWBUFFER; } if T::FLAGS & PY_TYPE_FLAG_BASETYPE != 0 { type_object.tp_flags |= ffi::Py_TPFLAGS_BASETYPE; diff --git a/src/types/module.rs b/src/types/module.rs index 388cd5e7..87d4bb02 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -11,10 +11,10 @@ use crate::objectprotocol::ObjectProtocol; use crate::python::{Python, ToPyPointer}; use crate::typeob::{initialize_type, PyTypeInfo}; use crate::types::{exceptions, PyDict, PyObjectRef, PyType}; +use crate::PyObjectAlloc; use std::ffi::{CStr, CString}; use std::os::raw::c_char; use std::str; -use PyObjectAlloc; /// Represents a Python `module` object. #[repr(transparent)] diff --git a/src/types/typeobject.rs b/src/types/typeobject.rs index 81a30598..526c295b 100644 --- a/src/types/typeobject.rs +++ b/src/types/typeobject.rs @@ -35,7 +35,7 @@ impl PyType { /// Undefined behavior if the pointer is NULL or invalid. #[inline] pub unsafe fn from_type_ptr(py: Python, p: *mut ffi::PyTypeObject) -> &PyType { - py.from_borrowed_ptr::(p as *mut ffi::PyObject) + py.from_borrowed_ptr(p as *mut ffi::PyObject) } /// Gets the name of the PyType.