Skip to content

Commit 93c576a

Browse files
committed
Fixed compiler and clippy warnings
1 parent 659532a commit 93c576a

File tree

10 files changed

+41
-48
lines changed

10 files changed

+41
-48
lines changed

onnxruntime-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn extract_zip(filename: &Path, outpath: &Path) {
178178
let mut file = archive.by_index(i).unwrap();
179179
#[allow(deprecated)]
180180
let outpath = outpath.join(file.sanitized_name());
181-
if !(&*file.name()).ends_with('/') {
181+
if !(file.name()).ends_with('/') {
182182
println!(
183183
"File {} extracted to \"{}\" ({} bytes)",
184184
i,

onnxruntime-sys/examples/c_api_sample.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,16 @@ fn main() {
278278

279279
// score model & input tensor, get back output tensor
280280

281-
let input_node_names_cstring: Vec<std::ffi::CString> = input_node_names
281+
let input_node_names_ptr: Vec<*const i8> = input_node_names
282282
.into_iter()
283283
.map(|n| std::ffi::CString::new(n).unwrap())
284-
.collect();
285-
let input_node_names_ptr: Vec<*const i8> = input_node_names_cstring
286-
.into_iter()
287284
.map(|n| n.into_raw() as *const i8)
288285
.collect();
289286
let input_node_names_ptr_ptr: *const *const i8 = input_node_names_ptr.as_ptr();
290287

291288
let output_node_names_cstring: Vec<std::ffi::CString> = output_node_names
292-
.into_iter()
293-
.map(|n| std::ffi::CString::new(n.clone()).unwrap())
289+
.iter()
290+
.map(|n| std::ffi::CString::new(n.to_owned()).unwrap())
294291
.collect();
295292
let output_node_names_ptr: Vec<*const i8> = output_node_names_cstring
296293
.iter()
@@ -341,8 +338,8 @@ fn main() {
341338
// NOTE: The C ONNX Runtime allocated the array, we shouldn't drop the vec
342339
// but let C de-allocate instead.
343340
let floatarr_vec: Vec<f32> = unsafe { Vec::from_raw_parts(floatarr, 5, 5) };
344-
for i in 0..5 {
345-
println!("Score for class [{}] = {}", i, floatarr_vec[i]);
341+
for (i, class) in floatarr_vec.iter().enumerate() {
342+
println!("Score for class [{}] = {}", i, class);
346343
}
347344
std::mem::forget(floatarr_vec);
348345

@@ -363,7 +360,7 @@ fn main() {
363360
}
364361

365362
fn CheckStatus(g_ort: *const OrtApi, status: *const OrtStatus) -> Result<(), String> {
366-
if status != std::ptr::null() {
363+
if status.is_null() {
367364
let raw = unsafe { g_ort.as_ref().unwrap().GetErrorMessage.unwrap()(status) };
368365
Err(char_p_to_str(raw).unwrap().to_string())
369366
} else {

onnxruntime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ureq = { version = "2.1", optional = true }
3131

3232
[dev-dependencies]
3333
image = "0.23"
34-
test-env-log = { version = "0.2", default-features = false, features = ["trace"] }
34+
test-log = { version = "0.2", default-features = false, features = ["trace"] }
3535
tracing-subscriber = "0.2"
3636
ureq = "2.1"
3737

onnxruntime/examples/print_structure.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::error::Error;
55
fn main() -> Result<(), Box<dyn Error>> {
66
// provide path to .onnx model on disk
77
let path = std::env::args()
8-
.skip(1)
9-
.next()
8+
.nth(1)
109
.expect("Must provide an .onnx file as the first arg");
1110

1211
let environment = environment::Environment::builder()

onnxruntime/src/environment.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl EnvBuilder {
243243
mod tests {
244244
use super::*;
245245
use std::sync::{RwLock, RwLockWriteGuard};
246-
use test_env_log::test;
246+
use test_log::test;
247247

248248
impl G_ENV {
249249
fn is_initialized(&self) -> bool {
@@ -328,28 +328,25 @@ mod tests {
328328
let main_env = Environment::new(initial_name.clone(), LoggingLevel::Warning).unwrap();
329329
let main_env_ptr = main_env.env_ptr() as usize;
330330

331-
let children: Vec<_> = (0..10)
332-
.map(|t| {
333-
let initial_name_cloned = initial_name.clone();
334-
std::thread::spawn(move || {
335-
let name = format!("concurrent_environment_creation: {}", t);
336-
let env = Environment::builder()
337-
.with_name(name)
338-
.with_log_level(LoggingLevel::Warning)
339-
.build()
340-
.unwrap();
341-
342-
assert_eq!(env.name(), initial_name_cloned);
343-
assert_eq!(env.env_ptr() as usize, main_env_ptr);
344-
})
331+
let children = (0..10).map(|t| {
332+
let initial_name_cloned = initial_name.clone();
333+
std::thread::spawn(move || {
334+
let name = format!("concurrent_environment_creation: {}", t);
335+
let env = Environment::builder()
336+
.with_name(name)
337+
.with_log_level(LoggingLevel::Warning)
338+
.build()
339+
.unwrap();
340+
341+
assert_eq!(env.name(), initial_name_cloned);
342+
assert_eq!(env.env_ptr() as usize, main_env_ptr);
345343
})
346-
.collect();
344+
});
347345

348346
assert_eq!(main_env.name(), initial_name);
349347
assert_eq!(main_env.env_ptr() as usize, main_env_ptr);
350348

351-
let res: Vec<std::thread::Result<_>> =
352-
children.into_iter().map(|child| child.join()).collect();
353-
assert!(res.into_iter().all(|r| std::result::Result::is_ok(&r)));
349+
let mut res = children.map(|child| child.join());
350+
assert!(res.all(|r| std::result::Result::is_ok(&r)));
354351
}
355352
}

onnxruntime/src/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Drop for MemoryInfo {
5252
#[cfg(test)]
5353
mod tests {
5454
use super::*;
55-
use test_env_log::test;
55+
use test_log::test;
5656

5757
#[test]
5858
fn memory_info_constructor_destructor() {

onnxruntime/src/session.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Module containing session types
22
3-
use std::{ffi::CString, fmt::Debug, path::Path};
3+
use std::{ffi::CString, fmt::Debug, marker::PhantomData, path::Path};
44

55
#[cfg(not(target_family = "windows"))]
66
use std::os::unix::ffi::OsStrExt;
@@ -227,7 +227,7 @@ impl<'a> SessionBuilder<'a> {
227227
.collect::<Result<Vec<Output>>>()?;
228228

229229
Ok(Session {
230-
env: self.env,
230+
env: PhantomData,
231231
session_ptr,
232232
allocator_ptr,
233233
memory_info,
@@ -283,7 +283,7 @@ impl<'a> SessionBuilder<'a> {
283283
.collect::<Result<Vec<Output>>>()?;
284284

285285
Ok(Session {
286-
env: self.env,
286+
env: PhantomData,
287287
session_ptr,
288288
allocator_ptr,
289289
memory_info,
@@ -296,7 +296,7 @@ impl<'a> SessionBuilder<'a> {
296296
/// Type storing the session information, built from an [`Environment`](environment/struct.Environment.html)
297297
#[derive(Debug)]
298298
pub struct Session<'a> {
299-
env: &'a Environment,
299+
env: PhantomData<&'a Environment>,
300300
session_ptr: *mut sys::OrtSession,
301301
allocator_ptr: *mut sys::OrtAllocator,
302302
memory_info: MemoryInfo,

onnxruntime/src/tensor/ndarray_tensor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ where
5757
mod tests {
5858
use super::*;
5959
use ndarray::{arr1, arr2, arr3};
60-
use test_env_log::test;
60+
use test_log::test;
6161

6262
#[test]
6363
fn softmax_1d() {

onnxruntime/src/tensor/ort_owned_tensor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Module containing tensor with memory owned by the ONNX Runtime
22
3-
use std::{fmt::Debug, ops::Deref};
3+
use std::{fmt::Debug, marker::PhantomData, ops::Deref};
44

55
use ndarray::{Array, ArrayView};
66
use tracing::debug;
@@ -31,7 +31,7 @@ where
3131
{
3232
pub(crate) tensor_ptr: *mut sys::OrtValue,
3333
array_view: ArrayView<'t, T, D>,
34-
memory_info: &'m MemoryInfo,
34+
memory_info: PhantomData<&'m MemoryInfo>,
3535
}
3636

3737
impl<'t, 'm, T, D> Deref for OrtOwnedTensor<'t, 'm, T, D>
@@ -67,18 +67,18 @@ where
6767
D: ndarray::Dimension,
6868
{
6969
pub(crate) tensor_ptr: *mut sys::OrtValue,
70-
memory_info: &'m MemoryInfo,
70+
memory_info: PhantomData<&'m MemoryInfo>,
7171
shape: D,
7272
}
7373

7474
impl<'m, D> OrtOwnedTensorExtractor<'m, D>
7575
where
7676
D: ndarray::Dimension,
7777
{
78-
pub(crate) fn new(memory_info: &'m MemoryInfo, shape: D) -> OrtOwnedTensorExtractor<'m, D> {
78+
pub(crate) fn new(_memory_info: &'m MemoryInfo, shape: D) -> OrtOwnedTensorExtractor<'m, D> {
7979
OrtOwnedTensorExtractor {
8080
tensor_ptr: std::ptr::null_mut(),
81-
memory_info,
81+
memory_info: PhantomData,
8282
shape,
8383
}
8484
}
@@ -115,7 +115,7 @@ where
115115
Ok(OrtOwnedTensor {
116116
tensor_ptr: self.tensor_ptr,
117117
array_view,
118-
memory_info: self.memory_info,
118+
memory_info: PhantomData,
119119
})
120120
}
121121
}

onnxruntime/src/tensor/ort_tensor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Module containing tensor with memory owned by Rust
22
3-
use std::{ffi, fmt::Debug, ops::Deref};
3+
use std::{ffi, fmt::Debug, marker::PhantomData, ops::Deref};
44

55
use ndarray::Array;
66
use tracing::{debug, error};
@@ -30,7 +30,7 @@ where
3030
{
3131
pub(crate) c_ptr: *mut sys::OrtValue,
3232
array: Array<T, D>,
33-
memory_info: &'t MemoryInfo,
33+
memory_info: PhantomData<&'t MemoryInfo>,
3434
}
3535

3636
impl<'t, T, D> OrtTensor<'t, T, D>
@@ -141,7 +141,7 @@ where
141141
Ok(OrtTensor {
142142
c_ptr: tensor_ptr,
143143
array,
144-
memory_info,
144+
memory_info: PhantomData,
145145
})
146146
}
147147
}
@@ -198,7 +198,7 @@ mod tests {
198198
use crate::{AllocatorType, MemType};
199199
use ndarray::{arr0, arr1, arr2, arr3};
200200
use std::ptr;
201-
use test_env_log::test;
201+
use test_log::test;
202202

203203
#[test]
204204
fn orttensor_from_array_0d_i32() {

0 commit comments

Comments
 (0)