You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ne...@apache.org on 2020/11/28 20:29:53 UTC

[arrow] branch master updated: ARROW-10741: [Rust] Apply previously ignored clippy suggestions

This is an automated email from the ASF dual-hosted git repository.

nevime pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d9fbeb  ARROW-10741: [Rust] Apply previously ignored clippy suggestions
1d9fbeb is described below

commit 1d9fbeb3e62d034f74e239f07fc16040d3f81c91
Author: Heres, Daniel <da...@gmail.com>
AuthorDate: Sat Nov 28 22:29:01 2020 +0200

    ARROW-10741: [Rust] Apply previously ignored clippy suggestions
    
    Just remove some from the ignore list and apply them.
    
    Closes #8772 from Dandandan/clippy_arrow
    
    Authored-by: Heres, Daniel <da...@gmail.com>
    Signed-off-by: Neville Dipale <ne...@gmail.com>
---
 rust/arrow/src/array/array_primitive.rs  |  8 ++++----
 rust/arrow/src/array/equal_json.rs       |  8 ++++----
 rust/arrow/src/array/iterator.rs         |  4 ++--
 rust/arrow/src/array/transform/mod.rs    |  2 +-
 rust/arrow/src/compute/kernels/filter.rs | 13 +++----------
 rust/arrow/src/json/reader.rs            |  4 ++--
 rust/arrow/src/lib.rs                    | 10 +---------
 7 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/rust/arrow/src/array/array_primitive.rs b/rust/arrow/src/array/array_primitive.rs
