Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [Medium] The `register!` macro fails to compile when using the deprecated `+` 
syntax for relative register aliases.
--

--- Patch [6]: [PATCH 6/8] rust: io: register: use new relative base syntax in 
doc and examples ---
commit ad4a7f900a81289c91c14aec0581812ddbb526e4
Author: Alexandre Courbot <[email protected]>

rust: io: register: use new relative base syntax in doc and examples

This commit (along with earlier patches in the series) converts the
documentation and examples to use the new Base: syntax to specify
relative registers bases. It also updates the macro's internal rules
to support this new syntax while keeping temporary support for the
old syntax.

> diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
> index 80e638a892d74..eeb7f859f8b9d 100644
> --- a/rust/kernel/io/register.rs
> +++ b/rust/kernel/io/register.rs
> @@ -801,6 +801,26 @@ fn into_io_op(self) -> (FixedRegisterLoc<T>, T) {
>  /// ```
>  #[macro_export]
>  macro_rules! register {
> +    // Deprecated `+` syntax for relative registers and their aliases.
> +    (
> +        $(
> +            $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty)
> +                $([ $size:expr $(, stride = $stride:expr)? ])?
> +                $(@ $($base:ident +)? $offset:literal)?
> +                $(=> $alias:ident $(+ $alias_offset:ty)? 
> $([$alias_idx:expr])? )?
> +            { $($fields:tt)* }
> +        )*
> +    ) => {
> +        $(
> +        $crate::register!(
> +            @reg $(#[$attr])* $vis $name ($storage) $([$size $(, stride = 
> $stride)?])?
> +                $(@ $($base :)? $offset)?
> +                $(=> $alias $(: $alias_offset)? $([$alias_idx])? )?
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[Severity: Medium]
Could this cause a regression where the macro fails to compile when using the
deprecated + syntax for relative register aliases?

In the deprecated branch above, $alias_offset is matched as a :ty fragment.
It is then forwarded here to an internal @reg rule:

[ ... ]

>      // Creates an alias register of relative offset register `alias` with 
> its own fields.
>      (
> -        @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => 
> $base:ident + $alias:ident
> +        @reg $(#[$attr:meta])* $vis:vis $name:ident ($storage:ty) => 
> $base:path : $alias:path
>              { $($fields:tt)* }
>      ) => {

However, this internal @reg rule expects a :path fragment. Rust macros do
not allow an abstract syntax tree node parsed as a ty fragment to match a
path specifier, which will result in a "no rules expected the token"
compilation error.

Since it was intended that the old form continues to be accepted temporarily,
continuous integration might miss this conditional compilation error if no
dependent driver using the old syntax is built in standard configs. Could
$alias_offset be matched as a :path or :ident instead of :ty in the
deprecated branch to avoid this?

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=6

Reply via email to