Repository: arrayfire/arrayfire-rust (language: rust)

Issue:
[BUG] Fix Clippy warnings



Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index 1b0b6edb8..39a9fa998 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,6 @@ Cargo.lock
 # ide files
 .idea/
 .vscode/
+
+#example downloads
+data/
diff --git a/build.rs b/build.rs
index 360fbb62f..5b55757aa 100644
--- a/build.rs
+++ b/build.rs
@@ -12,6 +12,7 @@ use std::env;
 use std::fs;
 use std::fs::OpenOptions;
 use std::io::{ErrorKind, Read};
+use std::path::Path;
 use std::path::PathBuf;
 use std::process::Command;
 
@@ -95,7 +96,7 @@ fn run(cmd: &mut Command, program: &str) {
     }
 }
 
-fn read_file(file_name: &std::path::PathBuf) -> String {
+fn read_file(file_name: &std::path::Path) -> String {
     let file_path = file_name.to_str().unwrap();
     let options = OpenOptions::new()
         .read(true)
@@ -115,7 +116,7 @@ fn read_file(file_name: &std::path::PathBuf) -> String {
     }
 }
 
-fn read_conf(conf_file: &std::path::PathBuf) -> Config {
+fn read_conf(conf_file: &std::path::Path) -> Config {
     let raw_conf = read_file(conf_file);
     let decoded: Config = serde_json::from_str(&raw_conf).unwrap();
     decoded
@@ -198,7 +199,7 @@ fn prep_cmake_options(conf: &Config) -> Vec<String> {
 }
 
 #[cfg(windows)]
-fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
+fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) {
     let _ = fs::create_dir(&build_dir);
 
     let options = prep_cmake_options(conf);
@@ -243,7 +244,7 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
 }
 
 #[cfg(not(windows))]
-fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
+fn run_cmake_command(conf: &Config, build_dir: &std::path::Path) {
     let _ = fs::create_dir(&build_dir);
 
     let options = prep_cmake_options(conf);
@@ -282,7 +283,7 @@ fn backend_exists(name: &str) -> bool {
     file_exists(&win_backend) || file_exists(&osx_backend) || file_exists(&linux_backend)
 }
 
-fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>, Vec<String>) {
+fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec<String>, Vec<String>) {
     let mut backend_dirs: Vec<String> = Vec::new();
     let mut backends: Vec<String> = Vec::new();
 
@@ -338,7 +339,7 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
     let mut ocl_lib_exists = false;
 
     for backend_dir in backend_dirs.iter() {
-        let lib_dir = PathBuf::from(backend_dir);
+        let lib_dir = Path::new(backend_dir);
 
         let culib_name = if cfg!(windows) {
             WIN_CUDA_LIB
@@ -429,7 +430,14 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
 
 fn main() {
     // Setup pathing
-    let src = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
+    let cargo_manifest_dir = match env::var("CARGO_MANIFEST_DIR") {
+        Ok(dir_path) => dir_path,
+        Err(error) => panic!(
+            "CARGO_MANIFEST_DIR environment variable is not available: {}",
+            error
+        ),
+    };
+    let src = Path::new(&cargo_manifest_dir);
     let conf_file = src.join("build.conf");
     let conf = read_conf(&conf_file);
 
diff --git a/examples/helloworld.rs b/examples/helloworld.rs
index 2b9c2e4cd..5e455425d 100644
--- a/examples/helloworld.rs
+++ b/examples/helloworld.rs
@@ -81,7 +81,7 @@ fn main() {
     //print(&x.0);
     //print(&x.1);
 
-    let u8_cnst = &constant(1 as u8, dims);
+    let u8_cnst = &constant(1_u8, dims);
     af_print!("u8 constant array", u8_cnst);
     println!(
         "Is u8_cnst array float precision type ? {}",
diff --git a/examples/neural_network.rs b/examples/neural_network.rs
index e7a49cdff..4fcb92a86 100644
--- a/examples/neural_network.rs
+++ b/examples/neural_network.rs
@@ -241,7 +241,7 @@ mod ann {
                     println!("Epoch: {}, Error: {}", epoch + 1, avg_error);
                 }
             }
-            return avg_error;
+            avg_error
         }
 
         fn predict(&self, input: &Array<f32>) -> Array<f32> {
@@ -312,7 +312,7 @@ mod ann {
                     MatProp::NONE,
                 );
 
-                error = index(&err, &[seq!(), seq!(1, output.dims()[1] as i32, 1)]);
+                error = index(err, &[seq!(), seq!(1, output.dims()[1] as i32, 1)]);
             }
         }
 
@@ -333,7 +333,7 @@ fn accuracy(predicted: &Array<f32>, target: &Array<f32>) -> f32 {
         &predicted_max_indices,
         false,
     ));
-    return 100f32 * matches as f32 / target_max_indices.elements() as f32;
+    100f32 * matches as f32 / target_max_indices.elements() as f32
 }
 
 fn main() {
diff --git a/src/core/arith.rs b/src/core/arith.rs
index a0e7e7322..3c7fcbd7f 100644
--- a/src/core/arith.rs
+++ b/src/core/arith.rs
@@ -668,18 +668,18 @@ where
     match (lo.is_scalar(), hi.is_scalar()) {
         (true, false) => {
             let l = tile(&lo, hi.dims());
-            clamp_helper(&input, &l, &hi, batch)
+            clamp_helper(input, &l, &hi, batch)
         }
         (false, true) => {
             let r = tile(&hi, lo.dims());
-            clamp_helper(&input, &lo, &r, batch)
+            clamp_helper(input, &lo, &r, batch)
         }
         (true, true) => {
             let l = tile(&lo, input.dims());
             let r = tile(&hi, input.dims());
-            clamp_helper(&input, &l, &r, batch)
+            clamp_helper(input, &l, &r, batch)
         }
-        _ => clamp_helper(&input, &lo, &hi, batch),
+        _ => clamp_helper(input, &lo, &hi, batch),
     }
 }
 
diff --git a/src/core/array.rs b/src/core/array.rs
index bae191d25..fdf262bec 100644
--- a/src/core/array.rs
+++ b/src/core/array.rs
@@ -682,6 +682,7 @@ where
     }
 
     /// Fetch Array as String
+    #[allow(clippy::inherent_to_string)]
     pub fn to_string(&self) -> String {
         let result: String;
         unsafe {
@@ -704,6 +705,7 @@ where
 
 /// Used for creating Array object from native
 /// resource id, an 64 bit integer
+#[allow(clippy::from_over_into)]
 impl<T: HasAfEnum> Into<Array<T>> for af_array {
     fn into(self) -> Array<T> {
         Array {
diff --git a/src/core/index.rs b/src/core/index.rs
index 17ec7b4aa..d87f0c1af 100644
--- a/src/core/index.rs
+++ b/src/core/index.rs
@@ -725,7 +725,7 @@ mod tests {
     fn non_macro_seq_assign() {
         set_device(0);
         // ANCHOR: non_macro_seq_assign
-        let mut a = constant(2.0 as f32, dim4!(5, 3));
+        let mut a = constant(2.0_f32, dim4!(5, 3));
         //print(&a);
         // 2.0 2.0 2.0
         // 2.0 2.0 2.0
@@ -733,7 +733,7 @@ mod tests {
         // 2.0 2.0 2.0
         // 2.0 2.0 2.0
 
-        let b = constant(1.0 as f32, dim4!(3, 3));
+        let b = constant(1.0_f32, dim4!(3, 3));
         let seqs = [seq!(1:3:1), seq!()];
         assign_seq(&mut a, &seqs, &b);
         //print(&a);
@@ -800,7 +800,7 @@ mod tests {
         //     0.4587     0.6793     0.0346
         //     0.5328     0.9347     0.0535
 
-        let b = constant(2.0 as f32, dim4!(3, 3, 1, 1));
+        let b = constant(2.0_f32, dim4!(3, 3, 1, 1));
 
         let mut idxrs = Indexer::default();
         idxrs.set_index(&indices, 0, None); // 2nd arg is indexing dimension
diff --git a/src/core/macros.rs b/src/core/macros.rs
index 4abba9ee7..366f0cc80 100644
--- a/src/core/macros.rs
+++ b/src/core/macros.rs
@@ -482,7 +482,7 @@ mod tests {
         let seq4gen = seq!(0:2:1);
         let mut a = randu::<f32>(dim4!(5, 3));
 
-        let b = constant(2.0 as f32, dim4!(3, 3));
+        let b = constant(2.0_f32, dim4!(3, 3));
 
         eval!(a[indices, seq4gen] = b);
         // ANCHOR_END: macro_seq_array_assign


Test patch:
diff --git a/tests/error_handler.rs b/tests/error_handler.rs
index b0b740a4b..7b1bcb12d 100644
--- a/tests/error_handler.rs
+++ b/tests/error_handler.rs
@@ -24,7 +24,7 @@ fn check_error_handler_mutation() {
     let children = (0..4)
         .map(|i| {
             thread::Builder::new()
-                .name(format!("child {}", i + 1).to_string())
+                .name(format!("child {}", i + 1))
                 .spawn(move || {
                     let target_device = i % arrayfire::device_count();
                     println!(