Skip to content

Commit d6dbca3

Browse files
y86-devojeda
authored andcommitted
rust: sync: change error type of constructor functions
Change the error type of the constructors of `Arc` and `UniqueArc` to be `AllocError` instead of `Error`. This makes the API more clear as to what can go wrong when calling `try_new` or its variants. Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 70a21e5 commit d6dbca3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

rust/kernel/sync/arc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
1818
use crate::{
1919
bindings,
20-
error::Result,
2120
types::{ForeignOwnable, Opaque},
2221
};
2322
use alloc::boxed::Box;
2423
use core::{
24+
alloc::AllocError,
2525
fmt,
2626
marker::{PhantomData, Unsize},
2727
mem::{ManuallyDrop, MaybeUninit},
@@ -152,7 +152,7 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
152152

153153
impl<T> Arc<T> {
154154
/// Constructs a new reference counted instance of `T`.
155-
pub fn try_new(contents: T) -> Result<Self> {
155+
pub fn try_new(contents: T) -> Result<Self, AllocError> {
156156
// INVARIANT: The refcount is initialised to a non-zero value.
157157
let value = ArcInner {
158158
// SAFETY: There are no safety requirements for this FFI call.
@@ -472,15 +472,15 @@ pub struct UniqueArc<T: ?Sized> {
472472

473473
impl<T> UniqueArc<T> {
474474
/// Tries to allocate a new [`UniqueArc`] instance.
475-
pub fn try_new(value: T) -> Result<Self> {
475+
pub fn try_new(value: T) -> Result<Self, AllocError> {
476476
Ok(Self {
477477
// INVARIANT: The newly-created object has a ref-count of 1.
478478
inner: Arc::try_new(value)?,
479479
})
480480
}
481481

482482
/// Tries to allocate a new [`UniqueArc`] instance whose contents are not initialised yet.
483-
pub fn try_new_uninit() -> Result<UniqueArc<MaybeUninit<T>>> {
483+
pub fn try_new_uninit() -> Result<UniqueArc<MaybeUninit<T>>, AllocError> {
484484
Ok(UniqueArc::<MaybeUninit<T>> {
485485
// INVARIANT: The newly-created object has a ref-count of 1.
486486
inner: Arc::try_new(MaybeUninit::uninit())?,

0 commit comments

Comments
 (0)