On Wed Aug 19, 2026 at 8:09 PM JST, Gary Guo wrote:
> Currently registers work for all untyped I/O regions, which is not ideal.
> It allows registers defined for device A to work for another device B and
> there is no safeguarding at all.
>
> All users of the `register!` macro know what type it will be operating on,
> and that type is consistent across the driver. Therefore, add a `base`
> parameter to `register!`.
>
> Currently this parameter is unused in the generated code; it will be used
> when all users of `register!` is converted to gain the parameter.
>
> Signed-off-by: Gary Guo <[email protected]>

While trying to confirm Sashiko's doctest warning I stumbled upon this warning:

    warning: field `base` is never read
      --> ../rust/macros/io/register.rs:143:5
        |
    142 | pub(crate) struct RegDef {
        |                   ------ field in this struct
    143 |     base: Option<Type>,
        |     ^^^^
        |
        = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

... and a few rustdoc ones (introduced before this patch I believe):

    warning: unresolved link to `transmutable`
      --> rust/kernel/mem.rs:83:25
      |
    83 | /// - [`Self`] must be [transmutable] from [`Self::Repr`].
      |                         ^^^^^^^^^^^^ no item named `transmutable` in 
scope
      |
      = help: to escape `[` and `]` characters, add '\' before them like `\[` 
or `\]`
      = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

    warning: unresolved link to `Self::Repr`
      --> rust/kernel/mem.rs:83:46
      |
    83 | /// - [`Self`] must be [transmutable] from [`Self::Repr`].
      |                                              ^^^^^^^^^^ the trait 
`AsReprMut` has no associated item named `Repr`

    warning: unresolved link to `Self::Repr`
      --> rust/kernel/mem.rs:84:19
      |
    84 | /// - Note that [`Self::Repr`] must be [transmutable] from `Self` as 
well, however that is a
      |                   ^^^^^^^^^^ the trait `AsReprMut` has no associated 
item named `Repr`

    warning: unresolved link to `transmutable`
      --> rust/kernel/mem.rs:84:41
      |
    84 | /// - Note that [`Self::Repr`] must be [transmutable] from `Self` as 
well, however that is a
      |                                         ^^^^^^^^^^^^ no item named 
`transmutable` in scope
      |
      = help: to escape `[` and `]` characters, add '\' before them like `\[` 
or `\]`

    warning: 4 warnings emitted

<...>
> diff --git a/rust/macros/io/register.rs b/rust/macros/io/register.rs
> index 8af12caa964b..2fb48e1be82d 100644
> --- a/rust/macros/io/register.rs
> +++ b/rust/macros/io/register.rs
> @@ -27,6 +27,7 @@
>  };
>  
>  mod kw {
> +    syn::custom_keyword!(base);
>      syn::custom_keyword!(stride);
>  }
>  
> @@ -139,16 +140,26 @@ fn parse(input: syn::parse::ParseStream<'_>) -> 
> Result<Self> {
>  }
>  
>  pub(crate) struct RegDef {
> +    base: Option<Type>,
>      regs: Vec<Reg>,
>  }
>  
>  impl Parse for RegDef {
>      fn parse(input: syn::parse::ParseStream<'_>) -> Result<Self> {
> +        let base = if input.peek(kw::base) {

Here as well Sashiko's finding looks accurate, albeit probably not
serious. The proposed fix is cheap though.

Reply via email to