Re: [PATCH 07/22] rust: pin-init: move the default error behavior of `try_[pin_]init`

From: Benno Lossin
Date: Wed Mar 05 2025 - 05:51:20 EST


On Wed Mar 5, 2025 at 11:29 AM CET, Andreas Hindborg wrote:
> "Benno Lossin" <benno.lossin@xxxxxxxxx> writes:
>
>> Move the ability to just write `try_pin_init!(Foo { a <- a_init })`
>> (note the missing `? Error` at the end) into the kernel crate.
>> Remove this notation from the pin-init crate, since the default when no
>> error is specified is the kernel-internal `Error` type. Instead add two
>> macros in the kernel crate that serve this default and are used instead
>> of the ones from `pin-init`.
>>
>> This is done, because the `Error` type that is used as the default is
>> from the kernel crate and it thus prevents making the pin-init crate
>> standalone.
>>
>> In order to not cause a build error due to a name overlap, the macros in
>> the pin-init crate are renamed, but this change is reverted in a future
>> commit when it is a standalone crate.
>>
>> Signed-off-by: Benno Lossin <benno.lossin@xxxxxxxxx>
>
> [...]
>
>> diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs
>> index dde2e0649790..4123d478c351 100644
>> --- a/rust/kernel/prelude.rs
>> +++ b/rust/kernel/prelude.rs
>> @@ -28,7 +28,8 @@
>> pub use super::{dev_alert, dev_crit, dev_dbg, dev_emerg, dev_err, dev_info, dev_notice, dev_warn};
>> pub use super::{pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr_notice, pr_warn};
>>
>> -pub use super::{init, pin_init, try_init, try_pin_init};
>> +pub use super::{init, pin_init};
>> +pub use super::{try_init, try_pin_init};
>
> Are you trying out a new scheme here - a balance between normalized and
> line-by-line use declarations? 😆

Uh no, not intentionally at least. This is an artifact of moving the
changes between the different patches, the "rust: make pin-init its own
crate" commit removes the line with `init` and `pin_init`, but keeps the
one with the `try_` versions. That is because those two will continue to
live in the `kernel` crate.

---
Cheers,
Benno