Skip to content

Commit 356c300

Browse files
nevi-mejorgecarleitao
authored andcommitted
ARROW-11603: [Rust] Fix Clippy Lints for Rust 1.50
# Rationale: CI uses "stable" rust. 1.50 stable was released today: https://blog.rust-lang.org/2021/02/11/Rust-1.50.0.html The new clippy is pickier resulting in many clippy warnings such as https://github.com/apache/arrow/pull/9469/checks?check_run_id=1881854256 We need to get CI back green # Changes Based on based on #9475 from @nevi-me, this PR aims to get the CI green as soon as possible. Ideally, we would fix the actual lint problems, However, when I tried to do so the lints propagated into a significant change -- as clippy says to remove the `Result` but then there are a bunch of call sites that then also need t be changed I want to get CI back clean as soon as possible so I just hammered through and cleaned up as best I could as well as sprinkling in various `#[allow(clippy::unnecessary_wraps)]` as necessary to get a clean run. My rationale is that the code is no worse than it was before. Though it could be better! Closes #9476 from alamb/ARROW-11602-lints Authored-by: Neville Dipale <[email protected]> Signed-off-by: Jorge C. Leitao <[email protected]>
1 parent 7c5cf92 commit 356c300

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+80
-106
lines changed

rust/arrow/examples/read_csv.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ use std::sync::Arc;
2222

2323
use arrow::csv;
2424
use arrow::datatypes::{DataType, Field, Schema};
25-
use arrow::error::Result;
2625
#[cfg(feature = "prettyprint")]
2726
use arrow::util::pretty::print_batches;
2827

