On 3/26/26 22:40, Gary Guo wrote:
On Thu Mar 26, 2026 at 6:52 AM GMT, Alvin Sun wrote:
Fixes clippy warning:
warning: all variants have the same postfix: `Init`
--> rust/kernel/sync/set_once.rs:68:1
I am not sure that this makes the code look nicer :/
AlreadyInit is very clear on what's wrong, which `InitError::Already` is weird.
Perhaps just allow this warning.
Got it, that makes more sense. I was actually a bit confused by this clippy
warning when I first saw it too, wasn't sure whether to just follow it
or not.
Now I know what to do - I'll drop this patch and allow the warning directly.
Best regards,
Alvin
Best,
Gary
Signed-off-by: Alvin Sun <[email protected]>
---
rust/kernel/sync/set_once.rs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/rust/kernel/sync/set_once.rs b/rust/kernel/sync/set_once.rs
index db9c5423fade3..3af5538aae1d4 100644
--- a/rust/kernel/sync/set_once.rs
+++ b/rust/kernel/sync/set_once.rs
@@ -67,17 +67,17 @@ fn default() -> Self {
#[derive(Debug)]
pub enum InitError<E> {
/// The `Once` has already been initialized.
- AlreadyInit,
+ Already,
/// The `Once` is being raced to initialize by another thread.
- RacedInit,
+ Raced,
/// Error occurs during initialization.
- DuringInit(E),
+ Inner(E),
}
impl<E> From<E> for InitError<E> {
#[inline]
fn from(err: E) -> Self {
- InitError::DuringInit(err)
+ InitError::Inner(err)
}
}
@@ -85,9 +85,9 @@ impl<E: Into<Error>> From<InitError<E>> for Error {
#[inline]
fn from(this: InitError<E>) -> Self {
match this {
- InitError::AlreadyInit => EEXIST,
- InitError::RacedInit => EBUSY,
- InitError::DuringInit(e) => e.into(),
+ InitError::Already => EEXIST,
+ InitError::Raced => EBUSY,
+ InitError::Inner(e) => e.into(),
}
}
}
@@ -155,8 +155,8 @@ pub fn init<E>(&self, init: impl Init<T, E>) -> Result<&T,
InitError<E>> {
}
}
}
- Err(1) => Err(InitError::RacedInit),
- Err(_) => Err(InitError::AlreadyInit),
+ Err(1) => Err(InitError::Raced),
+ Err(_) => Err(InitError::Already),
}
}