Skip to content

Commit b9b379f

Browse files
wedsonafojeda
authored andcommitted
rust: kernel: remove usage of allocator_api unstable feature
With the adoption of `BoxExt` and `VecExt`, we don't need the functions provided by this feature (namely the methods prefixed with `try_` and different allocator per collection instance). We do need `AllocError`, but we define our own as it is a trivial empty struct. Reviewed-by: Benno Lossin <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent eb5a830 commit b9b379f

File tree

9 files changed

+14
-15
lines changed

9 files changed

+14
-15
lines changed

rust/kernel/alloc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ mod allocator;
88
pub mod box_ext;
99
pub mod vec_ext;
1010

11+
/// Indicates an allocation error.
12+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
13+
pub struct AllocError;
14+
1115
/// Flags to be used when allocating memory.
1216
///
1317
/// They can be combined with the operators `|`, `&`, and `!`.

rust/kernel/alloc/box_ext.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
//! Extensions to [`Box`] for fallible allocations.
44
5-
use super::Flags;
5+
use super::{AllocError, Flags};
66
use alloc::boxed::Box;
7-
use core::alloc::AllocError;
87
use core::mem::MaybeUninit;
98
use core::result::Result;
109

rust/kernel/alloc/vec_ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
//! Extensions to [`Vec`] for fallible allocations.
44
5-
use super::Flags;
6-
use alloc::{alloc::AllocError, vec::Vec};
5+
use super::{AllocError, Flags};
6+
use alloc::vec::Vec;
77
use core::result::Result;
88

99
/// Extensions to [`Vec`].

rust/kernel/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
//!
55
//! C header: [`include/uapi/asm-generic/errno-base.h`](srctree/include/uapi/asm-generic/errno-base.h)
66
7-
use crate::str::CStr;
7+
use crate::{alloc::AllocError, str::CStr};
88

9-
use alloc::alloc::{AllocError, LayoutError};
9+
use alloc::alloc::LayoutError;
1010

1111
use core::convert::From;
1212
use core::fmt;

rust/kernel/init.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,13 @@
211211
//! [`pin_init!`]: crate::pin_init!
212212
213213
use crate::{
214-
alloc::{box_ext::BoxExt, Flags},
214+
alloc::{box_ext::BoxExt, AllocError, Flags},
215215
error::{self, Error},
216216
sync::UniqueArc,
217217
types::{Opaque, ScopeGuard},
218218
};
219219
use alloc::boxed::Box;
220220
use core::{
221-
alloc::AllocError,
222221
cell::UnsafeCell,
223222
convert::Infallible,
224223
marker::PhantomData,

rust/kernel/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! do so first instead of bypassing this crate.
1313
1414
#![no_std]
15-
#![feature(allocator_api)]
1615
#![feature(coerce_unsized)]
1716
#![feature(dispatch_from_dyn)]
1817
#![feature(new_uninit)]

rust/kernel/str.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
//! String representations.
44
5-
use crate::alloc::{flags::*, vec_ext::VecExt};
6-
use alloc::alloc::AllocError;
5+
use crate::alloc::{flags::*, vec_ext::VecExt, AllocError};
76
use alloc::vec::Vec;
87
use core::fmt::{self, Write};
98
use core::ops::{self, Deref, DerefMut, Index};

rust/kernel/sync/arc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
1717
1818
use crate::{
19-
alloc::{box_ext::BoxExt, Flags},
19+
alloc::{box_ext::BoxExt, AllocError, Flags},
2020
bindings,
2121
error::{self, Error},
2222
init::{self, InPlaceInit, Init, PinInit},
@@ -25,7 +25,7 @@ use crate::{
2525
};
2626
use alloc::boxed::Box;
2727
use core::{
28-
alloc::{AllocError, Layout},
28+
alloc::Layout,
2929
fmt,
3030
marker::{PhantomData, Unsize},
3131
mem::{ManuallyDrop, MaybeUninit},

rust/kernel/workqueue.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@
132132
//!
133133
//! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)
134134
135-
use crate::alloc::Flags;
135+
use crate::alloc::{AllocError, Flags};
136136
use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
137-
use alloc::alloc::AllocError;
138137
use alloc::boxed::Box;
139138
use core::marker::PhantomData;
140139
use core::pin::Pin;

0 commit comments

Comments
 (0)