[PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros

SeungJong Ha via B4 Relay posted 1 patch 2 weeks ago
scripts/generate_rust_analyzer.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros
Posted by SeungJong Ha via B4 Relay 2 weeks ago
From: SeungJong Ha <engineer.jjhama@gmail.com>

Currently, rust-analyzer fails to properly resolve structs annotated with
`#[pin_data]`. This prevents IDE features like "Go to Definition" from
working correctly for those structs.

Add the missing configuration to `generate_rust_analyzer.py` to ensure
the `pin-init` crate macros are handled correctly.

Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>
---
I encountered an issue where rust-analyzer fails to analyze
structs decorated with the #[pin_data] attribute while testing
Rust kernel modules.

It appears that the dependencies for pin-init and drivers were
missing from the analyzer's configuration. This patch adds
those missing dependencies.

I have verified that my rust-analyzer correctly processes
\#[pin_data] structs after applying this fix.

Best regards, SeungJong
---
Changes in v2:
- Fix typos
- Drop the quote module workaround (will be handled separately)
- Rebase onto `rust-fixes`
- Add `pin_init` dependency for Rust drivers
- Link to v1: https://lore.kernel.org/r/20260123-fix-pin-init-crate-dependecies-v1-1-1c6cfe9aa352@gmail.com
---
 scripts/generate_rust_analyzer.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 3b645da90092..766c2d91cd81 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -214,7 +214,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
             append_crate(
                 name,
                 path,
-                ["core", "kernel"],
+                ["core", "kernel", "pin_init"],
                 cfg=cfg,
             )
 

---
base-commit: 6d7fef23043553336259211346b6b135d6c1f4c3
change-id: 20260123-fix-pin-init-crate-dependecies-b94ac4247a48

Best regards,
-- 
SeungJong Ha <engineer.jjhama@gmail.com>
Re: [PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros
Posted by Miguel Ojeda 1 week, 5 days ago
On Fri, Jan 23, 2026 at 2:19 PM SeungJong Ha via B4 Relay
<devnull+engineer.jjhama.gmail.com@kernel.org> wrote:
>
> From: SeungJong Ha <engineer.jjhama@gmail.com>
>
> Currently, rust-analyzer fails to properly resolve structs annotated with
> `#[pin_data]`. This prevents IDE features like "Go to Definition" from
> working correctly for those structs.
>
> Add the missing configuration to `generate_rust_analyzer.py` to ensure
> the `pin-init` crate macros are handled correctly.
>
> Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>

Applied to `rust-fixes` -- thanks everyone!

Cheers,
Miguel
Re: [PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros
Posted by Jesung Yang 2 weeks ago
On Fri Jan 23, 2026 at 10:18 PM KST, SeungJong Ha via B4 Relay wrote:
> From: SeungJong Ha <engineer.jjhama@gmail.com>
>
> Currently, rust-analyzer fails to properly resolve structs annotated with
> `#[pin_data]`. This prevents IDE features like "Go to Definition" from
> working correctly for those structs.
>
> Add the missing configuration to `generate_rust_analyzer.py` to ensure
> the `pin-init` crate macros are handled correctly.
>
> Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>

Perhaps I'm missing something, but I wasn't able to reproduce this
problem (which I think is expected as the `kernel` crate already depends
on `pin_init`) with the following setup:

Tree: linux-next (next-20260122) [1]
      (includes latest changes from `rust-fixes` and `pin-init-next`)
Files: samples/rust/rust_*.rs, specifically rust_configfs.rs
rust-analyzer: 2024-04-29 (which corresponds to our MSRV), 2026-01-12

Could you share your environment details and a minimal reproducible
example?

Thanks!

[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tag/?h=next-20260122

Best regards,
Jesung

> ---
> I encountered an issue where rust-analyzer fails to analyze
> structs decorated with the #[pin_data] attribute while testing
> Rust kernel modules.
>
> It appears that the dependencies for pin-init and drivers were
> missing from the analyzer's configuration. This patch adds
> those missing dependencies.
>
> I have verified that my rust-analyzer correctly processes
> \#[pin_data] structs after applying this fix.
>
> Best regards, SeungJong
> ---
> Changes in v2:
> - Fix typos
> - Drop the quote module workaround (will be handled separately)
> - Rebase onto `rust-fixes`
> - Add `pin_init` dependency for Rust drivers
> - Link to v1: https://lore.kernel.org/r/20260123-fix-pin-init-crate-dependecies-v1-1-1c6cfe9aa352@gmail.com
> ---
>  scripts/generate_rust_analyzer.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 3b645da90092..766c2d91cd81 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -214,7 +214,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
>              append_crate(
>                  name,
>                  path,
> -                ["core", "kernel"],
> +                ["core", "kernel", "pin_init"],
>                  cfg=cfg,
>              )
>  
>
> ---
> base-commit: 6d7fef23043553336259211346b6b135d6c1f4c3
> change-id: 20260123-fix-pin-init-crate-dependecies-b94ac4247a48
>
> Best regards,
Re: [PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros
Posted by 하승종 2 weeks ago
2026년 1월 24일 (토) AM 9:43, Jesung Yang <y.j3ms.n@gmail.com>님이 작성:
>
> On Fri Jan 23, 2026 at 10:18 PM KST, SeungJong Ha via B4 Relay wrote:
> > From: SeungJong Ha <engineer.jjhama@gmail.com>
> >
> > Currently, rust-analyzer fails to properly resolve structs annotated with
> > `#[pin_data]`. This prevents IDE features like "Go to Definition" from
> > working correctly for those structs.
> >
> > Add the missing configuration to `generate_rust_analyzer.py` to ensure
> > the `pin-init` crate macros are handled correctly.
> >
> > Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>
>
> Perhaps I'm missing something, but I wasn't able to reproduce this
> problem (which I think is expected as the `kernel` crate already depends
> on `pin_init`) with the following setup:
>
> Tree: linux-next (next-20260122) [1]
>       (includes latest changes from `rust-fixes` and `pin-init-next`)
> Files: samples/rust/rust_*.rs, specifically rust_configfs.rs
> rust-analyzer: 2024-04-29 (which corresponds to our MSRV), 2026-01-12
>
> Could you share your environment details and a minimal reproducible
> example?

Sure! Here are the details of my environment:
Tree: rust-fixes (commit a44bfed) [2]
rust-analyzer: The latest stable release (managed by the Zed IDE
default channel).

verified the issue with the following modules:
- samples/rust/rust_configfs.rs
- drivers/block/rnull/rnull.rs

My reproduction steps were:
1. Without the patch: Hovering over structs annotated with #[pin_data]
(e.g., RustConfigfs, NullBlkModule) provided no information/diagnostics.
2. "Go to Definition" on those symbols also failed to locate the definition.
3. After applying this patch and restarting the LSP server, both
actions succeeded.

If you need me to test with a specific pinned version or provide a more isolated
reproduction case, please let me know.

>
> Thanks!
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tag/?h=next-20260122
>
> Best regards,
> Jesung
>

[2] https://github.com/Rust-for-Linux/linux/tree/rust-fixes

> > ---
> > I encountered an issue where rust-analyzer fails to analyze
> > structs decorated with the #[pin_data] attribute while testing
> > Rust kernel modules.
> >
> > It appears that the dependencies for pin-init and drivers were
> > missing from the analyzer's configuration. This patch adds
> > those missing dependencies.
> >
> > I have verified that my rust-analyzer correctly processes
> > \#[pin_data] structs after applying this fix.
> >
> > Best regards, SeungJong
> > ---
> > Changes in v2:
> > - Fix typos
> > - Drop the quote module workaround (will be handled separately)
> > - Rebase onto `rust-fixes`
> > - Add `pin_init` dependency for Rust drivers
> > - Link to v1: https://lore.kernel.org/r/20260123-fix-pin-init-crate-dependecies-v1-1-1c6cfe9aa352@gmail.com
> > ---
> >  scripts/generate_rust_analyzer.py | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > index 3b645da90092..766c2d91cd81 100755
> > --- a/scripts/generate_rust_analyzer.py
> > +++ b/scripts/generate_rust_analyzer.py
> > @@ -214,7 +214,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
> >              append_crate(
> >                  name,
> >                  path,
> > -                ["core", "kernel"],
> > +                ["core", "kernel", "pin_init"],
> >                  cfg=cfg,
> >              )
> >
> >
> > ---
> > base-commit: 6d7fef23043553336259211346b6b135d6c1f4c3
> > change-id: 20260123-fix-pin-init-crate-dependecies-b94ac4247a48
> >
> > Best regards,
>
Re: [PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros
Posted by Jesung Yang 2 weeks ago
On Sat Jan 24, 2026 at 11:14 AM KST, 하승종 wrote:
> 2026년 1월 24일 (토) AM 9:43, Jesung Yang <y.j3ms.n@gmail.com>님이 작성:
[...]
>> Perhaps I'm missing something, but I wasn't able to reproduce this
>> problem (which I think is expected as the `kernel` crate already depends
>> on `pin_init`) with the following setup:
>>
>> Tree: linux-next (next-20260122) [1]
>>       (includes latest changes from `rust-fixes` and `pin-init-next`)
>> Files: samples/rust/rust_*.rs, specifically rust_configfs.rs
>> rust-analyzer: 2024-04-29 (which corresponds to our MSRV), 2026-01-12
>>
>> Could you share your environment details and a minimal reproducible
>> example?
>
> Sure! Here are the details of my environment:
> Tree: rust-fixes (commit a44bfed) [2]
> rust-analyzer: The latest stable release (managed by the Zed IDE
> default channel).
>
> verified the issue with the following modules:
> - samples/rust/rust_configfs.rs
> - drivers/block/rnull/rnull.rs
>
> My reproduction steps were:
> 1. Without the patch: Hovering over structs annotated with #[pin_data]
> (e.g., RustConfigfs, NullBlkModule) provided no information/diagnostics.
> 2. "Go to Definition" on those symbols also failed to locate the definition.
> 3. After applying this patch and restarting the LSP server, both
> actions succeeded.

I've discovered that rust-analyzer fails to resolve
`#[pin_data]`-annotated structs if (and only if) we compile our
proc-macros, which essentially feeds `*.so` files to rust-analyzer. If
we don't compile anything, it resolves those structs correctly (despite
some diagnostic errors, if enabled).

This issue appears to be related to rust-analyzer's proc-macro expansion
logic, but anyway, this simple patch restores the IDE functionality. So,

Reviewed-by: Jesung Yang <y.j3ms.n@gmail.com>

Thanks!

Best regards,
Jesung
Re: [PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros
Posted by Gary Guo 2 weeks ago
On Fri Jan 23, 2026 at 1:18 PM GMT, SeungJong Ha via B4 Relay wrote:
> From: SeungJong Ha <engineer.jjhama@gmail.com>
> 
> Currently, rust-analyzer fails to properly resolve structs annotated with
> `#[pin_data]`. This prevents IDE features like "Go to Definition" from
> working correctly for those structs.
> 
> Add the missing configuration to `generate_rust_analyzer.py` to ensure
> the `pin-init` crate macros are handled correctly.
> 
> Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>

Acked-by: Gary Guo <gary@garyguo.net>

> ---
> I encountered an issue where rust-analyzer fails to analyze
> structs decorated with the #[pin_data] attribute while testing
> Rust kernel modules.
> 
> It appears that the dependencies for pin-init and drivers were
> missing from the analyzer's configuration. This patch adds
> those missing dependencies.
> 
> I have verified that my rust-analyzer correctly processes
> \#[pin_data] structs after applying this fix.
> 
> Best regards, SeungJong
> ---
> Changes in v2:
> - Fix typos
> - Drop the quote module workaround (will be handled separately)
> - Rebase onto `rust-fixes`
> - Add `pin_init` dependency for Rust drivers
> - Link to v1: https://lore.kernel.org/r/20260123-fix-pin-init-crate-dependecies-v1-1-1c6cfe9aa352@gmail.com
> ---
>  scripts/generate_rust_analyzer.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH v2] scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros
Posted by Tamir Duberstein 2 weeks ago
On Fri, Jan 23, 2026 at 8:19 AM SeungJong Ha via B4 Relay
<devnull+engineer.jjhama.gmail.com@kernel.org> wrote:
>
> From: SeungJong Ha <engineer.jjhama@gmail.com>
>
> Currently, rust-analyzer fails to properly resolve structs annotated with
> `#[pin_data]`. This prevents IDE features like "Go to Definition" from
> working correctly for those structs.
>
> Add the missing configuration to `generate_rust_analyzer.py` to ensure
> the `pin-init` crate macros are handled correctly.
>
> Signed-off-by: SeungJong Ha <engineer.jjhama@gmail.com>

Fixes: d7659acca7a3 ("rust: add pin-init crate build infrastructure")
Cc: stable@vger.kernel.org
Tested-by: Tamir Duberstein <tamird@kernel.org>
Acked-by: Tamir Duberstein <tamird@kernel.org>


> ---
> I encountered an issue where rust-analyzer fails to analyze
> structs decorated with the #[pin_data] attribute while testing
> Rust kernel modules.
>
> It appears that the dependencies for pin-init and drivers were
> missing from the analyzer's configuration. This patch adds
> those missing dependencies.
>
> I have verified that my rust-analyzer correctly processes
> \#[pin_data] structs after applying this fix.
>
> Best regards, SeungJong
> ---
> Changes in v2:
> - Fix typos
> - Drop the quote module workaround (will be handled separately)
> - Rebase onto `rust-fixes`
> - Add `pin_init` dependency for Rust drivers
> - Link to v1: https://lore.kernel.org/r/20260123-fix-pin-init-crate-dependecies-v1-1-1c6cfe9aa352@gmail.com
> ---
>  scripts/generate_rust_analyzer.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 3b645da90092..766c2d91cd81 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -214,7 +214,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
>              append_crate(
>                  name,
>                  path,
> -                ["core", "kernel"],
> +                ["core", "kernel", "pin_init"],
>                  cfg=cfg,
>              )
>
>
> ---
> base-commit: 6d7fef23043553336259211346b6b135d6c1f4c3
> change-id: 20260123-fix-pin-init-crate-dependecies-b94ac4247a48
>
> Best regards,
> --
> SeungJong Ha <engineer.jjhama@gmail.com>
>
>
>