Skip to content

Commit b3f06f6

Browse files
authored
Fix up clippy for Rust 1.78 (#5710)
* Fix up clippy for Rust 1.78 * Should not be pub
1 parent eb2d00b commit b3f06f6

File tree

9 files changed

+54
-39
lines changed

9 files changed

+54
-39
lines changed

arrow-cast/src/parse.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,20 @@ impl Parser for Float64Type {
435435
}
436436
}
437437

438+
/// This API is only stable since 1.70 so can't use it when current MSRV is lower
439+
#[inline(always)]
440+
fn is_some_and<T>(opt: Option<T>, f: impl FnOnce(T) -> bool) -> bool {
441+
match opt {
442+
None => false,
443+
Some(x) => f(x),
444+
}
445+
}
446+
438447
macro_rules! parser_primitive {
439448
($t:ty) => {
440449
impl Parser for $t {
441450
fn parse(string: &str) -> Option<Self::Native> {
442-
if !string.as_bytes().last().is_some_and(|x| x.is_ascii_digit()) {
451+
if !is_some_and(string.as_bytes().last(), |x| x.is_ascii_digit()) {
443452
return None;
444453
}
445454
match atoi::FromRadix10SignedChecked::from_radix_10_signed_checked(

arrow-integration-testing/src/bin/arrow-json-integration-test.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ struct Args {
4040
arrow: String,
4141
#[clap(short, long, help("Path to JSON file"))]
4242
json: String,
43-
#[clap(value_enum, short, long, default_value_t = Mode::Validate, help="Mode of integration testing tool")]
43+
#[clap(
44+
value_enum,
45+
short,
46+
long,
47+
default_value = "VALIDATE",
48+
help = "Mode of integration testing tool"
49+
)]
4450
mode: Mode,
4551
#[clap(short, long)]
4652
verbose: bool,

arrow-json/src/reader/serializer.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,16 @@ impl<'a, 'b> SerializeMap for ObjectSerializer<'a, 'b> {
309309
type Ok = ();
310310
type Error = SerializerError;
311311

312-
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
312+
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
313313
where
314-
T: Serialize,
314+
T: Serialize + ?Sized,
315315
{
316316
key.serialize(&mut *self.serializer)
317317
}
318318

319-
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
319+
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
320320
where
321-
T: Serialize,
321+
T: Serialize + ?Sized,
322322
{
323323
value.serialize(&mut *self.serializer)
324324
}
@@ -333,13 +333,9 @@ impl<'a, 'b> SerializeStruct for ObjectSerializer<'a, 'b> {
333333
type Ok = ();
334334
type Error = SerializerError;
335335

336-
fn serialize_field<T: ?Sized>(
337-
&mut self,
338-
key: &'static str,
339-
value: &T,
340-
) -> Result<(), Self::Error>
336+
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
341337
where
342-
T: Serialize,
338+
T: Serialize + ?Sized,
343339
{
344340
key.serialize(&mut *self.serializer)?;
345341
value.serialize(&mut *self.serializer)
@@ -376,9 +372,9 @@ impl<'a, 'b> SerializeSeq for ListSerializer<'a, 'b> {
376372
type Ok = ();
377373
type Error = SerializerError;
378374

379-
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
375+
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
380376
where
381-
T: Serialize,
377+
T: Serialize + ?Sized,
382378
{
383379
value.serialize(&mut *self.serializer)
384380
}
@@ -393,9 +389,9 @@ impl<'a, 'b> SerializeTuple for ListSerializer<'a, 'b> {
393389
type Ok = ();
394390
type Error = SerializerError;
395391

396-
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
392+
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
397393
where
398-
T: Serialize,
394+
T: Serialize + ?Sized,
399395
{
400396
value.serialize(&mut *self.serializer)
401397
}
@@ -410,9 +406,9 @@ impl<'a, 'b> SerializeTupleStruct for ListSerializer<'a, 'b> {
410406
type Ok = ();
411407
type Error = SerializerError;
412408

413-
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
409+
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
414410
where
415-
T: Serialize,
411+
T: Serialize + ?Sized,
416412
{
417413
value.serialize(&mut *self.serializer)
418414
}

arrow-json/src/writer/encoder.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,21 @@ struct StructArrayEncoder<'a> {
155155
explicit_nulls: bool,
156156
}
157157

158+
/// This API is only stable since 1.70 so can't use it when current MSRV is lower
159+
#[inline(always)]
160+
fn is_some_and<T>(opt: Option<T>, f: impl FnOnce(T) -> bool) -> bool {
161+
match opt {
162+
None => false,
163+
Some(x) => f(x),
164+
}
165+
}
166+
158167
impl<'a> Encoder for StructArrayEncoder<'a> {
159168
fn encode(&mut self, idx: usize, out: &mut Vec<u8>) {
160169
out.push(b'{');
161170
let mut is_first = true;
162171
for field_encoder in &mut self.encoders {
163-
let is_null = field_encoder.nulls.as_ref().is_some_and(|n| n.is_null(idx));
172+
let is_null = is_some_and(field_encoder.nulls.as_ref(), |n| n.is_null(idx));
164173
if is_null && !self.explicit_nulls {
165174
continue;
166175
}
@@ -447,13 +456,13 @@ impl<'a> MapEncoder<'a> {
447456
let (values, value_nulls) = make_encoder_impl(values, options)?;
448457

449458
// We sanity check nulls as these are currently not enforced by MapArray (#1697)
450-
if key_nulls.is_some_and(|x| x.null_count() != 0) {
459+
if is_some_and(key_nulls, |x| x.null_count() != 0) {
451460
return Err(ArrowError::InvalidArgumentError(
452461
"Encountered nulls in MapArray keys".to_string(),
453462
));
454463
}
455464

456-
if array.entries().nulls().is_some_and(|x| x.null_count() != 0) {
465+
if is_some_and(array.entries().nulls(), |x| x.null_count() != 0) {
457466
return Err(ArrowError::InvalidArgumentError(
458467
"Encountered nulls in MapArray entries".to_string(),
459468
));
@@ -478,7 +487,7 @@ impl<'a> Encoder for MapEncoder<'a> {
478487

479488
out.push(b'{');
480489
for idx in start..end {
481-
let is_null = self.value_nulls.as_ref().is_some_and(|n| n.is_null(idx));
490+
let is_null = is_some_and(self.value_nulls.as_ref(), |n| n.is_null(idx));
482491
if is_null && !self.explicit_nulls {
483492
continue;
484493
}

arrow-select/src/take.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,9 +1401,9 @@ mod tests {
14011401
);
14021402
}
14031403

1404-
fn _test_take_string<'a, K: 'static>()
1404+
fn _test_take_string<'a, K>()
14051405
where
1406-
K: Array + PartialEq + From<Vec<Option<&'a str>>>,
1406+
K: Array + PartialEq + From<Vec<Option<&'a str>>> + 'static,
14071407
{
14081408
let index = UInt32Array::from(vec![Some(3), None, Some(1), Some(3), Some(4)]);
14091409

arrow/src/util/string_writer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
//! }
6464
//! ```
6565
66+
use std::fmt::Formatter;
6667
use std::io::{Error, ErrorKind, Result, Write};
6768

6869
#[derive(Debug)]
@@ -83,10 +84,9 @@ impl Default for StringWriter {
8384
Self::new()
8485
}
8586
}
86-
87-
impl ToString for StringWriter {
88-
fn to_string(&self) -> String {
89-
self.data.clone()
87+
impl std::fmt::Display for StringWriter {
88+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
89+
write!(f, "{}", self.data)
9090
}
9191
}
9292

parquet/src/column/writer/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,13 +1172,6 @@ fn compare_greater<T: ParquetValueType>(descr: &ColumnDescriptor, a: &T, b: &T)
11721172
// https://github.com/apache/parquet-mr/blob/master/parquet-column/src/main/java/org/apache/parquet/column/values/factory/DefaultV1ValuesWriterFactory.java
11731173
// https://github.com/apache/parquet-mr/blob/master/parquet-column/src/main/java/org/apache/parquet/column/values/factory/DefaultV2ValuesWriterFactory.java
11741174

1175-
/// Trait to define default encoding for types, including whether or not the type
1176-
/// supports dictionary encoding.
1177-
trait EncodingWriteSupport {
1178-
/// Returns true if dictionary is supported for column writer, false otherwise.
1179-
fn has_dictionary_support(props: &WriterProperties) -> bool;
1180-
}
1181-
11821175
/// Returns encoding for a column when no other encoding is provided in writer properties.
11831176
fn fallback_encoding(kind: Type, props: &WriterProperties) -> Encoding {
11841177
match (kind, props.writer_version()) {

parquet/src/encodings/encoding/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::data_type::private::ParquetValueType;
2424
use crate::data_type::*;
2525
use crate::encodings::rle::RleEncoder;
2626
use crate::errors::{ParquetError, Result};
27-
use crate::util::bit_util::{self, num_required_bits, BitWriter};
27+
use crate::util::bit_util::{num_required_bits, BitWriter};
2828

2929
use bytes::Bytes;
3030
pub use dict_encoder::DictEncoder;
@@ -47,12 +47,13 @@ pub trait Encoder<T: DataType>: Send {
4747
/// identified by `valid_bits`.
4848
///
4949
/// Returns the number of non-null values encoded.
50+
#[cfg(test)]
5051
fn put_spaced(&mut self, values: &[T::T], valid_bits: &[u8]) -> Result<usize> {
5152
let num_values = values.len();
5253
let mut buffer = Vec::with_capacity(num_values);
5354
// TODO: this is pretty inefficient. Revisit in future.
5455
for (i, item) in values.iter().enumerate().take(num_values) {
55-
if bit_util::get_bit(valid_bits, i) {
56+
if crate::util::bit_util::get_bit(valid_bits, i) {
5657
buffer.push(item.clone());
5758
}
5859
}
@@ -727,6 +728,7 @@ mod tests {
727728
use crate::encodings::decoding::{get_decoder, Decoder, DictDecoder, PlainDecoder};
728729
use crate::schema::types::{ColumnDescPtr, ColumnDescriptor, ColumnPath, Type as SchemaType};
729730
use crate::util::test_common::rand_gen::{random_bytes, RandGen};
731+
use crate::util::bit_util;
730732

731733
const TEST_SET_SIZE: usize = 1024;
732734

parquet/src/file/statistics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ pub fn to_thrift(stats: Option<&Statistics>) -> Option<TStatistics> {
271271

272272
if stats.is_min_max_backwards_compatible() {
273273
// Copy to deprecated min, max values for compatibility with older readers
274-
thrift_stats.min = min.clone();
275-
thrift_stats.max = max.clone();
274+
thrift_stats.min.clone_from(&min);
275+
thrift_stats.max.clone_from(&max);
276276
}
277277

278278
if !stats.is_min_max_deprecated() {

0 commit comments

Comments
 (0)