mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
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. Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Benno Lossin <lossin@kernel.org>
This commit is contained in:
@@ -219,20 +219,12 @@ pub trait InPlaceInit<T>: Sized {
|
||||
/// [`Error`]: crate::error::Error
|
||||
#[macro_export]
|
||||
macro_rules! try_init {
|
||||
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
||||
$($fields:tt)*
|
||||
}) => {
|
||||
::pin_init::init!($(&$this in)? $t $(::<$($generics),*>)? {
|
||||
$($fields)*
|
||||
}? $crate::error::Error)
|
||||
};
|
||||
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
||||
$($fields:tt)*
|
||||
}? $err:ty) => {
|
||||
::pin_init::init!($(&$this in)? $t $(::<$($generics),*>)? {
|
||||
$($fields)*
|
||||
}? $err)
|
||||
};
|
||||
($($args:tt)*) => {
|
||||
::pin_init::init!(
|
||||
#[default_error($crate::error::Error)]
|
||||
$($args)*
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct an in-place, fallible pinned initializer for `struct`s.
|
||||
@@ -279,18 +271,10 @@ macro_rules! try_init {
|
||||
/// [`Error`]: crate::error::Error
|
||||
#[macro_export]
|
||||
macro_rules! try_pin_init {
|
||||
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
||||
$($fields:tt)*
|
||||
}) => {
|
||||
::pin_init::pin_init!($(&$this in)? $t $(::<$($generics),*>)? {
|
||||
$($fields)*
|
||||
}? $crate::error::Error)
|
||||
};
|
||||
($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
|
||||
$($fields:tt)*
|
||||
}? $err:ty) => {
|
||||
::pin_init::pin_init!($(&$this in)? $t $(::<$($generics),*>)? {
|
||||
$($fields)*
|
||||
}? $err)
|
||||
};
|
||||
($($args:tt)*) => {
|
||||
::pin_init::pin_init!(
|
||||
#[default_error($crate::error::Error)]
|
||||
$($args)*
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user