Skip to content

Commit 28cf02d

Browse files
authored
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
1 parent e5e4db9 commit 28cf02d

File tree

13 files changed

+52
-50
lines changed

13 files changed

+52
-50
lines changed

arrow-buffer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ authors = { workspace = true }
2525
license = { workspace = true }
2626
keywords = { workspace = true }
2727
include = { workspace = true }
28-
edition = { workspace = true }
28+
edition = "2024"
2929
rust-version = { workspace = true }
3030

3131
[lib]

arrow-buffer/benches/bit_mask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
use arrow_buffer::bit_mask::set_bits;
19-
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
19+
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
2020
use std::hint;
2121

2222
fn criterion_benchmark(c: &mut Criterion) {

arrow-buffer/src/bigint/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use crate::arith::derive_arith;
1919
use crate::bigint::div::div_rem;
2020
use num_bigint::BigInt;
21-
use num_traits::{cast::AsPrimitive, FromPrimitive, ToPrimitive};
21+
use num_traits::{FromPrimitive, ToPrimitive, cast::AsPrimitive};
2222
use std::cmp::Ordering;
2323
use std::num::ParseIntError;
2424
use std::ops::{BitAnd, BitOr, BitXor, Neg, Shl, Shr};
@@ -232,11 +232,7 @@ impl i256 {
232232
pub fn from_f64(v: f64) -> Option<Self> {
233233
BigInt::from_f64(v).and_then(|i| {
234234
let (integer, overflow) = i256::from_bigint_with_overflow(i);
235-
if overflow {
236-
None
237-
} else {
238-
Some(integer)
239-
}
235+
if overflow { None } else { Some(integer) }
240236
})
241237
}
242238

@@ -868,7 +864,7 @@ impl ToPrimitive for i256 {
868864
mod tests {
869865
use super::*;
870866
use num_traits::Signed;
871-
use rand::{rng, Rng};
867+
use rand::{Rng, rng};
872868

873869
#[test]
874870
fn test_signed_cmp() {

arrow-buffer/src/buffer/boolean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use crate::bit_chunk_iterator::BitChunks;
1919
use crate::bit_iterator::{BitIndexIterator, BitIndexU32Iterator, BitIterator, BitSliceIterator};
2020
use crate::{
21-
bit_util, buffer_bin_and, buffer_bin_or, buffer_bin_xor, buffer_unary_not,
22-
BooleanBufferBuilder, Buffer, MutableBuffer,
21+
BooleanBufferBuilder, Buffer, MutableBuffer, bit_util, buffer_bin_and, buffer_bin_or,
22+
buffer_bin_xor, buffer_unary_not,
2323
};
2424

2525
use std::ops::{BitAnd, BitOr, BitXor, Not};

arrow-buffer/src/buffer/immutable.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use std::fmt::Debug;
2020
use std::ptr::NonNull;
2121
use std::sync::Arc;
2222

23+
use crate::BufferBuilder;
2324
use crate::alloc::{Allocation, Deallocation};
2425
use crate::util::bit_chunk_iterator::{BitChunks, UnalignedBitChunk};
25-
use crate::BufferBuilder;
2626
use crate::{bit_util, bytes::Bytes, native::ArrowNativeType};
2727

2828
#[cfg(feature = "pool")]
@@ -172,7 +172,7 @@ impl Buffer {
172172
len: usize,
173173
owner: Arc<dyn Allocation>,
174174
) -> Self {
175-
Buffer::build_with_arguments(ptr, len, Deallocation::Custom(owner, len))
175+
unsafe { Buffer::build_with_arguments(ptr, len, Deallocation::Custom(owner, len)) }
176176
}
177177

178178
/// Auxiliary method to create a new Buffer
@@ -181,7 +181,7 @@ impl Buffer {
181181
len: usize,
182182
deallocation: Deallocation,
183183
) -> Self {
184-
let bytes = Bytes::new(ptr, len, deallocation);
184+
let bytes = unsafe { Bytes::new(ptr, len, deallocation) };
185185
let ptr = bytes.as_ptr();
186186
Buffer {
187187
ptr,
@@ -561,7 +561,7 @@ impl Buffer {
561561
pub unsafe fn from_trusted_len_iter<T: ArrowNativeType, I: Iterator<Item = T>>(
562562
iterator: I,
563563
) -> Self {
564-
MutableBuffer::from_trusted_len_iter(iterator).into()
564+
unsafe { MutableBuffer::from_trusted_len_iter(iterator).into() }
565565
}
566566

567567
/// Creates a [`Buffer`] from an [`Iterator`] with a trusted (upper) length or errors
@@ -578,7 +578,7 @@ impl Buffer {
578578
>(
579579
iterator: I,
580580
) -> Result<Self, E> {
581-
Ok(MutableBuffer::try_from_trusted_len_iter(iterator)?.into())
581+
unsafe { Ok(MutableBuffer::try_from_trusted_len_iter(iterator)?.into()) }
582582
}
583583
}
584584

arrow-buffer/src/buffer/mutable.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use std::alloc::{handle_alloc_error, Layout};
18+
use std::alloc::{Layout, handle_alloc_error};
1919
use std::mem;
2020
use std::ptr::NonNull;
2121

22-
use crate::alloc::{Deallocation, ALIGNMENT};
22+
use crate::alloc::{ALIGNMENT, Deallocation};
2323
use crate::{
2424
bytes::Bytes,
2525
native::{ArrowNativeType, ToByteSlice},
@@ -460,8 +460,8 @@ impl MutableBuffer {
460460
pub unsafe fn push_unchecked<T: ToByteSlice>(&mut self, item: T) {
461461
let additional = std::mem::size_of::<T>();
462462
let src = item.to_byte_slice().as_ptr();
463-
let dst = self.data.as_ptr().add(self.len);
464-
std::ptr::copy_nonoverlapping(src, dst, additional);
463+
let dst = unsafe { self.data.as_ptr().add(self.len) };
464+
unsafe { std::ptr::copy_nonoverlapping(src, dst, additional) };
465465
self.len += additional;
466466
}
467467

@@ -640,11 +640,11 @@ impl MutableBuffer {
640640
for item in iterator {
641641
// note how there is no reserve here (compared with `extend_from_iter`)
642642
let src = item.to_byte_slice().as_ptr();
643-
std::ptr::copy_nonoverlapping(src, dst, item_size);
644-
dst = dst.add(item_size);
643+
unsafe { std::ptr::copy_nonoverlapping(src, dst, item_size) };
644+
dst = unsafe { dst.add(item_size) };
645645
}
646646
assert_eq!(
647-
dst.offset_from(buffer.data.as_ptr()) as usize,
647+
unsafe { dst.offset_from(buffer.data.as_ptr()) } as usize,
648648
len,
649649
"Trusted iterator length was not accurately reported"
650650
);
@@ -703,20 +703,22 @@ impl MutableBuffer {
703703
let item = item?;
704704
// note how there is no reserve here (compared with `extend_from_iter`)
705705
let src = item.to_byte_slice().as_ptr();
706-
std::ptr::copy_nonoverlapping(src, dst, item_size);
707-
dst = dst.add(item_size);
706+
unsafe { std::ptr::copy_nonoverlapping(src, dst, item_size) };
707+
dst = unsafe { dst.add(item_size) };
708708
}
709709
// try_from_trusted_len_iter is instantiated a lot, so we extract part of it into a less
710710
// generic method to reduce compile time
711711
unsafe fn finalize_buffer(dst: *mut u8, buffer: &mut MutableBuffer, len: usize) {
712-
assert_eq!(
713-
dst.offset_from(buffer.data.as_ptr()) as usize,
714-
len,
715-
"Trusted iterator length was not accurately reported"
716-
);
717-
buffer.len = len;
712+
unsafe {
713+
assert_eq!(
714+
dst.offset_from(buffer.data.as_ptr()) as usize,
715+
len,
716+
"Trusted iterator length was not accurately reported"
717+
);
718+
buffer.len = len;
719+
}
718720
}
719-
finalize_buffer(dst, &mut buffer, len);
721+
unsafe { finalize_buffer(dst, &mut buffer, len) };
720722
Ok(buffer)
721723
}
722724
}

arrow-buffer/src/buffer/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::buffer::ScalarBuffer;
1918
use crate::ArrowNativeType;
19+
use crate::buffer::ScalarBuffer;
2020

2121
/// A slice-able buffer of monotonically increasing, positive integers used to store run-ends
2222
///

arrow-buffer/src/buffer/scalar.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ impl<T: ArrowNativeType> From<Buffer> for ScalarBuffer<T> {
162162
is_aligned,
163163
"Memory pointer is not aligned with the specified scalar type"
164164
),
165-
Deallocation::Custom(_, _) =>
166-
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."),
165+
Deallocation::Custom(_, _) => assert!(
166+
is_aligned,
167+
"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."
168+
),
167169
}
168170

169171
Self {

arrow-buffer/src/builder/boolean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::{bit_mask, bit_util, BooleanBuffer, Buffer, MutableBuffer};
18+
use crate::{BooleanBuffer, Buffer, MutableBuffer, bit_mask, bit_util};
1919
use std::ops::Range;
2020

2121
/// Builder for [`BooleanBuffer`]

arrow-buffer/src/native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::{i256, IntervalDayTime, IntervalMonthDayNano};
18+
use crate::{IntervalDayTime, IntervalMonthDayNano, i256};
1919
use half::f16;
2020

2121
mod private {

0 commit comments

Comments
 (0)