index d1014db..c6f20b1 100644
--- a/rust/arrow/src/array/array_primitive.rs
+++ b/rust/arrow/src/array/array_primitive.rs
@@ -589,12 +589,12 @@ mod tests {
         assert_eq!(0, arr.offset());
         assert_eq!(0, arr.null_count());
         let formatted = vec!["00:00:00.001", "10:30:00.005", "23:59:59.210"];
-        for i in 0..3 {
+        for (i, formatted) in formatted.iter().enumerate().take(3) {
             // check that we can't create dates or datetimes from time instances
             assert_eq!(None, arr.value_as_datetime(i));
             assert_eq!(None, arr.value_as_date(i));
             let time = arr.value_as_time(i).unwrap();
-            assert_eq!(formatted[i], time.format("%H:%M:%S%.3f").to_string());
+            assert_eq!(*formatted, time.format("%H:%M:%S%.3f").to_string());
         }
     }
 
@@ -613,12 +613,12 @@ mod tests {
         assert_eq!(0, arr.offset());
         assert_eq!(0, arr.null_count());
         let formatted = vec!["00:00:00.001", "10:30:00.005", "23:59:59.210"];
-        for i in 0..3 {
+        for (i, item) in formatted.iter().enumerate().take(3) {
             // check that we can't create dates or datetimes from time instances
             assert_eq!(None, arr.value_as_datetime(i));
             assert_eq!(None, arr.value_as_date(i));
             let time = arr.value_as_time(i).unwrap();
-            assert_eq!(formatted[i], time.format("%H:%M:%S%.3f").to_string());
+            assert_eq!(*item, time.format("%H:%M:%S%.3f").to_string());
         }
     }
 
diff --git a/rust/arrow/src/array/equal_json.rs b/rust/arrow/src/array/equal_json.rs
index 8016eb4..6fc37f1 100644
--- a/rust/arrow/src/array/equal_json.rs
+++ b/rust/arrow/src/array/equal_json.rs
@@ -402,8 +402,8 @@ mod tests {
     use crate::error::Result;
     use std::{convert::TryFrom, sync::Arc};
 
-    fn create_list_array<'a, U: AsRef<[i32]>, T: AsRef<[Option<U>]>>(
-        builder: &'a mut ListBuilder<Int32Builder>,
+    fn create_list_array<U: AsRef<[i32]>, T: AsRef<[Option<U>]>>(
+        builder: &mut ListBuilder<Int32Builder>,
         data: T,
     ) -> Result<ListArray> {
         for d in data.as_ref() {
@@ -418,8 +418,8 @@ mod tests {
     }
 
     /// Create a fixed size list of 2 value lengths
-    fn create_fixed_size_list_array<'a, U: AsRef<[i32]>, T: AsRef<[Option<U>]>>(
-        builder: &'a mut FixedSizeListBuilder<Int32Builder>,
+    fn create_fixed_size_list_array<U: AsRef<[i32]>, T: AsRef<[Option<U>]>>(
+        builder: &mut FixedSizeListBuilder<Int32Builder>,
         data: T,
     ) -> Result<FixedSizeListArray> {
         for d in data.as_ref() {
diff --git a/rust/arrow/src/array/iterator.rs b/rust/arrow/src/array/iterator.rs
index bd5f9a2..34dfe26 100644
--- a/rust/arrow/src/array/iterator.rs
+++ b/rust/arrow/src/array/iterator.rs
@@ -225,10 +225,10 @@ mod tests {
         let result: StringArray = array
             .iter()
             .map(|e| {
-                e.and_then(|e| {
+                e.map(|e| {
                     let mut a = e.to_string();
                     a.push('b');
-                    Some(a)
+                    a
                 })
             })
             .collect();
diff --git a/rust/arrow/src/array/transform/mod.rs b/rust/arrow/src/array/transform/mod.rs
index 410ca36..d8e398a 100644
--- a/rust/arrow/src/array/transform/mod.rs
+++ b/rust/arrow/src/array/transform/mod.rs
@@ -159,7 +159,7 @@ impl<'a> std::fmt::Debug for MutableArrayData<'a> {
     }
 }
 
-fn build_extend<'a>(array: &'a ArrayData) -> Extend<'a> {
+fn build_extend(array: &ArrayData) -> Extend {
     use crate::datatypes::*;
     match array.data_type() {
         DataType::Boolean => boolean::build_extend(array),
diff --git a/rust/arrow/src/compute/kernels/filter.rs b/rust/arrow/src/compute/kernels/filter.rs
index ff0fdb7..e90e493 100644
--- a/rust/arrow/src/compute/kernels/filter.rs
+++ b/rust/arrow/src/compute/kernels/filter.rs
@@ -929,12 +929,8 @@ mod tests {
     fn test_filter_array_low_density() {
         // this test exercises the all 0's branch of the filter algorithm
         let mut data_values = (1..=65).collect::<Vec<i32>>();
-        let mut filter_values = (1..=65)
-            .map(|i| match i % 65 {
-                0 => true,
-                _ => false,
-            })
-            .collect::<Vec<bool>>();
+        let mut filter_values =
+            (1..=65).map(|i| matches!(i % 65, 0)).collect::<Vec<bool>>();
         // set up two more values after the batch
         data_values.extend_from_slice(&[66, 67]);
         filter_values.extend_from_slice(&[false, true]);
@@ -952,10 +948,7 @@ mod tests {
         // this test exercises the all 1's branch of the filter algorithm
         let mut data_values = (1..=65).map(Some).collect::<Vec<_>>();
         let mut filter_values = (1..=65)
-            .map(|i| match i % 65 {
-                0 => false,
-                _ => true,
-            })
+            .map(|i| !matches!(i % 65, 0))
             .collect::<Vec<bool>>();
         // set second data value to null
         data_values[1] = None;
diff --git a/rust/arrow/src/json/reader.rs b/rust/arrow/src/json/reader.rs
index 5bfa30a..786fedf 100644
--- a/rust/arrow/src/json/reader.rs
+++ b/rust/arrow/src/json/reader.rs
@@ -814,7 +814,7 @@ impl<R: Read> Reader<R> {
                         let builder = builder
                             .as_any_mut()
                             .downcast_mut::<ListBuilder<StringBuilder>>()
-                            .ok_or(ArrowError::JsonError(
+                            .ok_or_else(||ArrowError::JsonError(
                                 "Cast failed for ListBuilder<StringBuilder> during nested data parsing".to_string(),
                             ))?;
                         for val in vals {
@@ -829,7 +829,7 @@ impl<R: Read> Reader<R> {
                         builder.append(true)?;
                     }
                     DataType::Dictionary(_, _) => {
-                        let builder = builder.as_any_mut().downcast_mut::<ListBuilder<StringDictionaryBuilder<DICT_TY>>>().ok_or(ArrowError::JsonError(
+                        let builder = builder.as_any_mut().downcast_mut::<ListBuilder<StringDictionaryBuilder<DICT_TY>>>().ok_or_else(||ArrowError::JsonError(
                             "Cast failed for ListBuilder<StringDictionaryBuilder> during nested data parsing".to_string(),
                         ))?;
                         for val in vals {
diff --git a/rust/arrow/src/lib.rs b/rust/arrow/src/lib.rs
index ccfb452..1355c72 100644
--- a/rust/arrow/src/lib.rs
+++ b/rust/arrow/src/lib.rs
@@ -133,15 +133,7 @@
 #![warn(missing_debug_implementations)]
 #![deny(clippy::redundant_clone)]
 // introduced to ignore lint errors when upgrading from 2020-04-22 to 2020-11-14
-#![allow(
-    clippy::bind_instead_of_map,
-    clippy::float_equality_without_abs,
-    clippy::match_like_matches_macro,
-    clippy::needless_lifetimes,
-    clippy::needless_range_loop,
-    clippy::or_fun_call,
-    clippy::type_complexity
-)]
+#![allow(clippy::float_equality_without_abs, clippy::type_complexity)]
 
 mod arch;
 pub mod array;