From 7932abf506e186d16d82bac4bf8e3f897c08a9b4 Mon Sep 17 00:00:00 2001 From: Michael Nitschinger Date: Tue, 28 Feb 2017 08:56:05 +0100 Subject: [PATCH] Fix various rustc and clippy warnings. This changeset fixes various rustc and clippy warnings. Note that it also gets rid of some type aliases which have been private and are unused in the library (and since they are private they can't be used from outside anyways). --- src/buffer.rs | 2 +- src/graph.rs | 44 ++++++++++++++++++++------------------------ src/lib.rs | 19 ++++++++++--------- src/session.rs | 7 +------ 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index ec3106783b..32853270f3 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -194,7 +194,7 @@ impl Deref for Buffer { impl DerefMut for Buffer { #[inline] - fn deref_mut<'a>(&'a mut self) -> &'a mut [T] { + fn deref_mut(&mut self) -> &mut [T] { self.as_mut() } } diff --git a/src/graph.rs b/src/graph.rs index b8a81dac25..346a362162 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -1,4 +1,3 @@ -extern crate libc; extern crate tensorflow_sys as tf; use libc::c_float; @@ -144,9 +143,9 @@ impl Graph { } /// Iterates over the operations in the graph. - pub fn operation_iter<'a>(&'a self) -> OperationIter<'a> { + pub fn operation_iter(&self) -> OperationIter { OperationIter { - graph: &self, + graph: self, pos: 0, } } @@ -492,9 +491,6 @@ impl<'a> Input<'a> { //////////////////////// -#[deprecated(note="Use Output instead.")] -type Port<'a> = Output<'a>; - /// A `Output` is one end of a graph edge. /// It holds an operation and an index into the outputs of that operation. #[derive(Debug,Copy,Clone)] @@ -756,13 +752,13 @@ impl<'a> OperationDescription<'a> { -> std::result::Result<(), NulError> { let c_attr_name = try!(CString::new(attr_name)); unsafe { - match &value.0 { - &None => tf::TF_SetAttrShape(self.inner, c_attr_name.as_ptr(), ptr::null(), -1), - &Some(ref dims) => { + match value.0 { + None => tf::TF_SetAttrShape(self.inner, c_attr_name.as_ptr(), ptr::null(), -1), + Some(ref dims) => { let c_dims: Vec = dims.iter() - .map(|x| match x { - &Some(d) => d, - &None => -1, + .map(|x| match *x { + Some(d) => d, + None => -1, }) .collect(); tf::TF_SetAttrShape(self.inner, @@ -783,28 +779,28 @@ impl<'a> OperationDescription<'a> { let c_attr_name = try!(CString::new(attr_name)); // Convert Option in each shape to i64 with None becoming -1. let c_dims: Vec>> = value.iter() - .map(|x| match &x.0 { - &None => None, - &Some(ref dims) => { + .map(|x| match x.0 { + None => None, + Some(ref dims) => { Some(dims.iter() - .map(|x| match x { - &None => -1, - &Some(d) => d, + .map(|x| match *x { + None => -1, + Some(d) => d, }) .collect()) } }) .collect(); let ptrs: Vec<*const i64> = c_dims.iter() - .map(|x| match x { - &None => ptr::null(), - &Some(ref dims) => dims.as_ptr(), + .map(|x| match *x { + None => ptr::null(), + Some(ref dims) => dims.as_ptr(), }) .collect(); let lens: Vec = value.iter() - .map(|x| match &x.0 { - &None => -1, - &Some(ref dims) => dims.len() as c_int, + .map(|x| match x.0 { + None => -1, + Some(ref dims) => dims.len() as c_int, }) .collect(); unsafe { diff --git a/src/lib.rs b/src/lib.rs index 41efb5a3ea..90ed6be623 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ //! This crate provides Rust bindings for the -//! [TensorFlow](https://www.tensorflow.org) machine learning library. +//! [`TensorFlow`](https://www.tensorflow.org) machine learning library. #![warn(missing_copy_implementations, missing_debug_implementations, @@ -343,6 +343,7 @@ c_enum!("Type of a single tensor element.", TF_DataType, DataType { /// 16-bit floating point. value Half = 19, + /// TensorFlow Resource (name, container, device,...) value Resource = 20, }); @@ -936,7 +937,7 @@ impl Deref for Tensor { impl DerefMut for Tensor { #[inline] - fn deref_mut<'a>(&'a mut self) -> &'a mut [T] { + fn deref_mut(&mut self) -> &mut [T] { &mut self.data } } @@ -1010,7 +1011,7 @@ trait OperationTrait { //////////////////////// /// Returns a string describing version information of the -/// TensorFlow library. TensorFlow using semantic versioning. +/// `TensorFlow` library. `TensorFlow` is using semantic versioning. pub fn version() -> std::result::Result { unsafe { CStr::from_ptr(tf::TF_Version()).to_str().map(|s| s.to_string()) } } @@ -1028,9 +1029,9 @@ pub struct Shape(Option>>); impl Shape { /// Returns the number of dimensions if known, or None if unknown. pub fn dims(&self) -> Option { - match self { - &Shape(None) => None, - &Shape(Some(ref v)) => Some(v.len()), + match *self { + Shape(None) => None, + Shape(Some(ref v)) => Some(v.len()), } } } @@ -1053,9 +1054,9 @@ impl Index for Shape { type Output = Option; fn index(&self, index: usize) -> &Option { - match &self.0 { - &None => &UNKNOWN_DIMENSION, - &Some(ref v) => { + match self.0 { + None => &UNKNOWN_DIMENSION, + Some(ref v) => { if index < v.len() { &v[index] } else { diff --git a/src/session.rs b/src/session.rs index 525d0e9b2b..28a343b0d6 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,5 +1,4 @@ -extern crate tensorflow_sys as tf; - +use tf; use libc::c_int; use std::marker; use std::ptr; @@ -21,9 +20,6 @@ pub struct Session { inner: *mut tf::TF_Session, } -#[deprecated(note = "Use Session instead.")] -type SessionWithGraph = Session; - impl Session { /// Creates a session. pub fn new(options: &SessionOptions, graph: &Graph) -> Result { @@ -236,7 +232,6 @@ impl<'l> Drop for StepWithGraph<'l> { #[cfg(test)] mod tests { - extern crate tensorflow_sys as tf; use super::*; use super::super::DataType; use super::super::Graph;