This is an automated email from the ASF dual-hosted git repository.
mbrobbel pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 28cf02db55 Migrate `arrow-buffer` to Rust 2024 (#8452)
28cf02db55 is described below
commit 28cf02db5500d9aa1a8effecc9622b331a5a69fe
Author: Matthijs Brobbel <[email protected]>
AuthorDate: Mon Sep 29 21:36:41 2025 +0200
Migrate `arrow-buffer` to Rust 2024 (#8452)
# Which issue does this PR close?
- Contribute to #6827
# Rationale for this change
Splitting up #8227.
# What changes are included in this PR?
Migrate `arrow-buffer` to Rust 2024
# Are these changes tested?
CI
# Are there any user-facing changes?
Yes
---
arrow-buffer/Cargo.toml | 2 +-
arrow-buffer/benches/bit_mask.rs | 2 +-
arrow-buffer/src/bigint/mod.rs | 10 +++-------
arrow-buffer/src/buffer/boolean.rs | 4 ++--
arrow-buffer/src/buffer/immutable.rs | 10 +++++-----
arrow-buffer/src/buffer/mutable.rs | 34 ++++++++++++++++++----------------
arrow-buffer/src/buffer/run.rs | 2 +-
arrow-buffer/src/buffer/scalar.rs | 6 ++++--
arrow-buffer/src/builder/boolean.rs | 2 +-
arrow-buffer/src/native.rs | 2 +-
arrow-buffer/src/pool.rs | 2 +-
arrow-buffer/src/util/bit_mask.rs | 16 +++++++---------
arrow-buffer/src/util/bit_util.rs | 10 +++++++---
13 files changed, 52 insertions(+), 50 deletions(-)
diff --git a/arrow-buffer/Cargo.toml b/arrow-buffer/Cargo.toml
index d1651abb79..8a8a1d8269 100644
--- a/arrow-buffer/Cargo.toml
+++ b/arrow-buffer/Cargo.toml
@@ -25,7 +25,7 @@ authors = { workspace = true }
license = { workspace = true }
keywords = { workspace = true }
include = { workspace = true }
-edition = { workspace = true }
+edition = "2024"
rust-version = { workspace = true }
[lib]
diff --git a/arrow-buffer/benches/bit_mask.rs b/arrow-buffer/benches/bit_mask.rs
index 545528724e..0384089e32 100644
--- a/arrow-buffer/benches/bit_mask.rs
+++ b/arrow-buffer/benches/bit_mask.rs
@@ -16,7 +16,7 @@
// under the License.
use arrow_buffer::bit_mask::set_bits;
-use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
+use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use std::hint;
fn criterion_benchmark(c: &mut Criterion) {
diff --git a/arrow-buffer/src/bigint/mod.rs b/arrow-buffer/src/bigint/mod.rs
index b078555c36..f4e1e56929 100644
--- a/arrow-buffer/src/bigint/mod.rs
+++ b/arrow-buffer/src/bigint/mod.rs
@@ -18,7 +18,7 @@
use crate::arith::derive_arith;
use crate::bigint::div::div_rem;
use num_bigint::BigInt;
-use num_traits::{cast::AsPrimitive, FromPrimitive, ToPrimitive};
+use num_traits::{FromPrimitive, ToPrimitive, cast::AsPrimitive};
use std::cmp::Ordering;
use std::num::ParseIntError;
use std::ops::{BitAnd, BitOr, BitXor, Neg, Shl, Shr};
@@ -232,11 +232,7 @@ impl i256 {
pub fn from_f64(v: f64) -> Option<Self> {
BigInt::from_f64(v).and_then(|i| {
let (integer, overflow) = i256::from_bigint_with_overflow(i);
- if overflow {
- None
- } else {
- Some(integer)
- }
+ if overflow { None } else { Some(integer) }
})
}
@@ -868,7 +864,7 @@ impl ToPrimitive for i256 {
mod tests {
use super::*;
use num_traits::Signed;
- use rand::{rng, Rng};
+ use rand::{Rng, rng};
#[test]
fn test_signed_cmp() {
diff --git a/arrow-buffer/src/buffer/boolean.rs
b/arrow-buffer/src/buffer/boolean.rs
index 8456f184a7..a3bcabbfdb 100644
--- a/arrow-buffer/src/buffer/boolean.rs
+++ b/arrow-buffer/src/buffer/boolean.rs
@@ -18,8 +18,8 @@
use crate::bit_chunk_iterator::BitChunks;
use crate::bit_iterator::{BitIndexIterator, BitIndexU32Iterator, BitIterator,
BitSliceIterator};
use crate::{
- bit_util, buffer_bin_and, buffer_bin_or, buffer_bin_xor, buffer_unary_not,
- BooleanBufferBuilder, Buffer, MutableBuffer,
+ BooleanBufferBuilder, Buffer, MutableBuffer, bit_util, buffer_bin_and,
buffer_bin_or,
+ buffer_bin_xor, buffer_unary_not,
};
use std::ops::{BitAnd, BitOr, BitXor, Not};
diff --git a/arrow-buffer/src/buffer/immutable.rs
b/arrow-buffer/src/buffer/immutable.rs
index 57f30edf1e..20eb966a8f 100644
--- a/arrow-buffer/src/buffer/immutable.rs
+++ b/arrow-buffer/src/buffer/immutable.rs
@@ -20,9 +20,9 @@ use std::fmt::Debug;
use std::ptr::NonNull;
use std::sync::Arc;
+use crate::BufferBuilder;
use crate::alloc::{Allocation, Deallocation};
use crate::util::bit_chunk_iterator::{BitChunks, UnalignedBitChunk};
-use crate::BufferBuilder;
use crate::{bit_util, bytes::Bytes, native::ArrowNativeType};
#[cfg(feature = "pool")]
@@ -172,7 +172,7 @@ impl Buffer {
len: usize,
owner: Arc<dyn Allocation>,
) -> Self {
- Buffer::build_with_arguments(ptr, len, Deallocation::Custom(owner,
len))
+ unsafe { Buffer::build_with_arguments(ptr, len,
Deallocation::Custom(owner, len)) }
}
/// Auxiliary method to create a new Buffer
@@ -181,7 +181,7 @@ impl Buffer {
len: usize,
deallocation: Deallocation,
) -> Self {
- let bytes = Bytes::new(ptr, len, deallocation);
+ let bytes = unsafe { Bytes::new(ptr, len, deallocation) };
let ptr = bytes.as_ptr();
Buffer {
ptr,
@@ -561,7 +561,7 @@ impl Buffer {
pub unsafe fn from_trusted_len_iter<T: ArrowNativeType, I: Iterator<Item =
T>>(
iterator: I,
) -> Self {
- MutableBuffer::from_trusted_len_iter(iterator).into()
+ unsafe { MutableBuffer::from_trusted_len_iter(iterator).into() }
}
/// Creates a [`Buffer`] from an [`Iterator`] with a trusted (upper)
length or errors
@@ -578,7 +578,7 @@ impl Buffer {
>(
iterator: I,
) -> Result<Self, E> {
- Ok(MutableBuffer::try_from_trusted_len_iter(iterator)?.into())
+ unsafe {
Ok(MutableBuffer::try_from_trusted_len_iter(iterator)?.into()) }
}
}
diff --git a/arrow-buffer/src/buffer/mutable.rs
b/arrow-buffer/src/buffer/mutable.rs
index 63fdbf598b..93d9d6b9ad 100644
--- a/arrow-buffer/src/buffer/mutable.rs
+++ b/arrow-buffer/src/buffer/mutable.rs
@@ -15,11 +15,11 @@
// specific language governing permissions and limitations
// under the License.
-use std::alloc::{handle_alloc_error, Layout};
+use std::alloc::{Layout, handle_alloc_error};
use std::mem;
use std::ptr::NonNull;
-use crate::alloc::{Deallocation, ALIGNMENT};
+use crate::alloc::{ALIGNMENT, Deallocation};
use crate::{
bytes::Bytes,
native::{ArrowNativeType, ToByteSlice},
@@ -460,8 +460,8 @@ impl MutableBuffer {
pub unsafe fn push_unchecked<T: ToByteSlice>(&mut self, item: T) {
let additional = std::mem::size_of::<T>();
let src = item.to_byte_slice().as_ptr();
- let dst = self.data.as_ptr().add(self.len);
- std::ptr::copy_nonoverlapping(src, dst, additional);
+ let dst = unsafe { self.data.as_ptr().add(self.len) };
+ unsafe { std::ptr::copy_nonoverlapping(src, dst, additional) };
self.len += additional;
}
@@ -640,11 +640,11 @@ impl MutableBuffer {
for item in iterator {
// note how there is no reserve here (compared with
`extend_from_iter`)
let src = item.to_byte_slice().as_ptr();
- std::ptr::copy_nonoverlapping(src, dst, item_size);
- dst = dst.add(item_size);
+ unsafe { std::ptr::copy_nonoverlapping(src, dst, item_size) };
+ dst = unsafe { dst.add(item_size) };
}
assert_eq!(
- dst.offset_from(buffer.data.as_ptr()) as usize,
+ unsafe { dst.offset_from(buffer.data.as_ptr()) } as usize,
len,
"Trusted iterator length was not accurately reported"
);
@@ -703,20 +703,22 @@ impl MutableBuffer {
let item = item?;
// note how there is no reserve here (compared with
`extend_from_iter`)
let src = item.to_byte_slice().as_ptr();
- std::ptr::copy_nonoverlapping(src, dst, item_size);
- dst = dst.add(item_size);
+ unsafe { std::ptr::copy_nonoverlapping(src, dst, item_size) };
+ dst = unsafe { dst.add(item_size) };
}
// try_from_trusted_len_iter is instantiated a lot, so we extract part
of it into a less
// generic method to reduce compile time
unsafe fn finalize_buffer(dst: *mut u8, buffer: &mut MutableBuffer,
len: usize) {
- assert_eq!(
- dst.offset_from(buffer.data.as_ptr()) as usize,
- len,
- "Trusted iterator length was not accurately reported"
- );
- buffer.len = len;
+ unsafe {
+ assert_eq!(
+ dst.offset_from(buffer.data.as_ptr()) as usize,
+ len,
+ "Trusted iterator length was not accurately reported"
+ );
+ buffer.len = len;
+ }
}
- finalize_buffer(dst, &mut buffer, len);
+ unsafe { finalize_buffer(dst, &mut buffer, len) };
Ok(buffer)
}
}
diff --git a/arrow-buffer/src/buffer/run.rs b/arrow-buffer/src/buffer/run.rs
index cc6d19044f..61fff6692e 100644
--- a/arrow-buffer/src/buffer/run.rs
+++ b/arrow-buffer/src/buffer/run.rs
@@ -15,8 +15,8 @@
// specific language governing permissions and limitations
// under the License.
-use crate::buffer::ScalarBuffer;
use crate::ArrowNativeType;
+use crate::buffer::ScalarBuffer;
/// A slice-able buffer of monotonically increasing, positive integers used to
store run-ends
///
diff --git a/arrow-buffer/src/buffer/scalar.rs
b/arrow-buffer/src/buffer/scalar.rs
index 4dd516c708..c058fbdce9 100644
--- a/arrow-buffer/src/buffer/scalar.rs
+++ b/arrow-buffer/src/buffer/scalar.rs
@@ -162,8 +162,10 @@ impl<T: ArrowNativeType> From<Buffer> for ScalarBuffer<T> {
is_aligned,
"Memory pointer is not aligned with the specified scalar type"
),
- Deallocation::Custom(_, _) =>
- assert!(is_aligned, "Memory pointer from external source (e.g,
FFI) is not aligned with the specified scalar type. Before importing buffer
through FFI, please make sure the allocation is aligned."),
+ Deallocation::Custom(_, _) => assert!(
+ is_aligned,
+ "Memory pointer from external source (e.g, FFI) is not aligned
with the specified scalar type. Before importing buffer through FFI, please
make sure the allocation is aligned."
+ ),
}
Self {
diff --git a/arrow-buffer/src/builder/boolean.rs
b/arrow-buffer/src/builder/boolean.rs
index bdcc3a55db..4ca91d1d73 100644
--- a/arrow-buffer/src/builder/boolean.rs
+++ b/arrow-buffer/src/builder/boolean.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use crate::{bit_mask, bit_util, BooleanBuffer, Buffer, MutableBuffer};
+use crate::{BooleanBuffer, Buffer, MutableBuffer, bit_mask, bit_util};
use std::ops::Range;
/// Builder for [`BooleanBuffer`]
diff --git a/arrow-buffer/src/native.rs b/arrow-buffer/src/native.rs
index eb8e067db0..68058a4eec 100644
--- a/arrow-buffer/src/native.rs
+++ b/arrow-buffer/src/native.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-use crate::{i256, IntervalDayTime, IntervalMonthDayNano};
+use crate::{IntervalDayTime, IntervalMonthDayNano, i256};
use half::f16;
mod private {
diff --git a/arrow-buffer/src/pool.rs b/arrow-buffer/src/pool.rs
index bf22d433d6..95bd308a35 100644
--- a/arrow-buffer/src/pool.rs
+++ b/arrow-buffer/src/pool.rs
@@ -30,8 +30,8 @@
//! ```
use std::fmt::Debug;
-use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
+use std::sync::atomic::{AtomicUsize, Ordering};
/// A memory reservation within a [`MemoryPool`] that is freed on drop
pub trait MemoryReservation: Debug + Send + Sync {
diff --git a/arrow-buffer/src/util/bit_mask.rs
b/arrow-buffer/src/util/bit_mask.rs
index 6030cb4b1b..a8ae1a7654 100644
--- a/arrow-buffer/src/util/bit_mask.rs
+++ b/arrow-buffer/src/util/bit_mask.rs
@@ -132,10 +132,8 @@ unsafe fn set_upto_64bits(
unsafe fn read_bytes_to_u64(data: &[u8], offset: usize, count: usize) -> u64 {
debug_assert!(count <= 8);
let mut tmp: u64 = 0;
- let src = data.as_ptr().add(offset);
- unsafe {
- std::ptr::copy_nonoverlapping(src, &mut tmp as *mut _ as *mut u8,
count);
- }
+ let src = unsafe { data.as_ptr().add(offset) };
+ unsafe { std::ptr::copy_nonoverlapping(src, &mut tmp as *mut _ as *mut u8,
count) };
tmp
}
@@ -143,8 +141,8 @@ unsafe fn read_bytes_to_u64(data: &[u8], offset: usize,
count: usize) -> u64 {
/// The caller must ensure `data` has `offset..(offset + 8)` range
#[inline]
unsafe fn write_u64_bytes(data: &mut [u8], offset: usize, chunk: u64) {
- let ptr = data.as_mut_ptr().add(offset) as *mut u64;
- ptr.write_unaligned(chunk);
+ let ptr = unsafe { data.as_mut_ptr().add(offset) } as *mut u64;
+ unsafe { ptr.write_unaligned(chunk) };
}
/// Similar to `write_u64_bytes`, but this method ORs the offset addressed
`data` and `chunk`
@@ -154,9 +152,9 @@ unsafe fn write_u64_bytes(data: &mut [u8], offset: usize,
chunk: u64) {
/// The caller must ensure `data` has `offset..(offset + 8)` range
#[inline]
unsafe fn or_write_u64_bytes(data: &mut [u8], offset: usize, chunk: u64) {
- let ptr = data.as_mut_ptr().add(offset);
- let chunk = chunk | (*ptr) as u64;
- (ptr as *mut u64).write_unaligned(chunk);
+ let ptr = unsafe { data.as_mut_ptr().add(offset) };
+ let chunk = chunk | (unsafe { *ptr }) as u64;
+ unsafe { (ptr as *mut u64).write_unaligned(chunk) };
}
#[cfg(test)]
diff --git a/arrow-buffer/src/util/bit_util.rs
b/arrow-buffer/src/util/bit_util.rs
index c297321bdc..f00a33aca9 100644
--- a/arrow-buffer/src/util/bit_util.rs
+++ b/arrow-buffer/src/util/bit_util.rs
@@ -47,7 +47,7 @@ pub fn get_bit(data: &[u8], i: usize) -> bool {
/// responsible to guarantee that `i` is within bounds.
#[inline]
pub unsafe fn get_bit_raw(data: *const u8, i: usize) -> bool {
- (*data.add(i / 8) & (1 << (i % 8))) != 0
+ unsafe { (*data.add(i / 8) & (1 << (i % 8))) != 0 }
}
/// Sets bit at position `i` for `data` to 1
@@ -64,7 +64,9 @@ pub fn set_bit(data: &mut [u8], i: usize) {
/// responsible to guarantee that `i` is within bounds.
#[inline]
pub unsafe fn set_bit_raw(data: *mut u8, i: usize) {
- *data.add(i / 8) |= 1 << (i % 8);
+ unsafe {
+ *data.add(i / 8) |= 1 << (i % 8);
+ }
}
/// Sets bit at position `i` for `data` to 0
@@ -81,7 +83,9 @@ pub fn unset_bit(data: &mut [u8], i: usize) {
/// responsible to guarantee that `i` is within bounds.
#[inline]
pub unsafe fn unset_bit_raw(data: *mut u8, i: usize) {
- *data.add(i / 8) &= !(1 << (i % 8));
+ unsafe {
+ *data.add(i / 8) &= !(1 << (i % 8));
+ }
}
/// Returns the ceil of `value`/`divisor`