Skip to content

Commit 7931375

Browse files
authored
Rust Edition 2024 (#9)
1 parent 342129c commit 7931375

File tree

7 files changed

+54
-50
lines changed

7 files changed

+54
-50
lines changed

.rustfmt.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
style_edition = "2024"
12
use_small_heuristics = "Max"
3+
use_field_init_shorthand = true
4+
reorder_modules = true

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ name = "oxc_index"
33
version = "2.0.0"
44
publish = true
55
authors = ["Boshen <[email protected]>"]
6-
edition = "2021"
6+
edition = "2024"
77
description = "Newtype-style helpers for `Vec` and `usize`."
88
keywords = ["newtype", "vec", "index", "indexed", "usize"]
99
categories = ["data-structures", "no-std", "rust-patterns"]
1010
readme = "README.md"
1111
license = "MIT"
1212
repository = "https://github.com/oxc-project/oxc-index-vec"
13-
rust-version = "1.76"
13+
rust-version = "1.85.0"
1414
include = ["/src"]
1515

1616
# <https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html>
@@ -44,8 +44,8 @@ rc_buffer = "warn"
4444
rc_mutex = "warn"
4545
rest_pat_in_fully_bound_structs = "warn"
4646
unnecessary_safety_comment = "warn"
47-
undocumented_unsafe_blocks = "warn"
4847
infinite_loop = "warn"
48+
undocumented_unsafe_blocks = "allow"
4949

5050
[lib]
5151
doctest = false

src/idxslice.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ impl<I: Idx, T> IndexSlice<I, [T]> {
9797
/// The resulting vector can be converted back into a box via
9898
/// `IndexVec<I, T>`'s `into_boxed_slice` method.
9999
#[inline]
100-
#[allow(clippy::wrong_self_convention)]
101100
pub fn into_vec(self: Box<Self>) -> IndexVec<I, T> {
102101
// SAFETY: Both the `IndexSlice` and the `IndexVec` are
103102
// thin wrappers around `[T]` and `Vec<T>` with the added marker for the index.
@@ -610,7 +609,7 @@ impl<I: Idx, T> IndexSlice<I, [T]> {
610609
/// safety caveats.
611610
#[inline]
612611
pub unsafe fn from_raw_parts<'a>(data: *const T, len: usize) -> &'a Self {
613-
Self::new(slice::from_raw_parts(data, len))
612+
unsafe { Self::new(slice::from_raw_parts(data, len)) }
614613
}
615614

616615
/// Create a mutable IdxSlice from its pointer and length.
@@ -621,7 +620,7 @@ impl<I: Idx, T> IndexSlice<I, [T]> {
621620
/// safety caveats.
622621
#[inline]
623622
pub unsafe fn from_raw_parts_mut<'a>(data: *mut T, len: usize) -> &'a mut Self {
624-
Self::new_mut(slice::from_raw_parts_mut(data, len))
623+
unsafe { Self::new_mut(slice::from_raw_parts_mut(data, len)) }
625624
}
626625

627626
/// Returns the first and all the rest of the elements of the slice, or `None` if it is empty.

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ impl_partialeq2! { IndexSlice<I, [A]>, &'a IndexSlice<J, [B]> }
744744
impl_partialeq2! { IndexSlice<I, [A]>, &'a mut IndexSlice<J, [B]> }
745745

746746
macro_rules! array_impls {
747-
($($N: expr)+) => {$(
747+
($($N: expr_2021)+) => {$(
748748
impl_partialeq! { IndexVec<I, A>, [B; $N] }
749749
impl_partialeq! { IndexVec<I, A>, &'b [B; $N] }
750750
impl_partialeq! { IndexSlice<I, [A]>, [B; $N] }
@@ -797,7 +797,7 @@ impl<'de, I: Idx, T: serde::de::Deserialize<'de>> serde::de::Deserialize<'de> fo
797797
}
798798

799799
#[cfg(test)]
800-
#[allow(clippy::legacy_numeric_constants)]
800+
#[expect(clippy::legacy_numeric_constants)]
801801
mod test {
802802
use super::*;
803803

src/macros.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ macro_rules! define_index_type {
158158
(
159159
$(#[$attrs:meta])*
160160
$v:vis struct $type:ident = $raw:ident;
161-
$($CONFIG_NAME:ident = $value:expr;)* $(;)?
161+
$($CONFIG_NAME:ident = $value:expr_2021;)* $(;)?
162162
) => {
163163
$crate::__define_index_type_inner!{
164164
@configs [$(($CONFIG_NAME; $value))*]
@@ -214,13 +214,13 @@ macro_rules! __internal_maybe_index_impl_serde {
214214
macro_rules! __define_index_type_inner {
215215
// DISABLE_MAX_INDEX_CHECK
216216
(
217-
@configs [(DISABLE_MAX_INDEX_CHECK; $no_check_max:expr) $(($CONFIG_NAME:ident; $value:expr))*]
217+
@configs [(DISABLE_MAX_INDEX_CHECK; $no_check_max:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
218218
@attrs [$(#[$attrs:meta])*]
219219
@derives [$(#[$derive:meta])*]
220220
@decl [$v:vis struct $type:ident ($raw:ident)]
221-
@debug_fmt [$dbg:expr]
222-
@max [$max:expr]
223-
@no_check_max [$_old_no_check_max:expr]
221+
@debug_fmt [$dbg:expr_2021]
222+
@max [$max:expr_2021]
223+
@no_check_max [$_old_no_check_max:expr_2021]
224224
) => {
225225
$crate::__define_index_type_inner!{
226226
@configs [$(($CONFIG_NAME; $value))*]
@@ -235,13 +235,13 @@ macro_rules! __define_index_type_inner {
235235

236236
// MAX_INDEX
237237
(
238-
@configs [(MAX_INDEX; $new_max:expr) $(($CONFIG_NAME:ident; $value:expr))*]
238+
@configs [(MAX_INDEX; $new_max:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
239239
@attrs [$(#[$attrs:meta])*]
240240
@derives [$(#[$derive:meta])*]
241241
@decl [$v:vis struct $type:ident ($raw:ident)]
242-
@debug_fmt [$dbg:expr]
243-
@max [$max:expr]
244-
@no_check_max [$cm:expr]
242+
@debug_fmt [$dbg:expr_2021]
243+
@max [$max:expr_2021]
244+
@no_check_max [$cm:expr_2021]
245245
) => {
246246
$crate::__define_index_type_inner!{
247247
@configs [$(($CONFIG_NAME; $value))*]
@@ -256,13 +256,13 @@ macro_rules! __define_index_type_inner {
256256

257257
// DEFAULT
258258
(
259-
@configs [(DEFAULT; $default_expr:expr) $(($CONFIG_NAME:ident; $value:expr))*]
259+
@configs [(DEFAULT; $default_expr:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
260260
@attrs [$(#[$attrs:meta])*]
261261
@derives [$(#[$derive:meta])*]
262262
@decl [$v:vis struct $type:ident ($raw:ident)]
263-
@debug_fmt [$dbg:expr]
264-
@max [$max:expr]
265-
@no_check_max [$no_check_max:expr]
263+
@debug_fmt [$dbg:expr_2021]
264+
@max [$max:expr_2021]
265+
@no_check_max [$no_check_max:expr_2021]
266266
) => {
267267
$crate::__define_index_type_inner!{
268268
@configs [$(($CONFIG_NAME; $value))*]
@@ -283,13 +283,13 @@ macro_rules! __define_index_type_inner {
283283

284284
// DEBUG_FORMAT
285285
(
286-
@configs [(DEBUG_FORMAT; $dbg:expr) $(($CONFIG_NAME:ident; $value:expr))*]
286+
@configs [(DEBUG_FORMAT; $dbg:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
287287
@attrs [$(#[$attrs:meta])*]
288288
@derives [$(#[$derive:meta])*]
289289
@decl [$v:vis struct $type:ident ($raw:ident)]
290-
@debug_fmt [$old_dbg:expr]
291-
@max [$max:expr]
292-
@no_check_max [$no_check_max:expr]
290+
@debug_fmt [$old_dbg:expr_2021]
291+
@max [$max:expr_2021]
292+
@no_check_max [$no_check_max:expr_2021]
293293
) => {
294294
$crate::__define_index_type_inner!{
295295
@configs [$(($CONFIG_NAME; $value))*]
@@ -304,13 +304,13 @@ macro_rules! __define_index_type_inner {
304304

305305
// DISPLAY_FORMAT
306306
(
307-
@configs [(DISPLAY_FORMAT; $format:expr) $(($CONFIG_NAME:ident; $value:expr))*]
307+
@configs [(DISPLAY_FORMAT; $format:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
308308
@attrs [$(#[$attrs:meta])*]
309309
@derives [$(#[$derive:meta])*]
310310
@decl [$v:vis struct $type:ident ($raw:ident)]
311-
@debug_fmt [$dbg:expr]
312-
@max [$max:expr]
313-
@no_check_max [$no_check_max:expr]
311+
@debug_fmt [$dbg:expr_2021]
312+
@max [$max:expr_2021]
313+
@no_check_max [$no_check_max:expr_2021]
314314
) => {
315315
$crate::__define_index_type_inner!{
316316
@configs [$(($CONFIG_NAME; $value))*]
@@ -331,13 +331,13 @@ macro_rules! __define_index_type_inner {
331331

332332
// IMPL_RAW_CONVERSIONS
333333
(
334-
@configs [(IMPL_RAW_CONVERSIONS; $val:expr) $(($CONFIG_NAME:ident; $value:expr))*]
334+
@configs [(IMPL_RAW_CONVERSIONS; $val:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
335335
@attrs [$(#[$attrs:meta])*]
336336
@derives [$(#[$derive:meta])*]
337337
@decl [$v:vis struct $type:ident ($raw:ident)]
338-
@debug_fmt [$dbg:expr]
339-
@max [$max:expr]
340-
@no_check_max [$no_check_max:expr]
338+
@debug_fmt [$dbg:expr_2021]
339+
@max [$max:expr_2021]
340+
@no_check_max [$no_check_max:expr_2021]
341341
) => {
342342
$crate::__define_index_type_inner!{
343343
@configs [$(($CONFIG_NAME; $value))*]
@@ -367,13 +367,13 @@ macro_rules! __define_index_type_inner {
367367
};
368368
// Try to make rust emit a decent error message...
369369
(
370-
@configs [($other:ident; $format:expr) $(($CONFIG_NAME:ident; $value:expr))*]
370+
@configs [($other:ident; $format:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
371371
@attrs [$(#[$attrs:meta])*]
372372
@derives [$(#[$derive:meta])*]
373373
@decl [$v:vis struct $type:ident ($raw:ident)]
374-
@debug_fmt [$dbg:expr]
375-
@max [$max:expr]
376-
@no_check_max [$no_check_max:expr]
374+
@debug_fmt [$dbg:expr_2021]
375+
@max [$max:expr_2021]
376+
@no_check_max [$no_check_max:expr_2021]
377377
) => {
378378
$crate::unknown_define_index_type_option!($other);
379379
};
@@ -383,9 +383,9 @@ macro_rules! __define_index_type_inner {
383383
@attrs [$(#[$attrs:meta])*]
384384
@derives [$(#[$derive:meta])*]
385385
@decl [$v:vis struct $type:ident ($raw:ident)]
386-
@debug_fmt [$dbg:expr]
387-
@max [$max:expr]
388-
@no_check_max [$no_check_max:expr]
386+
@debug_fmt [$dbg:expr_2021]
387+
@max [$max:expr_2021]
388+
@no_check_max [$no_check_max:expr_2021]
389389
) => {
390390

391391
$(#[$derive])*
@@ -422,7 +422,7 @@ macro_rules! __define_index_type_inner {
422422
}
423423

424424
/// Construct from a usize without any checks.
425-
#[allow(clippy::cast_possible_truncation)]
425+
#[expect(clippy::cast_possible_truncation)]
426426
#[inline(always)]
427427
$v const fn from_usize_unchecked(value: usize) -> Self {
428428
Self { _raw: value as $raw }
@@ -435,7 +435,7 @@ macro_rules! __define_index_type_inner {
435435
}
436436

437437
/// Construct this index type from a usize.
438-
#[allow(clippy::cast_possible_truncation)]
438+
#[expect(clippy::cast_possible_truncation)]
439439
#[inline]
440440
$v fn from_usize(value: usize) -> Self {
441441
Self::check_index(value as usize);

src/rayon_impl.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use core::{
1111

1212
use rayon::{
1313
iter::{
14-
plumbing::{bridge, Consumer, Producer, ProducerCallback, UnindexedConsumer},
1514
IndexedParallelIterator, IntoParallelIterator, ParallelDrainRange, ParallelIterator,
15+
plumbing::{Consumer, Producer, ProducerCallback, UnindexedConsumer, bridge},
1616
},
1717
slice::{Iter, IterMut},
1818
};
@@ -191,13 +191,15 @@ impl<T: Send> DrainProducer<'_, T> {
191191
/// Unsafe because we're moving from beyond `vec.len()`, so the caller must ensure
192192
/// that data is initialized and not read after the borrow is released.
193193
unsafe fn from_vec(vec: &mut Vec<T>, len: usize) -> DrainProducer<'_, T> {
194-
let start = vec.len();
195-
assert!(vec.capacity() - start >= len);
194+
unsafe {
195+
let start = vec.len();
196+
assert!(vec.capacity() - start >= len);
196197

197-
// The pointer is derived from `Vec` directly, not through a `Deref`,
198-
// so it has provenance over the whole allocation.
199-
let ptr = vec.as_mut_ptr().add(start);
200-
DrainProducer::new(slice::from_raw_parts_mut(ptr, len))
198+
// The pointer is derived from `Vec` directly, not through a `Deref`,
199+
// so it has provenance over the whole allocation.
200+
let ptr = vec.as_mut_ptr().add(start);
201+
DrainProducer::new(slice::from_raw_parts_mut(ptr, len))
202+
}
201203
}
202204
}
203205

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
clippy::cast_possible_truncation
77
)]
88

9-
use oxc_index::{index_vec, IndexSlice, IndexVec};
9+
use oxc_index::{IndexSlice, IndexVec, index_vec};
1010

1111
oxc_index::define_index_type! {
1212
pub struct USize16 = usize;

0 commit comments

Comments
 (0)