Skip to content

Commit 7fe950a

Browse files
committed
rust: init: use #[default_error(err)] for the initializer macros
Initializer macros should use this attribute instead of manually parsing the macro's input. This is because the syntax is now parsed using `syn`, which permits more complex constructs to be parsed. In addition, this ensures that the kernel's initializer marcos will have the exact same syntax as the ones from pin-init. Signed-off-by: Benno Lossin <lossin@kernel.org>
1 parent 65f8901 commit 7fe950a

1 file changed

Lines changed: 12 additions & 28 deletions

File tree

rust/kernel/init.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,12 @@ pub trait InPlaceInit<T>: Sized {
219219
/// [`Error`]: crate::error::Error
220220
#[macro_export]
221221
macro_rules! try_init {
222-
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
223-
$($fields:tt)*
224-
}) => {
225-
::pin_init::init!($(&$this in)? $t $(::<$($generics),*>)? {
226-
$($fields)*
227-
}? $crate::error::Error)
228-
};
229-
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
230-
$($fields:tt)*
231-
}? $err:ty) => {
232-
::pin_init::init!($(&$this in)? $t $(::<$($generics),*>)? {
233-
$($fields)*
234-
}? $err)
235-
};
222+
($($args:tt)*) => {
223+
::pin_init::init!(
224+
#[default_error($crate::error::Error)]
225+
$($args)*
226+
)
227+
}
236228
}
237229

238230
/// Construct an in-place, fallible pinned initializer for `struct`s.
@@ -279,18 +271,10 @@ macro_rules! try_init {
279271
/// [`Error`]: crate::error::Error
280272
#[macro_export]
281273
macro_rules! try_pin_init {
282-
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
283-
$($fields:tt)*
284-
}) => {
285-
::pin_init::pin_init!($(&$this in)? $t $(::<$($generics),*>)? {
286-
$($fields)*
287-
}? $crate::error::Error)
288-
};
289-
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
290-
$($fields:tt)*
291-
}? $err:ty) => {
292-
::pin_init::pin_init!($(&$this in)? $t $(::<$($generics),*>)? {
293-
$($fields)*
294-
}? $err)
295-
};
274+
($($args:tt)*) => {
275+
::pin_init::pin_init!(
276+
#[default_error($crate::error::Error)]
277+
$($args)*
278+
)
279+
}
296280
}

0 commit comments

Comments
 (0)