Skip to content

Commit 85d3f86

Browse files
committed
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).
1 parent 7f1ee07 commit 85d3f86

File tree

4 files changed

+32
-43
lines changed

4 files changed

+32
-43
lines changed

src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<T: TensorType> Deref for Buffer<T> {
194194

195195
impl<T: TensorType> DerefMut for Buffer<T> {
196196
#[inline]
197-
fn deref_mut<'a>(&'a mut self) -> &'a mut [T] {
197+
fn deref_mut(&mut self) -> &mut [T] {
198198
self.as_mut()
199199
}
200200
}

src/graph.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate libc;
21
extern crate tensorflow_sys as tf;
32

43
use libc::c_float;
@@ -144,9 +143,9 @@ impl Graph {
144143
}
145144

146145
/// Iterates over the operations in the graph.
147-
pub fn operation_iter<'a>(&'a self) -> OperationIter<'a> {
146+
pub fn operation_iter(&self) -> OperationIter {
148147
OperationIter {
149-
graph: &self,
148+
graph: self,
150149
pos: 0,
151150
}
152151
}
@@ -489,9 +488,6 @@ impl<'a> Input<'a> {
489488

490489
////////////////////////
491490

492-
#[deprecated(note="Use Output instead.")]
493-
type Port<'a> = Output<'a>;
494-
495491
/// A `Output` is one end of a graph edge.
496492
/// It holds an operation and an index into the outputs of that operation.
497493
#[derive(Debug,Copy,Clone)]
@@ -753,13 +749,13 @@ impl<'a> OperationDescription<'a> {
753749
-> std::result::Result<(), NulError> {
754750
let c_attr_name = try!(CString::new(attr_name));
755751
unsafe {
756-
match &value.0 {
757-
&None => tf::TF_SetAttrShape(self.inner, c_attr_name.as_ptr(), ptr::null(), -1),
758-
&Some(ref dims) => {
752+
match value.0 {
753+
None => tf::TF_SetAttrShape(self.inner, c_attr_name.as_ptr(), ptr::null(), -1),
754+
Some(ref dims) => {
759755
let c_dims: Vec<i64> = dims.iter()
760-
.map(|x| match x {
761-
&Some(d) => d,
762-
&None => -1,
756+
.map(|x| match *x {
757+
Some(d) => d,
758+
None => -1,
763759
})
764760
.collect();
765761
tf::TF_SetAttrShape(self.inner,
@@ -780,28 +776,28 @@ impl<'a> OperationDescription<'a> {
780776
let c_attr_name = try!(CString::new(attr_name));
781777
// Convert Option<i64> in each shape to i64 with None becoming -1.
782778
let c_dims: Vec<Option<Vec<i64>>> = value.iter()
783-
.map(|x| match &x.0 {
784-
&None => None,
785-
&Some(ref dims) => {
779+
.map(|x| match x.0 {
780+
None => None,
781+
Some(ref dims) => {
786782
Some(dims.iter()
787-
.map(|x| match x {
788-
&None => -1,
789-
&Some(d) => d,
783+
.map(|x| match *x {
784+
None => -1,
785+
Some(d) => d,
790786
})
791787
.collect())
792788
}
793789
})
794790
.collect();
795791
let ptrs: Vec<*const i64> = c_dims.iter()
796-
.map(|x| match x {
797-
&None => ptr::null(),
798-
&Some(ref dims) => dims.as_ptr(),
792+
.map(|x| match *x {
793+
None => ptr::null(),
794+
Some(ref dims) => dims.as_ptr(),
799795
})
800796
.collect();
801797
let lens: Vec<c_int> = value.iter()
802-
.map(|x| match &x.0 {
803-
&None => -1,
804-
&Some(ref dims) => dims.len() as c_int,
798+
.map(|x| match x.0 {
799+
None => -1,
800+
Some(ref dims) => dims.len() as c_int,
805801
})
806802
.collect();
807803
unsafe {

src/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! This crate provides Rust bindings for the
2-
//! [TensorFlow](https://www.tensorflow.org) machine learning library.
2+
//! [`TensorFlow`](https://www.tensorflow.org) machine learning library.
33
44
#![warn(missing_copy_implementations,
55
missing_debug_implementations,
@@ -343,6 +343,7 @@ c_enum!("Type of a single tensor element.", TF_DataType, DataType {
343343
/// 16-bit floating point.
344344
value Half = 19,
345345

346+
/// Tensorflow Resource (name, container, device,...)
346347
value Resource = 20,
347348
});
348349

@@ -929,7 +930,7 @@ impl<T: TensorType> Deref for Tensor<T> {
929930

930931
impl<T: TensorType> DerefMut for Tensor<T> {
931932
#[inline]
932-
fn deref_mut<'a>(&'a mut self) -> &'a mut [T] {
933+
fn deref_mut(&mut self) -> &mut [T] {
933934
&mut self.data
934935
}
935936
}
@@ -1003,16 +1004,13 @@ trait OperationTrait {
10031004
////////////////////////
10041005

10051006
/// Returns a string describing version information of the
1006-
/// TensorFlow library. TensorFlow using semantic versioning.
1007+
/// `TensorFlow` library. `TensorFlow` is using semantic versioning.
10071008
pub fn version() -> std::result::Result<String, Utf8Error> {
10081009
unsafe { CStr::from_ptr(tf::TF_Version()).to_str().map(|s| s.to_string()) }
10091010
}
10101011

10111012
////////////////////////
10121013

1013-
#[deprecated(note="Use Shape instead.")]
1014-
type TensorShape = Shape;
1015-
10161014
/// A Shape is the shape of a tensor. A Shape may be an unknown rank, or it may
10171015
/// have a known rank with each dimension being known or unknown.
10181016
#[derive(Debug,Eq,Ord,PartialEq,PartialOrd,Hash,Clone)]
@@ -1021,9 +1019,9 @@ pub struct Shape(Option<Vec<Option<i64>>>);
10211019
impl Shape {
10221020
/// Returns the number of dimensions if known, or None if unknown.
10231021
pub fn dims(&self) -> Option<usize> {
1024-
match self {
1025-
&Shape(None) => None,
1026-
&Shape(Some(ref v)) => Some(v.len()),
1022+
match *self {
1023+
Shape(None) => None,
1024+
Shape(Some(ref v)) => Some(v.len()),
10271025
}
10281026
}
10291027
}
@@ -1046,9 +1044,9 @@ impl Index<usize> for Shape {
10461044
type Output = Option<i64>;
10471045

10481046
fn index(&self, index: usize) -> &Option<i64> {
1049-
match &self.0 {
1050-
&None => &UNKNOWN_DIMENSION,
1051-
&Some(ref v) => {
1047+
match self.0 {
1048+
None => &UNKNOWN_DIMENSION,
1049+
Some(ref v) => {
10521050
if index < v.len() {
10531051
&v[index]
10541052
} else {

src/session.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
extern crate tensorflow_sys as tf;
2-
1+
use tf;
32
use libc::c_int;
43
use std::marker;
54
use std::ptr;
@@ -21,9 +20,6 @@ pub struct Session {
2120
inner: *mut tf::TF_Session,
2221
}
2322

24-
#[deprecated(note = "Use Session instead.")]
25-
type SessionWithGraph = Session;
26-
2723
impl Session {
2824
/// Creates a session.
2925
pub fn new(options: &SessionOptions, graph: &Graph) -> Result<Self> {
@@ -236,7 +232,6 @@ impl<'l> Drop for StepWithGraph<'l> {
236232

237233
#[cfg(test)]
238234
mod tests {
239-
extern crate tensorflow_sys as tf;
240235
use super::*;
241236
use super::super::DataType;
242237
use super::super::Graph;

0 commit comments

Comments
 (0)