From 9f2244bbcf8b977ebf7e73ac4d2f9477d58dbc67 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 27 Jun 2015 23:49:53 +0200 Subject: [PATCH] Remove unused imports and variables. --- src/conversion.rs | 8 ++++---- src/err.rs | 8 ++++---- src/function.rs | 1 - src/lib.rs | 2 +- src/objectprotocol.rs | 6 ++---- src/objects/boolobject.rs | 2 +- src/objects/dict.rs | 1 - src/objects/iterator.rs | 2 +- src/objects/list.rs | 5 +---- src/objects/module.rs | 2 +- src/objects/num.rs | 3 +-- src/objects/object.rs | 7 ++++--- src/objects/oldstyle.rs | 2 +- src/objects/string.rs | 2 +- src/objects/tuple.rs | 1 - src/objects/typeobject.rs | 4 +--- src/pythonrun.rs | 5 ++--- src/rustobject/method.rs | 10 ++++------ src/rustobject/mod.rs | 7 +++---- src/rustobject/typebuilder.rs | 13 +++---------- 20 files changed, 35 insertions(+), 56 deletions(-) diff --git a/src/conversion.rs b/src/conversion.rs index c8c21db7..86363855 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -19,8 +19,8 @@ use std; use ffi; use python::{Python, PythonObject, PythonObjectWithCheckedDowncast, ToPythonPointer}; -use objects::{exc, PyObject, PyBool, PyTuple}; -use err::{self, PyErr, PyResult}; +use objects::PyObject; +use err::PyResult; /// Conversion trait that allows various objects to be converted into Python objects. pub trait ToPyObject<'p> { @@ -91,7 +91,7 @@ impl <'p, 's> ToPyObject<'p> for PyObject<'s> { } #[inline] - fn into_py_object(self, py: Python<'p>) -> PyObject<'p> { + fn into_py_object(self, _py: Python<'p>) -> PyObject<'p> { // Transmute the lifetime. // This is safe, because both lifetime variables represent the same lifetime: // that of the python GIL acquisition. @@ -99,7 +99,7 @@ impl <'p, 's> ToPyObject<'p> for PyObject<'s> { } #[inline] - fn with_borrowed_ptr(&self, py: Python<'p>, f: F) -> R + fn with_borrowed_ptr(&self, _py: Python<'p>, f: F) -> R where F: FnOnce(*mut ffi::PyObject) -> R { f(self.as_ptr()) } diff --git a/src/err.rs b/src/err.rs index 8b693b6c..cd6d2a11 100644 --- a/src/err.rs +++ b/src/err.rs @@ -24,7 +24,7 @@ use objects::oldstyle::PyClass; use ffi; use libc; use conversion::ToPyObject; -use std::ffi::{CString, CStr}; +use std::ffi::CString; /// Represents a Python exception that was raised. #[derive(Clone, Debug)] @@ -244,7 +244,7 @@ pub unsafe fn result_from_owned_ptr(py : Python, p : *mut ffi::PyObject) -> PyRe } } -fn panic_after_error(py: Python) -> ! { +fn panic_after_error(_py: Python) -> ! { unsafe { ffi::PyErr_Print(); } panic!("Python API called failed"); } @@ -291,8 +291,8 @@ pub fn error_on_minusone(py : Python, result : libc::c_int) -> PyResult<()> { #[cfg(test)] mod tests { use {Python, PyErr}; - use objects::{PyObject, exc}; - + use objects::exc; + #[test] fn set_typeerror() { let gil = Python::acquire_gil(); diff --git a/src/function.rs b/src/function.rs index 9af13851..f9028912 100644 --- a/src/function.rs +++ b/src/function.rs @@ -16,7 +16,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use libc::c_char; use std::ptr; use python::Python; use objects::PyObject; diff --git a/src/lib.rs b/src/lib.rs index 40f363f8..ab258056 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ #![feature(utf8_error)] // for translating Utf8Error to Python exception #![feature(plugin)] #![plugin(interpolate_idents)] -#![allow(unused_imports, unused_variables)] +#![allow(unused_imports)] // because some imports are only necessary with python 2.x or 3.x //! Rust bindings to the Python interpreter. //! diff --git a/src/objectprotocol.rs b/src/objectprotocol.rs index 926b2f44..7c33ae53 100644 --- a/src/objectprotocol.rs +++ b/src/objectprotocol.rs @@ -16,13 +16,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std; -use std::{fmt, string}; -use std::borrow::Cow; +use std::fmt; use std::cmp::Ordering; use ffi; use libc; -use python::{Python, PythonObject, PythonObjectWithCheckedDowncast, ToPythonPointer}; +use python::{PythonObject, ToPythonPointer}; use objects::{PyObject, PyTuple, PyDict, PyString}; use conversion::ToPyObject; use err::{PyErr, PyResult, result_from_owned_ptr, error_on_minusone}; diff --git a/src/objects/boolobject.rs b/src/objects/boolobject.rs index c801fecd..008064b0 100644 --- a/src/objects/boolobject.rs +++ b/src/objects/boolobject.rs @@ -33,7 +33,7 @@ impl <'p> ToPyObject<'p> for bool { } #[inline] - fn with_borrowed_ptr(&self, py: Python<'p>, f: F) -> R + fn with_borrowed_ptr(&self, _py: Python<'p>, f: F) -> R where F: FnOnce(*mut ffi::PyObject) -> R { // Avoid unnecessary Py_INCREF/Py_DECREF pair diff --git a/src/objects/dict.rs b/src/objects/dict.rs index f424b8cb..0ebd71d5 100644 --- a/src/objects/dict.rs +++ b/src/objects/dict.rs @@ -16,7 +16,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std; use ffi; use python::{Python, ToPythonPointer, PythonObject}; use conversion::ToPyObject; diff --git a/src/objects/iterator.rs b/src/objects/iterator.rs index 0b41b3eb..e725d88b 100644 --- a/src/objects/iterator.rs +++ b/src/objects/iterator.rs @@ -16,7 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use python::{PythonObject, PythonObjectWithCheckedDowncast, ToPythonPointer}; +use python::{PythonObject, ToPythonPointer}; use objects::PyObject; use err::{PyErr, PyResult}; use ffi; diff --git a/src/objects/list.rs b/src/objects/list.rs index 4cab289a..78fe2671 100644 --- a/src/objects/list.rs +++ b/src/objects/list.rs @@ -16,11 +16,9 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std; use python::{Python, PythonObject, ToPythonPointer}; -use err::{self, PyResult, PyErr}; +use err::{self, PyResult}; use super::object::PyObject; -use super::exc; use ffi::{self, Py_ssize_t}; use conversion::{ToPyObject, FromPyObject}; @@ -140,7 +138,6 @@ impl <'p, T> ToPyObject<'p> for [T] where T: ToPyObject<'p> { impl <'p, T> FromPyObject<'p> for Vec where T: FromPyObject<'p> { fn from_py_object(s: &PyObject<'p>) -> PyResult<'p, Vec> { - let py = s.python(); let list = try!(s.cast_as::()); let mut v = Vec::with_capacity(list.len()); for i in 0 .. list.len() { diff --git a/src/objects/module.rs b/src/objects/module.rs index fcf3352b..17438c13 100644 --- a/src/objects/module.rs +++ b/src/objects/module.rs @@ -22,7 +22,7 @@ use libc::c_char; use python::{Python, PythonObject, ToPythonPointer}; use objectprotocol::ObjectProtocol; use conversion::ToPyObject; -use objects::{PyObject, PyType, PyTuple, PyDict, exc}; +use objects::{PyObject, PyTuple, PyDict, exc}; use err::{self, PyResult, PyErr}; use std::ffi::{CStr, CString}; diff --git a/src/objects/num.rs b/src/objects/num.rs index 94558d58..7d2cad9d 100644 --- a/src/objects/num.rs +++ b/src/objects/num.rs @@ -19,12 +19,11 @@ extern crate num; use libc::{c_long, c_double}; -use std; use python::{Python, PythonObject, ToPythonPointer}; use err::{self, PyResult, PyErr}; use super::object::PyObject; use super::exc; -use ffi::{self, Py_ssize_t}; +use ffi; use conversion::{ToPyObject, FromPyObject}; /// Represents a Python `int` object. diff --git a/src/objects/object.rs b/src/objects/object.rs index 03fe01ba..459963ff 100644 --- a/src/objects/object.rs +++ b/src/objects/object.rs @@ -17,11 +17,10 @@ // DEALINGS IN THE SOFTWARE. use std::mem; -use libc; use ffi; use python::{Python, PythonObject, PythonObjectWithCheckedDowncast, PythonObjectWithTypeObject, PythonObjectDowncastError, ToPythonPointer}; use objects::PyType; -use err::{PyErr, PyResult}; +use err::PyErr; /// Represents a reference to a Python object. /// @@ -175,6 +174,7 @@ impl <'p> PyObject<'p> { ptr } +/* /// Transmutes an owned FFI pointer to `&PyObject`. /// Undefined behavior if the pointer is NULL or invalid. #[inline] @@ -189,7 +189,8 @@ impl <'p> PyObject<'p> { pub unsafe fn borrow_from_owned_ptr_slice<'a>(py : Python<'p>, ptr : &'a [*mut ffi::PyObject]) -> &'a [PyObject<'p>] { mem::transmute(ptr) } - +*/ + /// Gets the reference count of this Python object. #[inline] pub fn get_refcnt(&self) -> usize { diff --git a/src/objects/oldstyle.rs b/src/objects/oldstyle.rs index cb55c6de..75bb5bc6 100644 --- a/src/objects/oldstyle.rs +++ b/src/objects/oldstyle.rs @@ -19,7 +19,7 @@ //! This module contains support for old-style classes. Only available in Python 2.x. use ffi; -use python::{Python, PythonObject, ToPythonPointer}; +use python::{PythonObject, ToPythonPointer}; use conversion::ToPyObject; use err::{self, PyResult}; use super::object::PyObject; diff --git a/src/objects/string.rs b/src/objects/string.rs index f9c79bd9..b9607a2b 100644 --- a/src/objects/string.rs +++ b/src/objects/string.rs @@ -17,7 +17,7 @@ // DEALINGS IN THE SOFTWARE. use std; -use std::{char, str}; +use std::str; use std::ascii::AsciiExt; use std::borrow::Cow; use libc::c_char; diff --git a/src/objects/tuple.rs b/src/objects/tuple.rs index 2e3a4979..70b4450d 100644 --- a/src/objects/tuple.rs +++ b/src/objects/tuple.rs @@ -16,7 +16,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std; use python::{Python, PythonObject, ToPythonPointer}; use err::{self, PyResult, PyErr}; use super::object::PyObject; diff --git a/src/objects/typeobject.rs b/src/objects/typeobject.rs index e75766f6..43f2da5d 100644 --- a/src/objects/typeobject.rs +++ b/src/objects/typeobject.rs @@ -16,13 +16,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use python::{Python, PythonObject, PythonObjectWithCheckedDowncast, PythonObjectWithTypeObject, ToPythonPointer}; +use python::{Python, PythonObject, ToPythonPointer}; use conversion::ToPyObject; use objects::{PyObject, PyTuple, PyDict}; use err::{PyResult, result_from_owned_ptr}; use ffi; -use libc::c_char; -use std; /// Represents a reference to a Python type object. pub struct PyType<'p>(PyObject<'p>); diff --git a/src/pythonrun.rs b/src/pythonrun.rs index f6c6fe50..32e8f625 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -18,8 +18,7 @@ use std::sync::{Once, ONCE_INIT}; use ffi; -use python::{Python, ToPythonPointer}; -use objects::PyObject; +use python::Python; static START: Once = ONCE_INIT; @@ -162,7 +161,7 @@ impl GILProtected { /// /// Requires a `Python` instance as proof that the GIL is acquired. #[inline] - pub fn get<'a>(&'a self, py: Python<'a>) -> &'a T { + pub fn get<'a>(&'a self, _py: Python<'a>) -> &'a T { &self.data } diff --git a/src/rustobject/method.rs b/src/rustobject/method.rs index 4a535f6c..9dcf4eff 100644 --- a/src/rustobject/method.rs +++ b/src/rustobject/method.rs @@ -16,11 +16,9 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std::{ptr, marker}; -use python::{Python, PythonObject}; +use std::marker; +use python::PythonObject; use objects::{PyObject, PyTuple, PyType}; -use conversion::ToPyObject; -use super::{PythonBaseObject, PyRustObject, PyRustType}; use super::typebuilder::TypeMember; use ffi; use err; @@ -110,7 +108,7 @@ pub unsafe fn py_method_impl<'p, T, R>( impl <'p, T> TypeMember<'p, T> for MethodDescriptor where T: PythonObject<'p> { #[inline] - fn into_descriptor(self, ty: &PyType<'p>, name: &str) -> PyObject<'p> { + fn into_descriptor(self, ty: &PyType<'p>, _name: &str) -> PyObject<'p> { unsafe { err::from_owned_ptr_or_panic(ty.python(), ffi::PyDescr_NewMethod(ty.as_type_ptr(), self.0)) @@ -200,7 +198,7 @@ pub unsafe fn py_class_method_impl<'p, R>( impl <'p, T> TypeMember<'p, T> for ClassMethodDescriptor where T: PythonObject<'p> { #[inline] - fn into_descriptor(self, ty: &PyType<'p>, name: &str) -> PyObject<'p> { + fn into_descriptor(self, ty: &PyType<'p>, _name: &str) -> PyObject<'p> { unsafe { err::from_owned_ptr_or_panic(ty.python(), ffi::PyDescr_NewClassMethod(ty.as_type_ptr(), self.0)) diff --git a/src/rustobject/mod.rs b/src/rustobject/mod.rs index 710c8846..44e554ca 100644 --- a/src/rustobject/mod.rs +++ b/src/rustobject/mod.rs @@ -20,7 +20,7 @@ use libc; use ffi; use python::{Python, ToPythonPointer, PythonObject}; use conversion::ToPyObject; -use objects::{PyObject, PyType, PyString, PyModule, PyDict}; +use objects::{PyObject, PyType}; use std::{mem, ops, ptr, marker}; use err::{self, PyResult}; @@ -56,7 +56,7 @@ impl <'p> PythonBaseObject<'p> for PyObject<'p> { type InitType = (); - unsafe fn alloc(ty: &PyType<'p>, init_val: ()) -> PyResult<'p, PyObject<'p>> { + unsafe fn alloc(ty: &PyType<'p>, _init_val: ()) -> PyResult<'p, PyObject<'p>> { let py = ty.python(); let ptr = ((*ty.as_type_ptr()).tp_alloc.unwrap())(ty.as_type_ptr(), 0); err::result_from_owned_ptr(py, ptr) @@ -156,7 +156,7 @@ impl <'p, 's, T, B> ToPyObject<'p> for PyRustObject<'s, T, B> where T: 'static + } #[inline] - fn with_borrowed_ptr(&self, py: Python<'p>, f: F) -> R + fn with_borrowed_ptr(&self, _py: Python<'p>, f: F) -> R where F: FnOnce(*mut ffi::PyObject) -> R { f(self.as_ptr()) } @@ -203,7 +203,6 @@ pub struct PyRustType<'p, T, B = PyObject<'p>> where T: 'p + Send, B: PythonBase impl <'p, T, B> PyRustType<'p, T, B> where T: 'p + Send, B: PythonBaseObject<'p> { /// Creates a PyRustObject instance from a value. pub fn create_instance(&self, val: T, base_val: B::InitType) -> PyRustObject<'p, T, B> { - let py = self.type_obj.python(); unsafe { PythonBaseObject::alloc(&self.type_obj, (val, base_val)).unwrap() } diff --git a/src/rustobject/typebuilder.rs b/src/rustobject/typebuilder.rs index db661f88..34a9c572 100644 --- a/src/rustobject/typebuilder.rs +++ b/src/rustobject/typebuilder.rs @@ -16,12 +16,12 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use std::{ptr, marker}; use libc; use ffi; use python::{Python, ToPythonPointer, PythonObject}; use conversion::ToPyObject; use objects::{PyObject, PyType, PyString, PyModule, PyDict}; -use std::{mem, ops, ptr, marker}; use err::{self, PyResult}; use super::{PythonBaseObject, PyRustObject, PyRustType}; @@ -44,7 +44,7 @@ pub fn new_typebuilder_for_module<'p, T>(m: &PyModule<'p>, name: &str) -> PyRust } unsafe extern "C" fn disabled_tp_new_callback - (subtype: *mut ffi::PyTypeObject, args: *mut ffi::PyObject, kwds: *mut ffi::PyObject) + (_subtype: *mut ffi::PyTypeObject, _args: *mut ffi::PyObject, _kwds: *mut ffi::PyObject) -> *mut ffi::PyObject { ffi::PyErr_SetString(ffi::PyExc_TypeError, b"Cannot initialize rust object from python.\0" as *const u8 as *const libc::c_char); @@ -173,15 +173,8 @@ pub trait TypeMember<'p, T> where T: PythonObject<'p> { // TODO: does this cause trouble for coherence? impl <'p, T, S> TypeMember<'p, T> for S where T: PythonObject<'p>, S: ToPyObject<'p> { #[inline] - fn into_descriptor(self, ty: &PyType<'p>, name: &str) -> PyObject<'p> { + fn into_descriptor(self, ty: &PyType<'p>, _name: &str) -> PyObject<'p> { self.into_py_object(ty.python()).into_object() } } -impl <'p, T> TypeMember<'p, T> for fn(&T) where T: PythonObject<'p> { - fn into_descriptor(self, ty: &PyType<'p>, name: &str) -> PyObject<'p> { - unimplemented!() - } -} - -