Skip to content

Commit 89fa9ff

Browse files
committed
Fix Clippy lints
1 parent 2659a4e commit 89fa9ff

File tree

5 files changed

+43
-45
lines changed

5 files changed

+43
-45
lines changed

src/graph.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::fmt;
2222
use std::fmt::Display;
2323
use std::fmt::Formatter;
2424
use std::mem::MaybeUninit;
25-
use std::os::raw::c_void as std_c_void;
2625
use std::ptr;
2726
use std::slice;
2827
use std::str::FromStr;
@@ -1906,7 +1905,7 @@ impl<'a> OperationDescription<'a> {
19061905
tf::TF_SetAttrString(
19071906
self.inner,
19081907
c_attr_name.as_ptr(),
1909-
c_value.as_ptr() as *const std_c_void,
1908+
c_value.as_ptr() as *const c_void,
19101909
c_value.len() as size_t,
19111910
);
19121911
}
@@ -1928,7 +1927,7 @@ impl<'a> OperationDescription<'a> {
19281927
tf::TF_SetAttrStringList(
19291928
self.inner,
19301929
c_attr_name.as_ptr(),
1931-
ptrs.as_ptr() as *const *const std_c_void,
1930+
ptrs.as_ptr(),
19321931
lens.as_ptr(),
19331932
ptrs.len() as c_int,
19341933
);
@@ -2159,7 +2158,7 @@ impl<'a> OperationDescription<'a> {
21592158
tf::TF_SetAttrTensorShapeProto(
21602159
self.inner,
21612160
c_attr_name.as_ptr(),
2162-
value.as_ptr() as *const std_c_void,
2161+
value.as_ptr() as *const c_void,
21632162
value.len() as size_t,
21642163
status.inner(),
21652164
);
@@ -2185,7 +2184,7 @@ impl<'a> OperationDescription<'a> {
21852184
tf::TF_SetAttrTensorShapeProtoList(
21862185
self.inner,
21872186
c_attr_name.as_ptr(),
2188-
ptrs.as_ptr() as *const *const std_c_void,
2187+
ptrs.as_ptr(),
21892188
lens.as_ptr(),
21902189
ptrs.len() as c_int,
21912190
status.inner(),
@@ -2238,7 +2237,7 @@ impl<'a> OperationDescription<'a> {
22382237
tf::TF_SetAttrTensorList(
22392238
self.inner,
22402239
c_attr_name.as_ptr(),
2241-
ptrs.as_ptr() as *const *mut tf::TF_Tensor,
2240+
ptrs.as_ptr(),
22422241
ptrs.len() as c_int,
22432242
status.inner(),
22442243
);
@@ -2261,7 +2260,7 @@ impl<'a> OperationDescription<'a> {
22612260
tf::TF_SetAttrValueProto(
22622261
self.inner,
22632262
c_attr_name.as_ptr(),
2264-
value.as_ptr() as *const std_c_void,
2263+
value.as_ptr() as *const c_void,
22652264
// Allow trivial_numeric_casts because usize is not
22662265
// necessarily size_t.
22672266
value.len() as size_t,
@@ -2329,7 +2328,7 @@ impl Function {
23292328
let status = Status::new();
23302329
unsafe {
23312330
let inner = tf::TF_FunctionImportFunctionDef(
2332-
proto.as_ptr() as *const std_c_void,
2331+
proto.as_ptr() as *const c_void,
23332332
proto.len(),
23342333
status.inner,
23352334
);
@@ -2349,7 +2348,7 @@ impl Function {
23492348
tf::TF_FunctionSetAttrValueProto(
23502349
self.inner,
23512350
attr_name_cstr.as_ptr(),
2352-
proto.as_ptr() as *const std_c_void,
2351+
proto.as_ptr() as *const c_void,
23532352
proto.len(),
23542353
status.inner,
23552354
);

src/lib.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -344,87 +344,86 @@ c_enum!("Error values that can be returned.", TF_Code, Code {
344344

345345
////////////////////////
346346

347-
c_enum!("Type of a single tensor element.", TF_DataType, DataType {
347+
c_enum!(
348+
TF_DataType,
349+
/// Type of a single tensor element.
350+
#[derive(Default)]
351+
DataType {
348352
/// 32-bit floating point.
349-
value Float = 1,
353+
#[default]
354+
Float = 1,
350355

351356
/// 64-bit floating point.
352-
value Double = 2,
357+
Double = 2,
353358

354359
/// 32-bit signed integer.
355-
value Int32 = 3,
360+
Int32 = 3,
356361

357362
/// 8-bit unsigned integer.
358-
value UInt8 = 4,
363+
UInt8 = 4,
359364

360365
/// 16-bit signed integer.
361-
value Int16 = 5,
366+
Int16 = 5,
362367

363368
/// 8-bit signed integer.
364-
value Int8 = 6,
369+
Int8 = 6,
365370

366371
/// String.
367-
value String = 7,
372+
String = 7,
368373

369374
/// Complex number composed of two 32-bit floats.
370-
value Complex64 = 8,
375+
Complex64 = 8,
371376

372377
/// 64-bit signed integer.
373-
value Int64 = 9,
378+
Int64 = 9,
374379

375380
/// Boolean.
376-
value Bool = 10,
381+
Bool = 10,
377382

378383
/// Quantized 8-bit signed integer.
379-
value QInt8 = 11,
384+
QInt8 = 11,
380385

381386
/// Quantized 8-bit unsigned integer.
382-
value QUInt8 = 12,
387+
QUInt8 = 12,
383388

384389
/// Quantized 32-bit signed integer.
385-
value QInt32 = 13,
390+
QInt32 = 13,
386391

387392
/// Float32 truncated to 16 bits. Only for cast ops.
388393
/// Note that this is not the same as Half. BFloat16 is not an IEEE-754
389394
/// 16-bit float. See
390395
/// <https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/bfloat16.h>
391396
/// for details.
392-
value BFloat16 = 14,
397+
BFloat16 = 14,
393398

394399
/// Quantized 16-bit signed integer.
395-
value QInt16 = 15,
400+
QInt16 = 15,
396401

397402
/// Quantized 16-bit unsigned integer.
398-
value QUInt16 = 16,
403+
QUInt16 = 16,
399404

400405
/// 16-bit unsigned integer.
401-
value UInt16 = 17,
406+
UInt16 = 17,
402407

403408
/// Complex number composed of two 64-bit floats.
404-
value Complex128 = 18,
409+
Complex128 = 18,
405410

406411
/// 16-bit floating point.
407-
value Half = 19,
412+
Half = 19,
408413

409414
/// TensorFlow Resource (name, container, device,...)
410-
value Resource = 20,
415+
Resource = 20,
411416

412417
/// A dynamic type similar to std::any::Any.
413-
value Variant = 21,
418+
Variant = 21,
414419

415420
/// 32-bit unsigned integer.
416-
value UInt32 = 22,
421+
UInt32 = 22,
417422

418423
/// 64-bit unsigned integer.
419-
value UInt64 = 23,
424+
UInt64 = 23,
420425
});
421426

422-
impl Default for DataType {
423-
fn default() -> DataType {
424-
DataType::Float
425-
}
426-
}
427-
428427
impl DataType {
429428
// We don't use Into, because we don't want this to be public API.
430429
fn into_proto(self) -> protos::types::DataType {
@@ -658,7 +657,7 @@ pub type Result<T> = std::result::Result<T, Status>;
658657
////////////////////////
659658

660659
/// A common implementation of the sealed supertrait
661-
///
660+
///
662661
/// See https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed
663662
mod private {
664663
use crate::{BFloat16, QInt16, QInt32, QInt8, QUInt16, QUInt8};
@@ -1092,7 +1091,7 @@ where
10921091
// Zero-initialize allocated memory.
10931092
let data = tf::TF_TensorData(inner);
10941093
let byte_size = tf::TF_TensorByteSize(inner);
1095-
libc::memset(data as *mut libc::c_void, 0, byte_size);
1094+
libc::memset(data, 0, byte_size);
10961095

10971096
TensorDataCRepr {
10981097
inner,

src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl Session {
164164
self.inner,
165165
run_options_ptr,
166166
step.input_ports.as_ptr(),
167-
input_tensors.as_ptr() as *const *mut tf::TF_Tensor,
167+
input_tensors.as_ptr(),
168168
input_tensors.len() as c_int,
169169
step.output_ports.as_ptr(),
170170
step.output_tensors.as_mut_ptr(),

tensorflow-op-codegen/src/bin/eager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ fn define_op<W: Write>(
437437
write!(w, "Some(f32::INFINITY)")?;
438438
} else if f == &f32::NEG_INFINITY {
439439
write!(w, "Some(f32::NEG_INFINITY)")?;
440-
} else if f == &f32::NAN {
440+
} else if f.is_nan() {
441441
write!(w, "Some(f32::NAN)")?;
442442
} else {
443443
write!(w, "Some({}f32)", f)?;

tensorflow-sys/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ fn install_prebuilt() {
245245
let framework_library_file = format!("{}{}{}", dll_prefix(), FRAMEWORK_LIBRARY, dll_suffix());
246246
let library_file = format!("{}{}{}", dll_prefix(), LIBRARY, dll_suffix());
247247

248-
let framework_library_full_path = lib_dir.join(&framework_library_file);
249-
let library_full_path = lib_dir.join(&library_file);
248+
let framework_library_full_path = lib_dir.join(framework_library_file);
249+
let library_full_path = lib_dir.join(library_file);
250250

251251
let download_required =
252252
(!windows && !framework_library_full_path.exists()) || !library_full_path.exists();

0 commit comments

Comments
 (0)