29-
fn main() -> Result<()> {
28+
fn main() {
3029
let schema = Schema::new(vec![
3130
Field::new("city", DataType::Utf8, false),
3231
Field::new("lat", DataType::Float64, false),
@@ -41,5 +40,4 @@ fn main() -> Result<()> {
4140
{
4241
print_batches(&[_batch]).unwrap();
4342
}
44-
Ok(())
4543
}

rust/arrow/examples/read_csv_infer_schema.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
extern crate arrow;
1919

2020
use arrow::csv;
21-
use arrow::error::Result;
2221
#[cfg(feature = "prettyprint")]
2322
use arrow::util::pretty::print_batches;
2423
use std::fs::File;
2524

26-
fn main() -> Result<()> {
25+
fn main() {
2726
let file = File::open("test/data/uk_cities_with_headers.csv").unwrap();
2827
let builder = csv::ReaderBuilder::new()
2928
.has_header(true)
@@ -34,5 +33,4 @@ fn main() -> Result<()> {
3433
{
3534
print_batches(&[_batch]).unwrap();
3635
}
37-
Ok(())
3836
}

rust/arrow/src/array/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ impl FieldData {
14991499
}
15001500

15011501
/// Appends a single value to this `FieldData`'s `values_buffer`.
1502+
#[allow(clippy::unnecessary_wraps)]
15021503
fn append_to_values_buffer<T: ArrowPrimitiveType>(
15031504
&mut self,
15041505
v: T::Native,
@@ -1521,6 +1522,7 @@ impl FieldData {
15211522
}
15221523

15231524
/// Appends a null to this `FieldData`.
1525+
#[allow(clippy::unnecessary_wraps)]
15241526
fn append_null<T: ArrowPrimitiveType>(&mut self) -> Result<()> {
15251527
if let Some(b) = &mut self.bitmap_builder {
15261528
let values_buffer = self

rust/arrow/src/array/transform/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ mod tests {
10751075
}
10761076

10771077
#[test]
1078-
fn test_fixed_size_binary_append() -> Result<()> {
1078+
fn test_fixed_size_binary_append() {
10791079
let a = vec![Some(vec![1, 2]), Some(vec![3, 4]), Some(vec![5, 6])];
10801080
let a = FixedSizeBinaryArray::from(a).data();
10811081

@@ -1118,7 +1118,6 @@ mod tests {
11181118
];
11191119
let expected = FixedSizeBinaryArray::from(expected).data();
11201120
assert_eq!(&result, expected.as_ref());
1121-
Ok(())
11221121
}
11231122

11241123
/*

rust/arrow/src/buffer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ mod tests {
16191619
}
16201620

16211621
#[test]
1622-
fn test_mutable_equal() -> Result<()> {
1622+
fn test_mutable_equal() {
16231623
let mut buf = MutableBuffer::new(1);
16241624
let mut buf2 = MutableBuffer::new(1);
16251625

@@ -1632,8 +1632,6 @@ mod tests {
16321632

16331633
buf2.reserve(65);
16341634
assert!(buf != buf2);
1635-
1636-
Ok(())
16371635
}
16381636

16391637
#[test]

rust/arrow/src/compute/kernels/cast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ const EPOCH_DAYS_FROM_CE: i32 = 719_163;
821821
/// Arrays should have the same primitive data type, otherwise this should fail.
822822
/// We do not perform this check on primitive data types as we only use this
823823
/// function internally, where it is guaranteed to be infallible.
824+
#[allow(clippy::unnecessary_wraps)]
824825
fn cast_array_data<TO>(array: &ArrayRef, to_type: DataType) -> Result<ArrayRef>
825826
where
826827
TO: ArrowNumericType,
@@ -838,6 +839,7 @@ where
838839
}
839840

840841
/// Convert Array into a PrimitiveArray of type, and apply numeric cast
842+
#[allow(clippy::unnecessary_wraps)]
841843
fn cast_numeric_arrays<FROM, TO>(from: &ArrayRef) -> Result<ArrayRef>
842844
where
843845
FROM: ArrowNumericType,
@@ -869,6 +871,7 @@ where
869871
}
870872

871873
/// Cast numeric types to Utf8
874+
#[allow(clippy::unnecessary_wraps)]
872875
fn cast_numeric_to_string<FROM>(array: &ArrayRef) -> Result<ArrayRef>
873876
where
874877
FROM: ArrowNumericType,
@@ -893,6 +896,7 @@ where
893896
}
894897

895898
/// Cast numeric types to Utf8
899+
#[allow(clippy::unnecessary_wraps)]
896900
fn cast_string_to_numeric<T>(from: &ArrayRef) -> Result<ArrayRef>
897901
where
898902
T: ArrowNumericType,
@@ -959,6 +963,7 @@ where
959963
/// Cast Boolean types to numeric
960964
///
961965
/// `false` returns 0 while `true` returns 1
966+
#[allow(clippy::unnecessary_wraps)]
962967
fn cast_bool_to_numeric<TO>(from: &ArrayRef) -> Result<ArrayRef>
963968
where
964969
TO: ArrowNumericType,

rust/arrow/src/compute/kernels/concat.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,18 @@ mod tests {
7777
use std::sync::Arc;
7878

7979
#[test]
80-
fn test_concat_empty_vec() -> Result<()> {
80+
fn test_concat_empty_vec() {
8181
let re = concat(&[]);
8282
assert!(re.is_err());
83-
Ok(())
8483
}
8584

8685
#[test]
87-
fn test_concat_incompatible_datatypes() -> Result<()> {
86+
fn test_concat_incompatible_datatypes() {
8887
let re = concat(&[
8988
&PrimitiveArray::<Int64Type>::from(vec![Some(-1), Some(2), None]),
9089
&StringArray::from(vec![Some("hello"), Some("bar"), Some("world")]),
9190
]);
9291
assert!(re.is_err());
93-
Ok(())
9492
}
9593

9694
#[test]

rust/arrow/src/compute/kernels/length.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::{
2424
};
2525
use std::sync::Arc;
2626

27+
#[allow(clippy::unnecessary_wraps)]
2728
fn length_string<OffsetSize>(array: &Array, data_type: DataType) -> Result<ArrayRef>
2829
where
2930
OffsetSize: OffsetSizeTrait,
@@ -178,11 +179,10 @@ mod tests {
178179

179180
/// Tests that length is not valid for u64.
180181
#[test]
181-
fn wrong_type() -> Result<()> {
182+
fn wrong_type() {
182183
let array: UInt64Array = vec![1u64].into();
183184

184185
assert!(length(&array).is_err());
185-
Ok(())
186186
}
187187

188188
/// Tests with an offset

rust/arrow/src/compute/kernels/sort.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl Default for SortOptions {
254254
}
255255

256256
/// Sort primitive values
257+
#[allow(clippy::unnecessary_wraps)]
257258
fn sort_boolean(
258259
values: &ArrayRef,
259260
value_indices: Vec<u32>,
@@ -316,6 +317,7 @@ fn sort_boolean(
316317
}
317318

318319
/// Sort primitive values
320+
#[allow(clippy::unnecessary_wraps)]
319321
fn sort_primitive<T, F>(
320322
values: &ArrayRef,
321323
value_indices: Vec<u32>,
@@ -446,6 +448,7 @@ fn sort_string_dictionary<T: ArrowDictionaryKeyType>(
446448

447449
/// shared implementation between dictionary encoded and plain string arrays
448450
#[inline]
451+
#[allow(clippy::unnecessary_wraps)]
449452
fn sort_string_helper<'a, A: Array, F>(
450453
values: &'a A,
451454
value_indices: Vec<u32>,
@@ -481,6 +484,7 @@ where
481484
Ok(UInt32Array::from(valid_indices))
482485
}
483486

487+
#[allow(clippy::unnecessary_wraps)]
484488
fn sort_list<S, T>(
485489
values: &ArrayRef,
486490
value_indices: Vec<u32>,

rust/arrow/src/compute/kernels/substring.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::{
2424
};
2525
use std::sync::Arc;
2626

27+
#[allow(clippy::unnecessary_wraps)]
2728
fn generic_substring<OffsetSize: StringOffsetSizeTrait>(
2829
array: &GenericStringArray<OffsetSize>,
2930
start: OffsetSize,

0 commit comments

Comments
 (0)